{"record":{"id":"2e912c0a83368f03","repo":"risingwavelabs/risingwave","slug":"required-column-should-be-kept","errorCode":null,"errorMessage":"required column should be kept","messagePattern":"required column should be kept","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/frontend/src/optimizer/plan_node/logical_expand.rs","lineNumber":156,"sourceCode":"            if idx < input_len {\n                input_required_cols.insert(idx);\n            } else if idx < input_len * 2 {\n                input_required_cols.insert(idx - input_len);\n            } else {\n                assert_eq!(idx, input_len * 2);\n            }\n        }\n        let input_required_cols = input_required_cols.ones().collect_vec();\n        let input_col_change =\n            ColIndexMapping::with_remaining_columns(&input_required_cols, input_len);\n        let input = self.input().prune_col(&input_required_cols, ctx);\n        let (expand, out_col_change) = self.rewrite_with_input(input, input_col_change);\n        let output_required_cols = required_cols\n            .iter()\n            .map(|idx| {\n                out_col_change\n                    .try_map(*idx)\n                    .expect(\"required column should be kept\")\n            })\n            .collect_vec();\n        LogicalProject::with_out_col_idx(expand.into(), output_required_cols.into_iter()).into()\n    }\n}\n\nimpl ExprRewritable<Logical> for LogicalExpand {}\n\nimpl ExprVisitable for LogicalExpand {}\n\nimpl PredicatePushdown for LogicalExpand {\n    fn predicate_pushdown(\n        &self,\n        predicate: Condition,\n        ctx: &mut PredicatePushdownContext,\n    ) -> PlanRef {\n        // No pushdown.\n        gen_filter_and_pushdown(self, predicate, Condition::true_cond(), ctx)","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/frontend/src/optimizer/plan_node/logical_expand.rs#L138-L174","documentation":"During column pruning of LogicalExpand, the mapping (`out_col_change`) produced by `rewrite_with_input` cannot map back one of the required output column indexes. The code asserts every required column survives the rewrite; if it does not, this `.expect` message panics, indicating an internal invariant violation in the expand-node column mapping rather than a user-facing failure.","triggerScenarios":"Calling `prune_col` on a LogicalExpand node where `out_col_change.try_map(idx)` returns None for a required column — i.e. the expand rewrite dropped a column the parent still requires.","commonSituations":"Optimizer bug reports/CI failures while running column pruning over queries with GROUPING SETS/ROLLUP/CUBE (which lower to LogicalExpand), usually after changes to Expand or pruning logic.","solutions":["Inspect the Expand node's mapping construction in `rewrite_with_input` to ensure all original output columns are preserved in `out_col_change`.","Reduce the failing query to a minimal GROUPING SETS/ROLLUP example and file a bug with the plan dump.","Check for recent changes to column pruning or Expand and re-run `./risedev c` plus planner tests after fixing the mapping."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// sanity-check mapping before pruning\nfor &idx in required_cols {\n    assert!(\n        out_col_change.try_map(idx).is_some(),\n        \"required col {idx} lost in expand rewrite\"\n    );\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Unit-test `rewrite_with_input` mapping round-trips for Expand nodes","Run planner tests after touching column pruning code","Minimalize failing GROUPING SETS/ROLLUP queries before debugging","Keep Expand output column lists in sync with its schema"],"tags":["rust","optimizer","column-pruning","assertion"],"backgroundTag":"internal-invariant-violation","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}