Skip to content

fix(join): deduplicate MARK JOIN probe rows - #24277

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
gouhongshen:codex/fix-mark-join-exists-or
May 6, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
gouhongshen:codex/fix-mark-join-exists-or

Conversation

@gouhongshen

@gouhongshen gouhongshen commented May 6, 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:

Fixes #24219

What this PR does / why we need it:

Correlated EXISTS subqueries are flattened into MARK JOINs. The loop join executor evaluated each build batch independently and emitted the same probe row once per build batch, so EXISTS(A) OR EXISTS(B) could inflate outer rows instead of acting as a boolean predicate.

This PR aggregates MARK JOIN condition results across all build batches before emitting the probe row. Each probe row now produces a single mark value (true, NULL, or false), preserving EXISTS/semi-join semantics. It also adds:

  • unit tests covering duplicate matches split across build batches and MARK JOIN resume after the default output batch size
  • a small BVT regression case with one outer row and 9000 inner rows, just enough to cross the 8192-row execution batch boundary

Validation:

  • CGO_CFLAGS="-I${ROOT}/thirdparties/install/include" CGO_LDFLAGS="-L${ROOT}/thirdparties/install/lib -Wl,-rpath,${ROOT}/thirdparties/install/lib" go test ./pkg/sql/colexec/loopjoin -coverprofile=/tmp/loopjoin_cover.out
  • make build
  • cd /Users/ghs-mo/MOWorkSpace/mo-tester && ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-3rd/test/distributed/cases/ -m genrs -i issue_24219
  • cd /Users/ghs-mo/MOWorkSpace/mo-tester && ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-3rd/test/distributed/cases/ -i issue_24219
  • local TPC-DS repro with ../tpcds: web_exists_count=0, catalog_exists_count=1, or_exists_count=1 after the fix
  • TPC-DS query10 matches the PG golden result modulo CHAR padding whitespace

@qodo-code-review

Copy link
Copy Markdown
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@aunjgr aunjgr 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.

LGTM. The fix correctly addresses the row-inflation bug by aggregating the mark result across all build batches before emitting a single probe row.

Verified:

  • Batch-size early-exit saves probeIdx = i before processing row i, so re-entry is correct
  • ctr.batIdx = 0 reset after each MARK probe row is correct since the inner loop always runs to completion
  • The non-MARK path correctly drops the now-unreachable else branch
  • Test covers the exact scenario: duplicate matches split across build batches producing exactly one output row per probe row

Minor note (non-blocking): old MARK logic had rowCountIncrease++ inside the Rel != 0 branch of ResultCols (line 302 on main), meaning it incremented per mark-column rather than per row. With a single mark column it was harmless, but the new code fixes this implicitly by moving the increment outside the ResultCols loop.

@mergify mergify Bot added the queued label May 6, 2026
@mergify

mergify Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-06 06:03 UTC · Rule: main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-05-06 06:03 UTC · at 7268d3058b79a269deb9e5783b22a23caa25d83a · squash

This pull request spent 11 seconds in the queue, including 1 second running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • 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)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • 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)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • 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)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify
mergify Bot merged commit 07b6406 into matrixorigin:main May 6, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label May 6, 2026
fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
Correlated `EXISTS` subqueries are flattened into MARK JOINs. The loop join executor evaluated each build batch independently and emitted the same probe row once per build batch, so `EXISTS(A) OR EXISTS(B)` could inflate outer rows instead of acting as a boolean predicate.

This PR aggregates MARK JOIN condition results across all build batches before emitting the probe row. Each probe row now produces a single mark value (`true`, `NULL`, or `false`), preserving EXISTS/semi-join semantics. It also adds:
- unit tests covering duplicate matches split across build batches and MARK JOIN resume after the default output batch size
- a small BVT regression case with one outer row and 9000 inner rows, just enough to cross the 8192-row execution batch boundary

Validation:
- `CGO_CFLAGS="-I${ROOT}/thirdparties/install/include" CGO_LDFLAGS="-L${ROOT}/thirdparties/install/lib -Wl,-rpath,${ROOT}/thirdparties/install/lib" go test ./pkg/sql/colexec/loopjoin -coverprofile=/tmp/loopjoin_cover.out`
- `make build`
- `cd /Users/ghs-mo/MOWorkSpace/mo-tester && ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-3rd/test/distributed/cases/ -m genrs -i issue_24219`
- `cd /Users/ghs-mo/MOWorkSpace/mo-tester && ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-3rd/test/distributed/cases/ -i issue_24219`
- local TPC-DS repro with `../tpcds`: `web_exists_count=0`, `catalog_exists_count=1`, `or_exists_count=1` after the fix
- TPC-DS query10 matches the PG golden result modulo CHAR padding whitespace

Approved by: @aunjgr, @heni02
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Correlated `EXISTS` subqueries are flattened into MARK JOINs. The loop join executor evaluated each build batch independently and emitted the same probe row once per build batch, so `EXISTS(A) OR EXISTS(B)` could inflate outer rows instead of acting as a boolean predicate.

This PR aggregates MARK JOIN condition results across all build batches before emitting the probe row. Each probe row now produces a single mark value (`true`, `NULL`, or `false`), preserving EXISTS/semi-join semantics. It also adds:
- unit tests covering duplicate matches split across build batches and MARK JOIN resume after the default output batch size
- a small BVT regression case with one outer row and 9000 inner rows, just enough to cross the 8192-row execution batch boundary

Validation:
- `CGO_CFLAGS="-I${ROOT}/thirdparties/install/include" CGO_LDFLAGS="-L${ROOT}/thirdparties/install/lib -Wl,-rpath,${ROOT}/thirdparties/install/lib" go test ./pkg/sql/colexec/loopjoin -coverprofile=/tmp/loopjoin_cover.out`
- `make build`
- `cd /Users/ghs-mo/MOWorkSpace/mo-tester && ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-3rd/test/distributed/cases/ -m genrs -i issue_24219`
- `cd /Users/ghs-mo/MOWorkSpace/mo-tester && ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-3rd/test/distributed/cases/ -i issue_24219`
- local TPC-DS repro with `../tpcds`: `web_exists_count=0`, `catalog_exists_count=1`, `or_exists_count=1` after the fix
- TPC-DS query10 matches the PG golden result modulo CHAR padding whitespace

Approved by: @aunjgr, @heni02
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Correlated `EXISTS` subqueries are flattened into MARK JOINs. The loop join executor evaluated each build batch independently and emitted the same probe row once per build batch, so `EXISTS(A) OR EXISTS(B)` could inflate outer rows instead of acting as a boolean predicate.

This PR aggregates MARK JOIN condition results across all build batches before emitting the probe row. Each probe row now produces a single mark value (`true`, `NULL`, or `false`), preserving EXISTS/semi-join semantics. It also adds:
- unit tests covering duplicate matches split across build batches and MARK JOIN resume after the default output batch size
- a small BVT regression case with one outer row and 9000 inner rows, just enough to cross the 8192-row execution batch boundary

Validation:
- `CGO_CFLAGS="-I${ROOT}/thirdparties/install/include" CGO_LDFLAGS="-L${ROOT}/thirdparties/install/lib -Wl,-rpath,${ROOT}/thirdparties/install/lib" go test ./pkg/sql/colexec/loopjoin -coverprofile=/tmp/loopjoin_cover.out`
- `make build`
- `cd /Users/ghs-mo/MOWorkSpace/mo-tester && ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-3rd/test/distributed/cases/ -m genrs -i issue_24219`
- `cd /Users/ghs-mo/MOWorkSpace/mo-tester && ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-3rd/test/distributed/cases/ -i issue_24219`
- local TPC-DS repro with `../tpcds`: `web_exists_count=0`, `catalog_exists_count=1`, `or_exists_count=1` after the fix
- TPC-DS query10 matches the PG golden result modulo CHAR padding whitespace

Approved by: @aunjgr, @heni02
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Correlated `EXISTS` subqueries are flattened into MARK JOINs. The loop join executor evaluated each build batch independently and emitted the same probe row once per build batch, so `EXISTS(A) OR EXISTS(B)` could inflate outer rows instead of acting as a boolean predicate.

This PR aggregates MARK JOIN condition results across all build batches before emitting the probe row. Each probe row now produces a single mark value (`true`, `NULL`, or `false`), preserving EXISTS/semi-join semantics. It also adds:
- unit tests covering duplicate matches split across build batches and MARK JOIN resume after the default output batch size
- a small BVT regression case with one outer row and 9000 inner rows, just enough to cross the 8192-row execution batch boundary

Validation:
- `CGO_CFLAGS="-I${ROOT}/thirdparties/install/include" CGO_LDFLAGS="-L${ROOT}/thirdparties/install/lib -Wl,-rpath,${ROOT}/thirdparties/install/lib" go test ./pkg/sql/colexec/loopjoin -coverprofile=/tmp/loopjoin_cover.out`
- `make build`
- `cd /Users/ghs-mo/MOWorkSpace/mo-tester && ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-3rd/test/distributed/cases/ -m genrs -i issue_24219`
- `cd /Users/ghs-mo/MOWorkSpace/mo-tester && ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-3rd/test/distributed/cases/ -i issue_24219`
- local TPC-DS repro with `../tpcds`: `web_exists_count=0`, `catalog_exists_count=1`, `or_exists_count=1` after the fix
- TPC-DS query10 matches the PG golden result modulo CHAR padding whitespace

Approved by: @aunjgr, @heni02

This branch was previously deployed

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: EXISTS(A) OR EXISTS(B) correlated subqueries inflate outer rows (semi-join semantics broken)

3 participants