{"record":{"id":"885b172746c7ad0e","repo":"databendlabs/databend","slug":"internal-error-entered-unreachable-code-885b17","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.rs","lineNumber":474,"sourceCode":"            self.ctx\n                .get_table_meta_timestamps(table.as_ref(), snapshot)?\n        } else {\n            // For non-fuse table, the table meta timestamps does not matter,\n            // just passes a placeholder value here\n            TableMetaTimestamps::new(None, Duration::hours(1))\n        };\n\n        let hook_lock_opt = if self.materialized_view_refresh_target.is_some() {\n            // Materialized-view refresh holds its lifecycle lock across this pipeline.\n            LockTableOption::NoLock\n        } else {\n            LockTableOption::LockNoRetry\n        };\n        let mut build_res = PipelineBuildResult::create();\n\n        match &self.plan.source {\n            InsertInputSource::Stage(_) => {\n                unreachable!()\n            }\n            InsertInputSource::Values(InsertValue::Values { rows }) => {\n                // Fixed-bucket PK Paimon tables need route + GlobalHash Exchange; unify with\n                // the SELECT insert physical plan so single-node uses local channel repartition.\n                if is_fixed_bucket_primary_key(&table)? {\n                    let insert_schema = self.plan.dest_schema();\n                    let (values_plan, bindings) =\n                        values_to_constant_scan(rows, insert_schema.clone())?;\n                    let select_schema = values_plan.output_schema()?;\n                    let mut insert_plan = build_insert_select_physical_plan(\n                        values_plan,\n                        select_schema,\n                        bindings,\n                        insert_schema,\n                        table.clone(),\n                        false,\n                        false,\n                        table_meta_timestamps,","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/service/src/interpreters/interpreter_insert.rs#L456-L492","documentation":"interpreter_insert's execute2 (src/query/service/src/interpreters/interpreter_insert.rs:474) matches on InsertInputSource and panics via unreachable!() for InsertInputSource::Stage. INSERT from a stage is supposed to be rewritten into an INSERT ... SELECT (a query source) before reaching this interpreter; a Stage source surviving to execute2 means an upstream rewrite was skipped or a new path bypassed it.","triggerScenarios":"Executing `INSERT INTO t FROM @stage` (or equivalent direct stage-source insert) on a code path where the Stage source is not converted to a SELECT-based insert before execute2 runs.","commonSituations":"Users issuing INSERT directly from a stage instead of the supported COPY INTO or INSERT INTO ... SELECT FROM @stage forms; internal regressions where the stage-to-query rewrite was bypassed (e.g. via prepared plans or internal tooling).","solutions":["Rewrite the statement as `INSERT INTO t (SELECT ... FROM @stage ...)` or use `COPY INTO t FROM @stage`, which are the supported paths","Upgrade to a Databend version where stage-source inserts are always rewritten to query sources or rejected with a clear user error","Capture the exact SQL and version and file a bug — a Stage source must never reach execute2","As a code fix, replace unreachable! with Err(ErrorCode::Internal(\"InsertInputSource::Stage should be rewritten to a query source\"))"],"exampleFix":"-- before (panics)\nINSERT INTO t FROM @my_stage;\n-- after\nINSERT INTO t (SELECT $1, $2 FROM @my_stage);","handlingStrategy":"validation","validationCode":"-- never INSERT directly FROM @stage; use a SELECT or COPY INTO\nINSERT INTO t (SELECT $1, $2 FROM @my_stage);\n-- or: COPY INTO t FROM @my_stage;","typeGuard":"if matches!(plan.source, InsertInputSource::Stage(_)) {\n    return Err(ErrorCode::BadArguments(\"rewrite stage-source INSERT as INSERT ... SELECT\".into()));\n}","tryCatchPattern":null,"preventionTips":["Use COPY INTO for loading files/stages into tables","Wrap stage sources in INSERT ... SELECT form","Avoid legacy INSERT FROM @stage syntax from older engines","Add SQL lint rules in CI to reject direct stage-source inserts"],"tags":["rust","unreachable-panic","insert","stage"],"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"}