Indexes & Query Plans
Cheat sheet · https://pcornel.dk/topic.php?topic=6088
Answer
Indexes (usually B-trees) let the database find rows without scanning the table; the query planner chooses access paths using statistics and shows them in EXPLAIN plans.
Remember
Index columns used in WHERE, JOIN and ORDER BY; column order matters in composite indexes. Too many indexes slow writes. Compare estimated and actual rows in EXPLAIN ANALYZE.
First checks
EXPLAIN ANALYZE <query>— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
Verify in this order
query → planner uses statistics → chooses index or scan → executes
Where it usually breaks
Typical failures are adding redundant indexes, indexing low-selectivity columns without workload evidence, reading only estimated plans, ignoring parameter-sensitive plans/statistics, or treating a scan as automatically bad when most rows are needed.
Indexes & Query Plans verification boundary matrix
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | B-tree concepts | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | Composite indexes / Selectivity | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | Covering/index-only access | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | EXPLAIN/query plans | The original bounded check succeeds in the same time window | Production correctness outside this scope |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6088