databendlabs/databend · error

internal error: entered unreachable code

Error message

internal error: entered unreachable code

What it means

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.

Solutions

  1. Rewrite the multi-table INSERT source as a simpler SELECT (split unions/set operations, materialize into a temp table first)
  2. Upgrade to a Databend version where insert_multi_table handles the plan shape your source produces
  3. File a bug with the exact multi-table INSERT statement and version
  4. As a code fix, replace `_ => unreachable!()` with a returned ErrorCode::Internal describing the unexpected source variant

Example fix

// before
_ => unreachable!(),
// after
other => {
    return Err(ErrorCode::Internal(format!(
        "insert multi-table: unexpected source plan {:?}", other
    )));
}
Defensive patterns

Strategy: validation

Validate before calling

-- verify the multi-table INSERT source is a plain SELECT before running
-- good: INSERT INTO t1/t2 (SELECT cols FROM src WHERE ...)
-- split UNION/complex sources first

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11). Data as JSON: /api/errors/80fac607375e7a80. Report an issue: GitHub.

Appendix: source

Thrown at src/query/service/src/interpreters/interpreter_insert_multi_table.rs:386

                            span: None,
                            id: phys_pos,
                            data_type,
                            display_name: sym.to_string(),
                        };
                        (remote_expr, sym)
                    })
                    .collect();

                // Project only the new expr columns (input_col_num .. input_col_num + n).
                let input_col_num = physical_schema.num_fields();
                let projections: BTreeSet<usize> =
                    (input_col_num..input_col_num + exprs.len()).collect();

                let reordered =
                    PhysicalPlan::new(EvalScalar::create(input_source, exprs, projections, None));
                Ok((reordered, metadata.clone()))
            }
            _ => unreachable!(),
        }
    }

    fn source_required_columns(&self) -> ColumnSet {
        let mut required = ColumnSet::new();
        for when in &self.plan.whens {
            required.extend(when.condition.used_columns());
        }
        required
    }

    async fn build_insert_into_branches(&self) -> Result<InsertIntoBranches> {
        let InsertMultiTable {
            input_source: _,
            whens,
            opt_else,
            overwrite: _,
            is_first,

View on GitHub (pinned to 288d84d76e)