Level 6 / Project 06 - Query Performance Checker¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | — |
Focus¶
- timing and query diagnostics
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-6/06-query-performance-checker
python project.py --input data/sample_input.txt --output data/output_summary.json
pytest -q
Expected terminal output¶
{
"queries_analyzed": 4,
"indexes_created": ["CREATE INDEX IF NOT EXISTS idx_orders_customer ...", ...],
"before": [...],
"after": [...]
}
Expected artifacts¶
data/output_summary.json— before/after query plan analysis- Passing tests (
pytest -q→ 6+ passed) - Updated
notes.md
Alter it (required)¶
- Add a composite index on
(customer, product)and observe how multi-column queries benefit. - Add timing comparison: print the speedup ratio (before_ms / after_ms) for each query.
- Add a
--seed-countflag to control how many rows are inserted for benchmarking. - Re-run script and tests after each change.
Break it (required)¶
- Pass a syntactically invalid SQL query and observe the error.
- Create an index on a column that is never used in WHERE clauses — confirm it has no effect on query plans.
- Run a query with
SELECT *on a table with 10,000+ rows and observe the timing.
Fix it (required)¶
- Wrap
analyze_queryin a try/except to handle invalid SQL gracefully. - Add a check that warns if an index exists but is never used by any analyzed query.
- Add tests for error handling.
Explain it (teach-back)¶
- What does
EXPLAIN QUERY PLANoutput tell you about how SQLite executes a query? - What is the difference between "SCAN TABLE" and "SEARCH TABLE USING INDEX"?
- Why does adding an index not always make queries faster?
- When would you choose NOT to add an index?
Mastery check¶
You can move on when you can: - run baseline without docs, - explain one core function line-by-line, - break and recover in one session, - keep tests passing after your change.
Related Concepts¶
- Collections Explained
- Files and Paths
- Functions Explained
- How Loops Work
- Quiz: Collections Explained
| ← Prev | Home | Next → |
|---|---|---|