Debugging Tools Overview
| Tool | Purpose | When to Use |
|---|---|---|
explain() | View execution plan | Understand what SQL will run |
| Profiler | Measure performance | Find slow operations |
| Logging | View execution details | Debug unexpected behavior |
Quick Decision Matrix
| Need | Tool | Command |
|---|---|---|
| See execution plan | explain() | ds.explain() |
| Measure performance | Profiler | config.enable_profiling() |
| Debug SQL queries | Logging | config.enable_debug() |
| All of the above | Combined | See below |
Quick Setup
Enable All Debugging
explain() Method
View the execution plan before running a query.Query
Response
Profiling
Measure execution time for each operation.Query
Response
Logging
View detailed execution logs.Common Debugging Scenarios
- Query Not Returning Expected Results
- Query Running Slowly
- Understanding Engine Selection
- Debugging Cache Issues
Best Practices
- Debug in Development, Not Production
- Use explain() Before Running Large Queries
- Profile Before Optimizing
- Check SQL When Results Are Wrong
Debugging Tools Summary
| Tool | Command | Output |
|---|---|---|
| Explain plan | ds.explain() | Execution steps + SQL |
| Verbose explain | ds.explain(verbose=True) | + Metadata |
| View SQL | ds.to_sql() | SQL query string |
| Enable debug | config.enable_debug() | Detailed logs |
| Enable profiling | config.enable_profiling() | Timing data |
| Profiler report | get_profiler().report() | Performance summary |
| Clear profiler | get_profiler().reset() | Clear timing data |
Next Steps
- explain() Method - Detailed execution plan documentation
- Profiling Guide - Performance measurement
- Logging Configuration - Log level and format setup