aqo
aqo · Adaptive query optimization extension using execution statistics to improve cardinality estimation.
Overview
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
aqo augments PostgreSQL cardinality estimation with models learned from prior executions of normalized query shapes. It targets expensive queries whose bad row estimates lead to bad plans; it is experimental optimizer research, not a guaranteed accelerator.
The reviewed upstream requires a PostgreSQL-version-specific core patch and a complete server rebuild, plus cluster-wide preload:
Restart PostgreSQL, create the extension, and train only a chosen query inside a controlled transaction:
controlled is the upstream production default for ignoring unknown query shapes. learn records them; intelligent auto-tunes; forced shares a common model; disabled bypasses AQO. Inspect aqo_queries and aqo_query_texts, and use aqo.show_details or aqo.show_hash only for diagnosis.
Training executes the real query and can add CPU, memory, storage, and latency. Plans can regress as data distributions change. AQO does not support temporary objects, and replicas cannot collect training statistics. Pin the exact patched server branch, benchmark representative parameters, retain a fast disable path, and test failover, upgrade, model cleanup, and backup/restore before cluster-wide use.