{"record":{"id":"c5525b38d073cda8","repo":"prestodb/presto","slug":"generic-internal-error-c5525b","errorCode":"GENERIC_INTERNAL_ERROR","errorMessage":"Expect exactly 1 child PlanNode","messagePattern":"Expect exactly 1 child PlanNode","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"critical","filePath":"presto-spi/src/main/java/com/facebook/presto/spi/plan/LimitNode.java","lineNumber":149,"sourceCode":"    }\n\n    @Override\n    public PlanNode assignStatsEquivalentPlanNode(Optional<PlanNode> statsEquivalentPlanNode)\n    {\n        return new LimitNode(getSourceLocation(), getId(), statsEquivalentPlanNode, source, count, getStep());\n    }\n\n    @Override\n    public PlanNode replaceChildren(List<PlanNode> newChildren)\n    {\n        checkCondition(newChildren != null && newChildren.size() == 1, GENERIC_INTERNAL_ERROR, \"Expect exactly 1 child PlanNode\");\n        return new LimitNode(getSourceLocation(), getId(), getStatsEquivalentPlanNode(), newChildren.get(0), count, getStep());\n    }\n\n    private static void checkCondition(boolean condition, ErrorCodeSupplier errorCode, String message)\n    {\n        if (!condition) {\n            throw new PrestoException(errorCode, message);\n        }\n    }\n}\n","sourceCodeStart":131,"sourceCodeEnd":153,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spi/src/main/java/com/facebook/presto/spi/plan/LimitNode.java#L131-L153","documentation":"LimitNode enforces its plan-shape invariant (exactly one source child) via checkCondition, which throws PrestoException with GENERIC_INTERNAL_ERROR when violated. This is an engine-internal invariant failure, not user input error: the LimitNode was constructed or its children were replaced with a list whose size is not 1.","triggerScenarios":"Building a LimitNode with newChildren.size() != 1, or replaceChildren(LimitNode) receiving an empty or multi-element list from a plan rewriter/optimizer rule.","commonSituations":"Custom PlanNode rewriters/optimizers that mishandle child replacement; engine bug after upgrades; tests constructing malformed plans.","solutions":["Inspect the optimizer/rewriter rule that produced the malformed LimitNode and fix child list construction.","Capture the query and stack trace and file an issue — this is an internal invariant violation.","Try disabling the suspected optimization rule as a workaround.","Upgrade to a Presto version where the planner bug is fixed."],"exampleFix":"// before\nnode.replaceChildren(children); // children may be empty\n\n// after\ncheckState(children.size() == 1, \"LimitNode requires exactly 1 child, got %s\", children.size());\nnode.replaceChildren(ImmutableList.of(children.get(0)));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    plan = planOptimizers.optimize(plan);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == GENERIC_INTERNAL_ERROR.toErrorCode().getCode()) {\n        log.error(\"Planner invariant violated for query \" + queryId, e);\n        throw e; // report bug; not user-fixable\n    } else throw e;\n}","preventionTips":["Always pass exactly one source child when constructing/replacing LimitNode children.","Keep custom optimizer rules updated against engine plan-shape contracts.","Report internal invariant failures with the query plan to maintainers."],"tags":["presto","spi","plan-node","internal-error","limit-node"],"backgroundTag":"internal-invariant-violation","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"}