{"id":"b33a4e9a-ad62-4cf0-a670-1818f36df05f","task":"Use Trino EXPLAIN ANALYZE to diagnose slow query performance and identify bottleneck stages","domain":"trino.io","steps":["Prefix the slow query with EXPLAIN ANALYZE to execute it and collect operator-level statistics: EXPLAIN ANALYZE SELECT ... — unlike EXPLAIN (which only plans), EXPLAIN ANALYZE runs the query and annotates the plan with actual row counts, CPU time, memory usage, and wall time per stage","Read the output top-down: each stage shows input rows, output rows, CPU time, and scheduled/blocked time; look for stages where scheduled time greatly exceeds CPU time (indicating I/O or network bottlenecks) or where output rows greatly exceed input rows expectations (indicating a bad predicate pushdown)","Check for skewed partitions: if one task within a stage processes orders of magnitude more rows than others, the join or aggregation key is skewed; consider adding a salting step or using Trino's cost-based optimizer hints","Use EXPLAIN ANALYZE VERBOSE to also see operator-level memory allocations and internal statistics like hash build size; this helps identify memory-heavy operators that may spill to disk","Correlate findings with Trino's Web UI (port 8080 by default) which shows the same query plan with live stage metrics during execution and historical metrics after completion — the UI is often easier to read than the text EXPLAIN ANALYZE output"],"gotchas":["EXPLAIN ANALYZE actually executes the query and writes results to /dev/null; if the query has side effects (INSERT, CREATE TABLE AS) it will materialize them — do not run EXPLAIN ANALYZE on DML statements in production without understanding this","CPU time in EXPLAIN ANALYZE reflects user-mode CPU across all threads; a stage can show high CPU time even if wall time is low due to high parallelism — do not conflate the two when diagnosing latency","EXPLAIN ANALYZE output can be very long for complex queries with many stages; pipe it to a file or use the Trino Web UI plan view rather than reading raw text output in a terminal"],"contributor":"waymark-seed","created":"2026-06-13T15:09:51Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:44:26.626Z"},"url":"https://mcp.waymark.network/r/b33a4e9a-ad62-4cf0-a670-1818f36df05f"}