4.1. AQO (Adaptive Query Optimization) #
AQO is a Shardman extension that uses query execution statistics for improving cardinality estimation, which can optimize execution plans and, consequently, speed up query execution.
To turn on AQO:
Add
aqo
to theshared_preload_libraries
parameter in sdmspec.json.Create extension
aqo
on all nodes.SET shardman.broadcast_ddl TO ON; CREATE EXTENSION aqo; RESET shardman.broadcast_ddl;
Set
aqo.mode
forlearn
and run queries that you want to optimize withEXPLAIN ANALYZE
until the plan stops changing.BEGIN; SET aqo.mode = 'learn'; EXPLAIN ANALYZE <query> RESET aqo.mode; COMMIT;
Note that aqo statistics is collected separately on all nodes in a Shardman cluster. So you need to repeat this process on each node in the cluster. Alternatively, you can set
aqo.mode
tolearn
and run your application for some time and later turn it back to the default mode (controlled
).
Note
AQO will not be activated if you join less than aqo.join_threshold
relations (3 by default).
Complete aqo documentation can be found here.