Skip to content

Lab 02 — Index Access Paths

Source reference

This lab applies and PostgreSQL-adapts concepts from SQL/Query Optimization. See the coverage and terminology guide.

Scenario

A product lookup searches for a SKU without regard to letter case. The table has baseline indexes, but the expression applied to sku may change which access paths PostgreSQL can use.

Run the exercise

make shell
\i sql/labs/02-indexes/bad_queries.sql

Investigate

  1. Identify the scan type and compare estimated rows with actual rows.
  2. Record rows removed by the filter and buffers touched.
  3. Inspect existing indexes on commerce.products.
  4. Explain whether the predicate matches an indexed expression.
  5. Form a hypothesis before testing any index change.

Diagnostic question

Why can a highly selective lookup still miss an apparently relevant index, and what plan evidence demonstrates the reason?

Previous: Baseline · Next: Composite indexes