{"record":{"id":"81e203b8912cc62e","repo":"databendlabs/databend","slug":"internal-error-entered-unreachable-code-81e203","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/physical_plans/physical_mutation_into_organize.rs","lineNumber":116,"sourceCode":"                for idx in 0..row_id_len {\n                    rules.push(idx);\n                    rules.push(idx + row_id_len);\n                }\n                builder.main_pipeline.reorder_inputs(rules);\n                self.resize_row_id(2, builder)?;\n            }\n            MutationStrategy::MatchedOnly => {\n                assert_eq!(builder.main_pipeline.output_len() % 2, 0);\n                let row_id_len = builder.main_pipeline.output_len() / 2;\n                for idx in 0..row_id_len {\n                    rules.push(idx);\n                    rules.push(idx + row_id_len);\n                }\n                builder.main_pipeline.reorder_inputs(rules);\n                self.resize_row_id(2, builder)?;\n            }\n            MutationStrategy::NotMatchedOnly => {}\n            MutationStrategy::Direct => unreachable!(),\n        }\n        Ok(())\n    }\n}\n\nimpl MutationOrganize {\n    fn resize_row_id(&self, step: usize, builder: &mut PipelineBuilder) -> Result<()> {\n        // resize row_id\n        let row_id_len = builder.main_pipeline.output_len() / step;\n        let mut ranges = Vec::with_capacity(builder.main_pipeline.output_len());\n        let mut vec = Vec::with_capacity(row_id_len);\n        for idx in 0..row_id_len {\n            vec.push(idx);\n        }\n        ranges.push(vec.clone());\n\n        // data ports\n        for idx in 0..row_id_len {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/service/src/physical_plans/physical_mutation_into_organize.rs#L98-L134","documentation":"A `unreachable!()` panic in the mutation organize plan's `build_pipeline2`. The match over `MutationStrategy` handles reordering inputs, row-id resizing, and NotMatchedOnly, but asserts `Direct` never occurs here. Reaching it means a Direct-strategy mutation organize plan was built through an incompatible branch — an internal invariant breach in the physical planner.","triggerScenarios":"Building a pipeline for a MutationOrganize physical plan whose strategy field is `MutationStrategy::Direct`; the builder expects only MatchedOnly/MixedMatched/NotMatchedOnly strategies that need input reordering or row-id handling.","commonSituations":"MERGE INTO queries after optimizer changes where Direct strategy was introduced but MutationOrganize's builder was not updated; running plans produced by a mismatched planner/executor version combination.","solutions":["File a Databend issue with the failing query plan, since Direct strategies should not reach this code path","Upgrade Databend to a version where Direct strategy pipeline building is handled separately","Verify the physical plan source: check which optimizer pass produced a MutationOrganize with Direct strategy","Work around by restructuring the MERGE INTO so the planner emits a MatchedOnly/MixedMatched/NotMatchedOnly strategy"],"exampleFix":"// before\nMutationStrategy::NotMatchedOnly => {}\nMutationStrategy::Direct => unreachable!(),\n// after\nMutationStrategy::NotMatchedOnly | MutationStrategy::Direct => {} // Direct needs no input reorganization","handlingStrategy":"try-catch","validationCode":"if matches!(organize_plan.strategy, MutationStrategy::Direct) {\n    return Err(ErrorCode::Internal(\"Direct strategy reaches MutationOrganize builder\"));\n}","typeGuard":"fn needs_input_reorg(s: &MutationStrategy) -> bool { !matches!(s, MutationStrategy::Direct) }","tryCatchPattern":"std::panic::catch_unwind(AssertUnwindSafe(|| self.build_pipeline2(builder))).map_err(|_| ErrorCode::Internal(\"organize pipeline build panicked\"))","preventionTips":["Ensure Direct-strategy plans bypass MutationOrganize entirely","Replace unreachable!() in library code with typed internal errors","Test all strategy variants through build_pipeline2","Track planner changes that introduce new strategy kinds with checklist updates"],"tags":["rust","panic","unreachable","internal-invariant","merge-into","pipeline"],"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"}