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
Known 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
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp