{"record":{"id":"7e626400bbc2e4a4","repo":"databendlabs/databend","slug":"internal-error-entered-unreachable-code-7e6264","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/sql/src/planner/plans/aggregate.rs","lineNumber":336,"sourceCode":"                if self.group_items.is_empty() {\n                    // Scalar aggregation\n                    required.distribution = Distribution::Any;\n                } else {\n                    required.distribution = self.get_distribution(ctx)?;\n                }\n            }\n\n            AggregateMode::Final => {\n                if self.group_items.is_empty() {\n                    // Scalar aggregation\n                    required.distribution = Distribution::Serial;\n                } else {\n                    // The distribution should have been derived by partial aggregation\n                    required.distribution = Distribution::Any;\n                }\n            }\n\n            AggregateMode::Initial => unreachable!(),\n        }\n        Ok(required)\n    }\n\n    fn derive_relational_prop(&self, rel_expr: &RelExpr) -> Result<Arc<RelationalProperty>> {\n        let input_prop = rel_expr.derive_relational_prop_child(0)?;\n\n        // Derive output columns\n        let mut output_columns = ColumnSet::new();\n        for group_item in self.group_items.iter() {\n            output_columns.insert(group_item.index);\n        }\n        for agg in self.aggregate_functions.iter() {\n            output_columns.insert(agg.index);\n        }\n\n        // Derive outer columns\n        let outer_columns = input_prop","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/sql/src/planner/plans/aggregate.rs#L318-L354","documentation":"In Aggregate::compute_required_prop_child, AggregateMode::Initial must never appear during physical property enforcement: initial aggregation nodes are created/distributed before required-property computation runs, so the arm is marked unreachable. Hitting it means an Initial-mode aggregate reached the property derivation phase, breaking the distributed-aggregation planning invariant.","triggerScenarios":"Computing required properties for an Aggregate whose mode is still Initial — e.g. a query plan where partial/final aggregation splitting did not run or ran in the wrong order before property enforcement.","commonSituations":"Seen during distributed aggregation planning (GROUP BY queries on multi-node setups) after changes to the aggregation-splitting optimizer passes or in single-node plans that mistakenly keep Initial mode.","solutions":["Check the rule that splits Initial into Partial/Final aggregation ran before this compute_required_prop_child call.","Log the aggregate's mode and plan context at the panic to confirm which node was unsplit.","Handle Initial explicitly (set Distribution::Any) instead of panicking if Initial-mode aggregates are legitimate at this stage.","Verify the physical property framework's visit order — children are derived before parents — is preserved in recent refactorings."],"exampleFix":"// before\nAggregateMode::Initial => unreachable!(),\n// after\nAggregateMode::Initial => required.distribution = Distribution::Any,","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// No SQL-level guard; capture and retry on a single node or with simplified aggregation\nif err.contains(\"unreachable code\") && query_has_group_by {\n    exec(set_setting(\"enable_distributed_aggregation\", false), query);\n}","preventionTips":["Ensure aggregation-splitting optimizer settings are not disabled inconsistently across nodes.","Avoid mixing versions where Initial-mode aggregates can reach property enforcement.","Test distributed GROUP BY plans after upgrading the cluster.","Capture EXPLAIN (physical) output when the panic occurs."],"tags":["rust","planner","aggregate","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}