{"record":{"id":"80fac607375e7a80","repo":"databendlabs/databend","slug":"internal-error-entered-unreachable-code-80fac6","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/service/src/interpreters/interpreter_insert_multi_table.rs","lineNumber":386,"sourceCode":"                            span: None,\n                            id: phys_pos,\n                            data_type,\n                            display_name: sym.to_string(),\n                        };\n                        (remote_expr, sym)\n                    })\n                    .collect();\n\n                // Project only the new expr columns (input_col_num .. input_col_num + n).\n                let input_col_num = physical_schema.num_fields();\n                let projections: BTreeSet<usize> =\n                    (input_col_num..input_col_num + exprs.len()).collect();\n\n                let reordered =\n                    PhysicalPlan::new(EvalScalar::create(input_source, exprs, projections, None));\n                Ok((reordered, metadata.clone()))\n            }\n            _ => unreachable!(),\n        }\n    }\n\n    fn source_required_columns(&self) -> ColumnSet {\n        let mut required = ColumnSet::new();\n        for when in &self.plan.whens {\n            required.extend(when.condition.used_columns());\n        }\n        required\n    }\n\n    async fn build_insert_into_branches(&self) -> Result<InsertIntoBranches> {\n        let InsertMultiTable {\n            input_source: _,\n            whens,\n            opt_else,\n            overwrite: _,\n            is_first,","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/service/src/interpreters/interpreter_insert_multi_table.rs#L368-L404","documentation":"build_source_physical_plan in interpreter_insert_multi_table (src/query/service/src/interpreters/interpreter_insert_multi_table.rs:386) matches on the input source plan and panics via `_ => unreachable!()` for unhandled variants. Multi-table INSERT expects the source to be a query plan of a specific shape; anything else reaching the physical-plan builder is an internal invariant violation.","triggerScenarios":"Executing INSERT INTO ... (multi-table / conditional insert with WHEN clauses) where the bound source plan is not one of the handled physical shapes — e.g. a source requiring reordering via EvalScalar vs. a plain passthrough, and the binder produced a third variant.","commonSituations":"Multi-table INSERT statements with complex SELECT sources (set operations, new plan nodes) on versions where the multi-table interpreter wasn't extended; usually hit after upgrades or with advanced query shapes.","solutions":["Rewrite the multi-table INSERT source as a simpler SELECT (split unions/set operations, materialize into a temp table first)","Upgrade to a Databend version where insert_multi_table handles the plan shape your source produces","File a bug with the exact multi-table INSERT statement and version","As a code fix, replace `_ => unreachable!()` with a returned ErrorCode::Internal describing the unexpected source variant"],"exampleFix":"// before\n_ => unreachable!(),\n// after\nother => {\n    return Err(ErrorCode::Internal(format!(\n        \"insert multi-table: unexpected source plan {:?}\", other\n    )));\n}","handlingStrategy":"validation","validationCode":"-- verify the multi-table INSERT source is a plain SELECT before running\n-- good: INSERT INTO t1/t2 (SELECT cols FROM src WHERE ...)\n-- split UNION/complex sources first","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use plain SELECT sources for multi-table INSERT; pre-materialize unions into a temp table","Validate multi-table INSERT statements on a staging cluster after upgrades","Avoid nesting exotic query shapes inside conditional insert WHEN/ELSE branches","File bugs with the exact statement when a source shape is rejected"],"tags":["rust","unreachable-panic","insert","multi-table"],"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"}