databendlabs/databend · error

internal error: entered unreachable code

Error message

internal error: entered unreachable code

What it means

A `unreachable!()` in `resolve_range_condition` (called by RangeJoin planning). When processing join predicate sides, the code asserts only `JoinPredicate::Single` (left/right) values occur at that point — `ALL`, `Both`, and `Other` predicate kinds are treated as impossible. Hitting it means a range-join condition was built from a predicate shape the range-join planner does not support but received anyway.

Solutions

  1. Simplify the range join condition into supported single-sided inequality predicates (one left column op right column per condition)
  2. Check whether a newer Databend version handles the predicate shape or rejects the query gracefully; upgrade
  3. Rewrite the join to avoid Other/complex predicates in range joins, e.g., split into multiple joins or move logic into a WHERE clause
  4. File the failing query with Databend maintainers so unsupported predicate kinds are rejected at planning rather than panicking

Example fix

// before
JoinPredicate::ALL(_) | JoinPredicate::Both { .. } | JoinPredicate::Other(_) => unreachable!(),
// after
JoinPredicate::ALL(_) | JoinPredicate::Both { .. } | JoinPredicate::Other(_) => {
    return Err(ErrorCode::Unimplemented("unsupported join predicate for range join"))
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate predicate shape before planning a range join
match predicate {
    JoinPredicate::Single(_) => plan_range_join(predicate),
    _ => return Err(ErrorCode::Unimplemented("range join requires single-sided predicates")),
}

Type guard

fn is_single(p: &JoinPredicate) -> bool { matches!(p, JoinPredicate::Single(_)) }

Try / catch

catch_unwind around RangeJoin planning; return a planning error suggesting query rewrite instead of a panic

Prevention

When it happens

Trigger: Planning a range join (e.g., join with inequality conditions) whose source `JoinPredicate` is `ALL`, `Both{..}`, or `Other` at the point where only single-sided predicates are expected.

Common situations: Queries with complex range join conditions (non-equi joins, OR-combined predicates) that the planner classifies into an unsupported JoinPredicate variant; optimizer changes that alter predicate classification.

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/1ed33a2d3169ae91. Report an issue: GitHub.

Appendix: source

Thrown at src/query/service/src/physical_plans/physical_range_join.rs:328

            for (idx, arg) in [arg1, arg2].iter().enumerate() {
                let join_predicate = JoinPredicate::new(arg, left_prop, right_prop);
                match join_predicate {
                    JoinPredicate::Left(_) => {
                        left = Some(arg.type_check(left_schema.as_ref())?.project_column_ref(
                            |index| left_schema.index_of(&index.to_string()),
                        )?);
                    }
                    JoinPredicate::Right(_) => {
                        if idx == 0 {
                            opposite = true;
                        }
                        right = Some(arg.type_check(right_schema.as_ref())?.project_column_ref(
                            |index| right_schema.index_of(&index.to_string()),
                        )?);
                    }
                    JoinPredicate::ALL(_)
                    | JoinPredicate::Both { .. }
                    | JoinPredicate::Other(_) => unreachable!(),
                }
            }
            let op = if opposite {
                match func.func_name.as_str() {
                    "gt" => "lt",
                    "lt" => "gt",
                    "gte" => "lte",
                    "lte" => "gte",
                    _ => unreachable!(),
                }
            } else {
                func.func_name.as_str()
            };
            Ok(RangeJoinCondition {
                left_expr: left.unwrap().as_remote_expr(),
                right_expr: right.unwrap().as_remote_expr(),
                operator: op.to_string(),
            })

View on GitHub (pinned to 288d84d76e)