Query optimization source alignment
Source
This coverage guide uses SQL/Query Optimization as a reference and adapts its cross-database terminology to PostgreSQL 17. The source was last updated June 18, 2024.
Coverage map
| Source concept | Lab coverage | Knowledge check |
|---|---|---|
| Execution plans and tuning | Labs 01 and 10 | Plans and indexes |
| Full-table scans | Labs 01, 02, and 10 | Plans and indexes |
Equality, range, IN, NOT, <>, and leading wildcard predicates |
Lab 02 | Index structures and SARGability |
| Primary and secondary indexes | Labs 02–03 | Index structures and SARGability |
| Clustered physical ordering | Lab 02 conceptual comparison | Index structures and SARGability |
| Dense and sparse indexes | Lab 02 conceptual comparison | Index structures and SARGability |
| B-tree and hash indexes | Lab 02 | Index structures and SARGability |
| Bitmap access | Lab 02 | Index structures and SARGability |
| Partial/filtered indexes | Labs 02–03 | Index structures and SARGability |
| Covering indexes | Labs 03, 07, and 13 | Plans and indexes |
| Function/expression indexes | Lab 02 | Plans and indexes |
| Full-text indexes | Lab 02 conceptual comparison | Index structures and SARGability |
| Spatial indexes | Lab 02 conceptual comparison | Index structures and SARGability |
| SARGable predicates | Labs 02–03 | Index structures and SARGability |
| Functions and arithmetic on indexed columns | Lab 02 | Index structures and SARGability |
| Composite-index prefixes | Lab 03 | Plans and indexes |
| Index write cost | Labs 02–03 | Plans and indexes |
PostgreSQL terminology corrections
The source discusses concepts across multiple database engines. Apply these distinctions in this lab:
- PostgreSQL
EXPLAINreplaces Oracle'sEXPLAIN PLANsyntax andEXPLAIN ANALYZEexecutes the statement. - PostgreSQL primary-key indexes do not automatically determine permanent physical table order.
CLUSTERperforms a one-time table rewrite around an index, and later writes do not preserve that ordering. - PostgreSQL does not provide Oracle-style bitmap indexes. A Bitmap Index Scan and Bitmap Heap Scan combine ordinary indexes into an execution-time bitmap.
- A PostgreSQL partial index corresponds to the source's filtered-index concept.
- A PostgreSQL
INCLUDEindex can cover selected output columns, but index-only scans still depend on MVCC visibility information. - Dense and sparse describe index-entry coverage as general storage concepts; PostgreSQL B-tree leaf behavior should not be reduced to a user-selectable dense/sparse index type.
- Hash indexes support equality, while B-tree indexes support equality, ranges, and ordering. Measure before replacing a B-tree with a hash index.
- Full-text search normally uses
tsvectorwith GIN or GiST. Spatial access commonly uses GiST or SP-GiST with geometric or extension-provided types.
SARGability caveats
Functions, arithmetic, NOT, <>, and leading wildcards can prevent a useful B-tree search, but this is not an absolute rule. Expression indexes, operator classes, alternative query shapes, selectivity, and PostgreSQL's cost model affect the selected path. Prove the behavior with an actual plan rather than memorizing “avoid functions.”