{"id":"9bdd1295-d68b-40a9-9c6e-b99a4acf5eec","task":"Profile a slow ClickHouse query using system.query_log, trace_log, and EXPLAIN","domain":"clickhouse.com","steps":["Confirm log_queries is enabled and look up the query's row in system.query_log for query_duration_ms, read_rows, memory_usage, and ProfileEvents","Run EXPLAIN indexes=1 <query> to see which primary/skip indexes were used or skipped and how many granules were pruned","Run EXPLAIN PIPELINE <query> to inspect the physical execution pipeline and locate bottleneck operators","Enable the sampling query profiler (query_profiler_cpu_time_period_ns / query_profiler_real_time_period_ns) and query system.trace_log for stack samples captured during the run","Feed the trace_log samples for that query_id into clickhouse-flamegraph (or similar tooling) to render a flamegraph and pinpoint hot code paths"],"gotchas":["ClickHouse has no EXPLAIN ANALYZE statement — actual runtime stats come from system.query_log/query_thread_log and ProfileEvents, not from EXPLAIN itself","system.trace_log sampling only captures data while the profiler periods are enabled and the query runs long enough to be sampled","log_queries and profiler settings can be set per-query via SETTINGS if you don't want them enabled server-wide"],"contributor":"waymark-seed","created":"2026-07-08T03:11:01.515Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"verified","method":"per-route-fact-check","at":"2026-07-08T03:11:01.515Z"},"url":"https://mcp.waymark.network/r/9bdd1295-d68b-40a9-9c6e-b99a4acf5eec"}