ClickHouse can log two events for one SQL agent query
Use application dispatches for attempts per task. Match them to ClickHouse terminal events to see how much of that work the server log captures.
If you’re sizing a warehouse for a SQL agent, don’t divide raw ClickHouse query-log rows by the number of user questions. A single successful query produces a start and a finish event, and distributed work can add child-query records. But counting only finishes also gives the wrong number: it drops failures, and even a count of all terminal events can miss calls the application tried to make. ClickHouse’s system.query_log reference documents the server-side events; use an application ledger for the attempt count.
Count dispatches in the application, then reconcile with the server
In a pilot, assign each user task an ID. Record one attempt when the application hands a SQL call to its database client, including each retry; use a fresh query ID per attempt where the client supports it. Divide those dispatches by all user tasks in the pilot, including tasks that failed or made no SQL calls. If the driver retries beneath your instrumentation, either capture those retries too or label the measure as application-level dispatches rather than all network attempts.
Match the ledger to system.query_log by query_id, keeping is_initial_query = 1 and the terminal types QueryFinish, ExceptionWhileProcessing, and ExceptionBeforeStart. The initial-query filter removes child work but does not identify agent traffic by itself; the reference notes that server-internal work can also be marked initial. Count matched attempt IDs, not log rows. Report the share of application attempts with a terminal match separately from attempts per task.
For example, suppose one task dispatches four calls: a success, a query that fails during processing, a retry that succeeds, and a call that times out at the client with no matching terminal row after reconciliation. The first three produce six parent events and three matched terminal outcomes under unfiltered logging. The fourth still counts in the application ledger: four attempts per task, three of four with a terminal match. Mark the fourth as a client timeout with no observed terminal outcome, not a confirmed database failure or zero server work. A client-side connection failure with no match also stays in the ledger if it occurred after dispatch to the driver. If a timed-out attempt later acquires a terminal match, update the coverage count, not the dispatch count.
Check what the log could have missed
Check the effective ClickHouse query-logging settings for the pilot: log_queries = 1, log_queries_probability = 1 for no sampling, log_queries_min_query_duration_ms = 0 for no duration cutoff, and log_queries_min_type = 'QUERY_START' if you want all event types. A nonzero duration threshold can omit fast queries and excludes before-start exceptions; a higher minimum event type can suppress otherwise eligible events. Allow time for log flushing and collect from all relevant nodes; ClickHouse Cloud documents clusterAllReplicas because the log is local to each node.
A November 24 ClickHouse engineering post illustrates how agents can create bursts even when data refreshes nightly. Its workload figures are scenarios, not measured deployment results. For your own sizing pilot, use application dispatches to describe demand, matched server records to measure observed warehouse work, and application wall-clock time to measure what the user waited. These answer three different questions.
sources
- ClickHouse reference: system.query_logclickhouse.com
- ClickHouse reference: query logging settingsclickhouse.com
- ClickHouse Engineering: Your agents don’t care that you’re a batch shopclickhouse.com
comments · 0
- EKOS’s pending BIRD submission pairs a SQLite-tuned run with a separate hidden-test scoreDec 3, 2026
- MotherDuck rolls out DuckDB 2.0 and reports faster cold reads, not faster agent answersDec 3, 2026
- Oracle Select AI can use two definitions of the same metric. Source order won’t break the tieDec 3, 2026