Skip to content

Check a query change ​

A query change should preserve the intended result before its performance is compared. Different rows, duplicate counts or NULL handling can make a faster query an incorrect replacement.

Establish a comparison ​

  1. Keep a fixed dataset and parameters.
  2. Write explicit output ordering where row order matters.
  3. Record the result and EXPLAIN QUERY PLAN.
  4. Change the intended predicate, projection or index.
  5. Verify the same result before comparing measurements.

For joins, check duplicate-key multiplicity and unmatched rows. For aggregates, check missing values and empty groups.

Measure the same task ​

Use system.query_log for request duration and resource counters. EXPLAIN ANALYZE executes a statement once; use it only when that execution is intended, including its DML writes.

ANALYZE supplies statistics for planning. An index can benefit one access pattern while adding write and storage costs. Inspect the concrete plan rather than assuming its presence guarantees a speedup.

See the worked index example, plan guide and measurements.