{"record":{"id":"00d49de4cebe6a3b","repo":"prestodb/presto","slug":"query-planning-timeout-00d49d","errorCode":"QUERY_PLANNING_TIMEOUT","errorMessage":"The query planner exceeded the timeout of %s.","messagePattern":"The query planner exceeded the timeout of (.+?)\\.","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/planner/RelationPlanner.java","lineNumber":1377,"sourceCode":"                    outputs.size());\n\n            int fieldId = 0;\n            for (Field field : descriptor.getVisibleFields()) {\n                int fieldIndex = descriptor.indexOf(field);\n                variableMapping.put(outputs.get(fieldId), childOutputVariables.get(fieldIndex));\n                fieldId++;\n            }\n\n            sources.add(relationPlan.getRoot());\n        }\n\n        return new SetOperationPlan(sources.build(), variableMapping.build());\n    }\n\n    private void checkInterruption()\n    {\n        if (Thread.currentThread().isInterrupted()) {\n            throw new PrestoException(QUERY_PLANNING_TIMEOUT, String.format(\"The query planner exceeded the timeout of %s.\", getQueryAnalyzerTimeout(session).toString()));\n        }\n    }\n\n    private PlanBuilder initializePlanBuilder(RelationPlan relationPlan)\n    {\n        TranslationMap translations = new TranslationMap(relationPlan, analysis, lambdaDeclarationToVariableMap);\n\n        // Make field->variable mapping from underlying relation plan available for translations\n        // This makes it possible to rewrite FieldOrExpressions that reference fields from the underlying tuple directly\n        translations.setFieldMappings(relationPlan.getFieldMappings());\n\n        return new PlanBuilder(translations, relationPlan.getRoot());\n    }\n\n    private PlanNode distinct(PlanNode node)\n    {\n        return new AggregationNode(\n                node.getSourceLocation(),","sourceCodeStart":1359,"sourceCodeEnd":1395,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/planner/RelationPlanner.java#L1359-L1395","documentation":"During relational planning, RelationPlanner.checkInterruption polls the current thread's interrupt flag; if it is set, planning is assumed to have exceeded the analyzer timeout (query.analyzer-timeout / query planner timeout) and QUERY_PLANNING_TIMEOUT is thrown. The engine interrupts planning threads once the configured timeout elapses.","triggerScenarios":"Planning a very complex relation (huge set operations, deep expression trees) that takes longer than the configured planner/analyzer timeout, causing the worker thread to be interrupted and the next checkInterruption() call to throw.","commonSituations":"Queries with enormous UNION/INTERSECT trees or thousands of joins; clusters with a low query.analyzer-timeout setting; shared fleet overload slowing planning past the deadline.","solutions":["Increase query.analyzer-timeout (config property or session property) to give planning more time","Simplify the query: reduce set-operation depth, break into staged queries/materialized steps","Retry the query during lower cluster load if planning was merely slow, not intrinsically too complex","Profile the plan complexity; very large generated SQL may indicate a client-side generation bug"],"exampleFix":"// before\nquery.analyzer-timeout=1m\n// after\nquery.analyzer-timeout=10m","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    result = execute(sql);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"QUERY_PLANNING_TIMEOUT\")) {\n        // one retry, optionally with a raised analyzer timeout\n        session.setProperty(\"query_analyzer_timeout\", \"20m\");\n        result = execute(sql);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Set query.analyzer-timeout generously for workloads with complex SQL","Avoid generating extremely deep set-operation or join trees","Split giant queries into materialized intermediate steps","Retry during off-peak hours if planning time is load-sensitive"],"tags":["presto","planner","timeout","interruption"],"backgroundTag":"query-planning-timeout","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}