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:

  1. Add aqo to the 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 for learn and run queries that you want to optimize with EXPLAIN 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 to learn 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.

pdf