All posts

The query advisor: DDL recommendations you review, not that run themselves

How chmonitor's optimization advisor turns a slow ClickHouse query into ranked skip-index, projection, and PREWHERE recommendations — and why it never applies any of them for you.

This is for anyone who’s found a slow query in system.query_log and then had to guess whether a skip index, a projection, or a PREWHERE rewrite would actually fix it. chmonitor’s query advisor answers that question with ranked, explained recommendations — but it stops at the recommendation. By the end you’ll know how to run it and what you’re expected to do with the output.

Prerequisites

Steps

1. Point the advisor at a slow query

The advisor takes either a raw SQL string or a query_id from system.query_log. In the dashboard, ask the AI agent something like:

Analyze query_id abc-123 and tell me how to speed it up.

Under the hood this calls the get_optimization_recommendations tool, which reads EXPLAIN output plus system.tables, system.columns, system.data_skipping_indexes, and system.parts for the tables involved — no writes, no DDL execution.

2. Read the ranked output

Each recommendation comes back with:

3. Review, then apply it yourself

This is the part that matters: the advisor recommends, it does not execute. Nothing it returns has been run against your cluster. Before applying any suggested DDL:

Verifying it worked

After applying a recommendation, re-run the query that was slow and pull its latest execution from system.query_log:

SELECT query_id, query_duration_ms, read_rows, read_bytes
FROM system.query_log
WHERE type = 'QueryFinish' AND query_id = {query_id:String}
ORDER BY event_time DESC
LIMIT 1

Compare query_duration_ms and read_bytes against the pre-change baseline. If the numbers didn’t move as expected, the advisor’s estimate was off for your data distribution — that’s a signal to try the next-ranked recommendation, not a bug to report.