Skip to content

fix(compile): deduplicate parallel distinct set results - #27544

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
Lundomn:fix/intersect-distinct-parallel-27525
Aug 24, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
Lundomn:fix/intersect-distinct-parallel-27525

Conversation

@Lundomn

@Lundomn Lundomn commented Aug 24, 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 #27525

What this PR does / why we need it:

Parallel INTERSECT and MINUS execute one distinct set operator per worker. Each worker removes duplicates locally, but the worker outputs were merged without a final global distinct phase. As a result, the same set key could be returned once per worker, causing duplicate rows and incorrect downstream aggregates for ordinary INTERSECT / INTERSECT DISTINCT.

This change extracts the existing UNION DISTINCT merge-and-group logic into a shared helper and applies it after parallel INTERSECT and MINUS. INTERSECT ALL and the single-worker path retain their existing behavior. The group expressions remain nullable so NULL set keys preserve SQL distinct semantics.

Regression tests verify:

  • parallel INTERSECT and MINUS add a global distinct merge;
  • INTERSECT ALL keeps its per-worker results without the distinct merge;
  • UNION DISTINCT retains its existing global merge behavior;
  • nullable group expressions are deep-copied and retain nullable semantics.

Tests completed locally on latest main (ba8954d543af0bdfb1948a8b89f77f5235ac9259):

  • go test -mod=readonly ./pkg/sql/compile -count=1
  • go test -mod=readonly -race ./pkg/sql/compile -count=1
  • go vet -mod=readonly ./pkg/sql/compile
  • latest-main mo-service build
  • 500,257-row standalone regression with parallel scans, nullable set keys, and aggregate checks; expected and actual result: (859, 858, 429429, 1)

@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 →

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

Deep-reviewed exact head 1461404. The final GROUP correctly provides cross-worker deduplication for parallel INTERSECT/MINUS, while the single-scope path and INTERSECT ALL remain unchanged. Full compile tests, focused race runs, go vet, formatting/diff checks, and a clean merge-tree check passed.

@mergify

mergify Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-24 09:24 UTC · Rule: main · triggered by @Lundomn with the merge queue checkbox
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-24 10:19 UTC · at 1d60094462781d2fb1ac396200daeb38755d4a25 · squash

This pull request spent 54 minutes 55 seconds in the queue, including 54 minutes 4 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • 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 CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify mergify Bot added the queued label Aug 24, 2026
@mergify
mergify Bot merged commit 47217cb into matrixorigin:main Aug 24, 2026
33 checks passed
@mergify mergify Bot removed the queued label Aug 24, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#27544)

Parallel `INTERSECT` and `MINUS` execute one distinct set operator per worker. Each worker removes duplicates locally, but the worker outputs were merged without a final global distinct phase. As a result, the same set key could be returned once per worker, causing duplicate rows and incorrect downstream aggregates for ordinary `INTERSECT` / `INTERSECT DISTINCT`.

This change extracts the existing `UNION DISTINCT` merge-and-group logic into a shared helper and applies it after parallel `INTERSECT` and `MINUS`. `INTERSECT ALL` and the single-worker path retain their existing behavior. The group expressions remain nullable so NULL set keys preserve SQL distinct semantics.

Regression tests verify:

- parallel `INTERSECT` and `MINUS` add a global distinct merge;
- `INTERSECT ALL` keeps its per-worker results without the distinct merge;
- `UNION DISTINCT` retains its existing global merge behavior;
- nullable group expressions are deep-copied and retain nullable semantics.

Tests completed locally on latest `main` (`ba8954d543af0bdfb1948a8b89f77f5235ac9259`):

- `go test -mod=readonly ./pkg/sql/compile -count=1`
- `go test -mod=readonly -race ./pkg/sql/compile -count=1`
- `go vet -mod=readonly ./pkg/sql/compile`
- latest-main `mo-service` build
- 500,257-row standalone regression with parallel scans, nullable set keys, and aggregate checks; expected and actual result: `(859, 858, 429429, 1)`

Approved by: @aptend
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#27544)

Parallel `INTERSECT` and `MINUS` execute one distinct set operator per worker. Each worker removes duplicates locally, but the worker outputs were merged without a final global distinct phase. As a result, the same set key could be returned once per worker, causing duplicate rows and incorrect downstream aggregates for ordinary `INTERSECT` / `INTERSECT DISTINCT`.

This change extracts the existing `UNION DISTINCT` merge-and-group logic into a shared helper and applies it after parallel `INTERSECT` and `MINUS`. `INTERSECT ALL` and the single-worker path retain their existing behavior. The group expressions remain nullable so NULL set keys preserve SQL distinct semantics.

Regression tests verify:

- parallel `INTERSECT` and `MINUS` add a global distinct merge;
- `INTERSECT ALL` keeps its per-worker results without the distinct merge;
- `UNION DISTINCT` retains its existing global merge behavior;
- nullable group expressions are deep-copied and retain nullable semantics.

Tests completed locally on latest `main` (`ba8954d543af0bdfb1948a8b89f77f5235ac9259`):

- `go test -mod=readonly ./pkg/sql/compile -count=1`
- `go test -mod=readonly -race ./pkg/sql/compile -count=1`
- `go vet -mod=readonly ./pkg/sql/compile`
- latest-main `mo-service` build
- 500,257-row standalone regression with parallel scans, nullable set keys, and aggregate checks; expected and actual result: `(859, 858, 429429, 1)`

Approved by: @aptend
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#27544)

Parallel `INTERSECT` and `MINUS` execute one distinct set operator per worker. Each worker removes duplicates locally, but the worker outputs were merged without a final global distinct phase. As a result, the same set key could be returned once per worker, causing duplicate rows and incorrect downstream aggregates for ordinary `INTERSECT` / `INTERSECT DISTINCT`.

This change extracts the existing `UNION DISTINCT` merge-and-group logic into a shared helper and applies it after parallel `INTERSECT` and `MINUS`. `INTERSECT ALL` and the single-worker path retain their existing behavior. The group expressions remain nullable so NULL set keys preserve SQL distinct semantics.

Regression tests verify:

- parallel `INTERSECT` and `MINUS` add a global distinct merge;
- `INTERSECT ALL` keeps its per-worker results without the distinct merge;
- `UNION DISTINCT` retains its existing global merge behavior;
- nullable group expressions are deep-copied and retain nullable semantics.

Tests completed locally on latest `main` (`ba8954d543af0bdfb1948a8b89f77f5235ac9259`):

- `go test -mod=readonly ./pkg/sql/compile -count=1`
- `go test -mod=readonly -race ./pkg/sql/compile -count=1`
- `go vet -mod=readonly ./pkg/sql/compile`
- latest-main `mo-service` build
- 500,257-row standalone regression with parallel scans, nullable set keys, and aggregate checks; expected and actual result: `(859, 858, 429429, 1)`

Approved by: @aptend

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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: INTERSECT DISTINCT duplicates set keys under parallel scans

3 participants