5.1. AQO (Adaptive Query Optimization)

AQO (Adaptive query optimization) is a Shardman extension which uses query execution statistics for improving cardinality estimation.

To turn on AQO:

  1. Add aqo to shared_preload_libraries parameter in sdmspec.json.

  2. Create extension aqo on all nodes.

                 SET shardman.broadcast_ddl TO ON;
                 CREATE EXTENSION aqo;
                 RESET shardman.broadcast_ddl;
                

  3. Set aqo.mode to learn and run queries which you want to optimize with EXPLAIN ANALYZE until plan stops changing.

                 BEGIN;
                 SET aqo.mode = 'learn';
                 EXPLAIN ANALYZE <query>
                 RESET aqo.mode;
                 COMMIT;
                            

    Note that aqo statistics is separate on all nodes in Shardman cluster. So you'll have to repeat this process on each node in the cluster. Alternatively, you can set aqo.mode to learn and run your application for some time and later turn it back to 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.