bug(optimizer): join reordering panics for nested ANY JOIN

Open
#20,829 1 comment 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@forsaken628 is already working on this.

Since Oct 23, 2026.

Assessment

This issue has not been assessed yet.

Description

Problem

Confirmed on main: a query containing ANY JOIN panics during join reordering instead of returning the existing “ANY JOIN is not supported yet” error. This is not specific to an intermediate PR revision.

Reproduce

Run in a fresh schema with default settings:

CREATE TABLE rf_any_a(k INT, v INT);
CREATE TABLE rf_any_b(k INT, v INT);
CREATE TABLE rf_any_c(k INT);
INSERT INTO rf_any_a VALUES (1,10), (1,11), (2,20);
INSERT INTO rf_any_b VALUES (1,100), (2,200);
INSERT INTO rf_any_c VALUES (0), (1);

SELECT q.k, q.v
FROM (
  SELECT a.k, a.v
  FROM rf_any_a a LEFT ANY JOIN rf_any_b b ON a.k = b.k
) q
JOIN rf_any_c c ON q.k = c.k
ORDER BY q.k, q.v;

Actual: error 1104, no entry found for key. EXPLAIN fails too. The panic is at self.table_index_map[table] in dphyp.rs:745.

For comparison, setting disable_join_reorder = 1 makes SELECT return error 1002, ANY JOIN is not supported yet. This SET is only a diagnostic control, not required to reproduce. The corresponding RIGHT ANY JOIN form (replace rf_any_a a LEFT ANY JOIN rf_any_b b with rf_any_b b RIGHT ANY JOIN rf_any_a a) also fails. With reordering disabled, EXPLAIN succeeds and shows the ANY join; the unsupported-operation check is reached only when SELECT builds its execution pipeline.

Expected: reject unsupported ANY JOIN with a clear error, without an optimizer panic.

Confirmed on main

Rebuilt and ran the SQL above on main commit 2558f77fd87b0829651ec49c0e1151b9fabc6383 on 2026-10-27. This was the latest main head checked for this run. The clean detached worktree had no tracked modifications; no PR patches were applied.

Environment: macOS ARM64, debug OSS databend-query-oss and databend-meta-oss built from that commit, a fresh isolated single-node deployment with filesystem storage, and bendsql over HTTP.

SELECT version() returned:

Databend Query v1.2.954-2558f77fd8(rust-1.100.0-nightly-2026-10-27T05:03:13.700400000Z)

Verified defaults: disable_join_reorder = 0, enable_dphyp = 1. No SET is needed to trigger the panic.

Nested join Operation Default settings disable_join_reorder = 1 (control)
LEFT ANY SELECT error 1104: no entry found for key error 1002: ANY JOIN is not supported yet
LEFT ANY EXPLAIN error 1104: no entry found for key plan generated successfully
RIGHT ANY SELECT error 1104: no entry found for key error 1002: ANY JOIN is not supported yet
RIGHT ANY EXPLAIN error 1104: no entry found for key plan generated successfully

All four default-setting failures logged a panic in DPhpyOptimizer::build_join_order_edges at src/query/sql/src/planner/optimizer/optimizers/hyper_dp/dphyp.rs:745:62, indexing self.table_index_map[table].

As a fixture control, replacing LEFT ANY with an ordinary INNER JOIN returned (1,10) and (1,11). The server also answered SELECT version(), 1 after all panic cases; these were caught query-level panics, not a server-process crash.

Dominant language
Rust
Stars
9.5k
Forks
903
Avg merge
2d 13h
Merged PRs (30d)
204

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from databendlabs/databend

All issues in databendlabs/databend

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.