Skip to content

fix(plan): handle correlated scalar outer projections#25920

Merged
XuPeng-SH merged 10 commits into
matrixorigin:mainfrom
aunjgr:fix/23062-correlated-scalar-projection
Jul 22, 2026
Merged

fix(plan): handle correlated scalar outer projections#25920
XuPeng-SH merged 10 commits into
matrixorigin:mainfrom
aunjgr:fix/23062-correlated-scalar-projection

Conversation

@aunjgr

@aunjgr aunjgr commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #23062

What this PR does / why we need it:

Direct outer-column references projected by correlated scalar subqueries could remain in the executable right subtree, causing internal errors and incorrect behavior through DISTINCT and ORDER BY/LIMIT wrappers.

This change:

  • normalizes the direct correlated projection before predicate pull-up;
  • preserves SINGLE JOIN cardinality checks for direct and ORDER BY-only cases;
  • uses MARK JOIN existence semantics for DISTINCT and LIMIT 1;
  • seeds predicate-free scalar MARK joins with TRUE so empty and nonempty inner inputs preserve all outer rows correctly;
  • adds planner and distributed regressions for empty, one-row, and multi-row inner inputs.

Testing

  • make build
  • go vet ./pkg/sql/plan
  • .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=180s ./pkg/sql/plan
  • focused mo-tester BVT: 21/21 passed

@mergify mergify Bot added the kind/bug Something isn't working label Jul 20, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jul 20, 2026
@aunjgr
aunjgr marked this pull request as ready for review July 20, 2026 16:51
@aunjgr
aunjgr requested review from XuPeng-SH and heni02 as code owners July 20, 2026 16:52
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@aunjgr

aunjgr commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@gouhongshen Addressed in commit 20ecd5903. The rewrite now preflights the exact synthesized CASE signature through the function resolver and proceeds only when the resolved return type is semantically equal to the source type via types.Type.Eq. ENUM coercion and unsupported ROWID/vector cases therefore stay on the pre-existing path, as do metadata-changing cases such as BIT width changes; ordinary INT metadata is accepted using the codebase semantic type-equivalence rule. Added focused type regressions for INT, ENUM, ROWID, vector, and BIT. Full pkg/sql/plan tests, build, vet, and the targeted BVT pass.

@aunjgr
aunjgr requested review from XuPeng-SH and gouhongshen July 22, 2026 04:51

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed latest head 20ecd59. No blocking findings.

The prior requested changes are resolved: OFFSET/rank/dynamic or zero LIMIT shapes now fall back before mutation; literal LIMIT 1 uses MARK existence semantics; LIMIT >= 2 removes the misplaced limit while SINGLE join preserves per-outer-row cardinality; synthesized CASE is gated by semantic type equality.

Verified with full pkg/sql/plan tests, focused regressions 5x, go build, go vet, and an exact-head mo-service execution matrix covering empty/one/multi-row inputs, NULLs, duplicate outer rows, DISTINCT, LIMIT 1, LIMIT 2, and proper 1242/21000 multi-row errors. Current CI has no failures (three jobs are still running).

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

No blocking or non-blocking findings remain. The latest discussion is supported by the current code: prior LIMIT/OFFSET and CASE type regressions are resolved, while unsupported CASE types conservatively retain pre-existing behavior without introducing a regression. Current-head CI is green; local focused tests could not run because libmo.dylib is absent.

@mergify mergify Bot added the queued label Jul 22, 2026
@mergify

mergify Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-07-22 06:43 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue2026-07-22 08:30 UTC · at 090ebf69767a58bf4381635cbeb2e0434868c474

This pull request spent 1 hour 47 minutes 16 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection] (documentation)
  • github-review-decision = APPROVED [🛡 GitHub branch protection] (documentation)

Reason

Pull request #25920 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants