Repository navigation
fix(plan): preserve NATURAL JOIN visible column order - #32776
Conversation
Discover NATURAL JOIN common columns from each operand's visible star projection instead of its flattened base-table bindings. Nested joins already merge and reorder their common columns, so scanning the right bindings can produce an incorrect SELECT * order and propagate different positional values into views, prepared statements and INSERT SELECT. Share ordered common-column discovery between ordinary joins and correlated JSON_TABLE joins. Follow the left visible operand for INNER, LEFT and FULL joins and the preserved right operand for RIGHT joins. Reuse existing visibility filtering, deduplicate merged names, and retain addUsingCol's ambiguity, equality and coalesce handling. Explicit USING lists and qualified stars are unchanged. Add planner regressions for nested and simple joins, side-specific order, JSON_TABLE, hidden columns, tenant visibility and ambiguous names. Extend the existing join star-order BVT to check metadata, prepared execution, positional writes and post-error reuse. Existing persisted explicit view projections are not rewritten. Fixes matrixorigin#32599.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Local CPU validation on the PR head:
The service was built from newest main plus this fix, with CPU-only settings. No lookup-kernel changes are included. Existing persisted view projections remain unchanged, as required by their frozen-schema contract. |
|
Queue requested — the merge queue status continues in this comment ↓. |
✅ Merged into
|
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 2dbc4b8f980e32d42748b872f38543bc1967d2bf
Assessment: approve
The fix reuses authoritative star visibility for NATURAL JOIN ordering while preserving ambiguity checks, equality predicates, FULL JOIN coalescing and frozen-view contracts. No actionable findings.
Model: gpt-6.1-sol / max
Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0
Validation:
-
Focused NATURAL/RIGHT JOIN regressions and full pkg/sql/plan passed with -count=1.
-
Baseline control reproduced incorrect inner/nested ordering; RIGHT and flat-three-table controls passed.
-
Changed SQL case passed 55/55 comparisons twice on the same instance; static-view control passed 52/52. Cleanup and shutdown verified.
-
Public probes passed for unmatched RIGHT rows, nested FULL coalescing, nested RIGHT ordering and correlated JSON_TABLE filtering.
-
Service identity, native inputs, gofmt and diff checks verified. validation-evidence.json maps claimed checks to terminal receipts and retained logs.
Limitations:
-
Validation used Linux amd64 CPU and a standalone instance; no multi-CN, GPU or race runs.
-
Author-reported molint/license/golangci-lint results lacked raw artifacts and were not counted.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #32599
What this PR does / why we need it:
Derive NATURAL JOIN common-column order from each operand's visible output schema instead of scanning flattened base-table bindings. Nested joins have already merged and reordered their common columns; using underlying table order produces an incorrect
SELECT *projection and propagates different positional values through views, prepared statements andINSERT ... SELECT.Follow the left visible operand for INNER, LEFT and FULL joins, and the preserved right operand for RIGHT joins. Share ordered common-column discovery between ordinary joins and correlated JSON_TABLE joins. Reuse existing star-expansion visibility rules, normalize and deduplicate common names, and retain the existing ambiguity checks, equality predicates and FULL JOIN coalesce handling.
Explicit
USINGlists and qualified stars are unchanged. Existing views retain their persisted explicit projections; creating or recreating a view uses the corrected order.Add planner regressions for nested and flat joins, side-specific ordering, JSON_TABLE, case-insensitive names, hidden columns, tenant visibility and ambiguous common names. Extend the existing join star-order SQL regression to verify exact column metadata, view and prepared-query results, positional inserts, and successful reuse after an invalid-column error.