Repository navigation
perf: reduce redundant group-by hash keys - #26727
Merged
Merged
Conversation
XuPeng-SH
approved these changes
Aug 5, 2026
XuPeng-SH
left a comment
Contributor
There was a problem hiding this comment.
Reviewed exact head 66df311. The functional-dependency optimization is conservative: it removes only direct same-table non-PK keys when a complete real PK is present, while retaining the logical GroupBy contract. Planner rewrites and local/merge/spill/shuffle/codec lifecycle paths were checked. Full controlled CGo group/plan/compile/explain tests and the full group race suite passed. APPROVE.
XuPeng-SH
force-pushed
the
feature/groupby-minimal-hash
branch
from
August 5, 2026 16:19
66df311 to
c2bf4ed
Compare
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#13680 ## What this PR does / why we need it: This PR keeps the logical `GROUP BY` expressions unchanged while allowing the executor to hash only an optimizer-proven physical equality key. When a complete base-table primary key is present, non-key columns from the same table no longer need to participate in hash-table equality. The change: - derives a physical group-by hash key from complete primary-key metadata, with conservative fallbacks for grouping sets, derived expressions, fake keys, and unavailable composite-key components; - propagates the key through local Group, MergeGroup, spill/reload, operator duplication, and remote pipeline encoding; - keeps the protobuf change backward-compatible: an empty or missing field uses all logical group-by expressions; - updates aggregate cardinality estimation, shuffle selection, text/JSON explain output, and DISTINCT aggregate rewrites; - validates physical-key indices at execution boundaries and preserves the full logical group output. Benchmark with 8,192 rows, 4,096 groups, one integer primary key, and four wide VARCHAR columns: - full logical key: 2.43-2.78 ms/op, 141-144 KiB/op; - integer primary key: 1.34-1.39 ms/op, 16.5-16.7 KiB/op. Validation: - `make pb` - `go build` and `go vet` for `pkg/sql/plan`, `pkg/sql/colexec/group`, `pkg/sql/compile`, and `pkg/sql/plan/explain` - full tests for the same packages - race test for `pkg/sql/colexec/group` - planner, DISTINCT, shuffle, Group/MergeGroup, spill/reload, reset/reuse, explain, and remote-codec regression tests
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#13680 ## What this PR does / why we need it: This PR keeps the logical `GROUP BY` expressions unchanged while allowing the executor to hash only an optimizer-proven physical equality key. When a complete base-table primary key is present, non-key columns from the same table no longer need to participate in hash-table equality. The change: - derives a physical group-by hash key from complete primary-key metadata, with conservative fallbacks for grouping sets, derived expressions, fake keys, and unavailable composite-key components; - propagates the key through local Group, MergeGroup, spill/reload, operator duplication, and remote pipeline encoding; - keeps the protobuf change backward-compatible: an empty or missing field uses all logical group-by expressions; - updates aggregate cardinality estimation, shuffle selection, text/JSON explain output, and DISTINCT aggregate rewrites; - validates physical-key indices at execution boundaries and preserves the full logical group output. Benchmark with 8,192 rows, 4,096 groups, one integer primary key, and four wide VARCHAR columns: - full logical key: 2.43-2.78 ms/op, 141-144 KiB/op; - integer primary key: 1.34-1.39 ms/op, 16.5-16.7 KiB/op. Validation: - `make pb` - `go build` and `go vet` for `pkg/sql/plan`, `pkg/sql/colexec/group`, `pkg/sql/compile`, and `pkg/sql/plan/explain` - full tests for the same packages - race test for `pkg/sql/colexec/group` - planner, DISTINCT, shuffle, Group/MergeGroup, spill/reload, reset/reuse, explain, and remote-codec regression tests
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#13680 ## What this PR does / why we need it: This PR keeps the logical `GROUP BY` expressions unchanged while allowing the executor to hash only an optimizer-proven physical equality key. When a complete base-table primary key is present, non-key columns from the same table no longer need to participate in hash-table equality. The change: - derives a physical group-by hash key from complete primary-key metadata, with conservative fallbacks for grouping sets, derived expressions, fake keys, and unavailable composite-key components; - propagates the key through local Group, MergeGroup, spill/reload, operator duplication, and remote pipeline encoding; - keeps the protobuf change backward-compatible: an empty or missing field uses all logical group-by expressions; - updates aggregate cardinality estimation, shuffle selection, text/JSON explain output, and DISTINCT aggregate rewrites; - validates physical-key indices at execution boundaries and preserves the full logical group output. Benchmark with 8,192 rows, 4,096 groups, one integer primary key, and four wide VARCHAR columns: - full logical key: 2.43-2.78 ms/op, 141-144 KiB/op; - integer primary key: 1.34-1.39 ms/op, 16.5-16.7 KiB/op. Validation: - `make pb` - `go build` and `go vet` for `pkg/sql/plan`, `pkg/sql/colexec/group`, `pkg/sql/compile`, and `pkg/sql/plan/explain` - full tests for the same packages - race test for `pkg/sql/colexec/group` - planner, DISTINCT, shuffle, Group/MergeGroup, spill/reload, reset/reuse, explain, and remote-codec regression tests
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #13680
What this PR does / why we need it:
This PR keeps the logical
GROUP BYexpressions unchanged while allowing the executor to hash only an optimizer-proven physical equality key. When a complete base-table primary key is present, non-key columns from the same table no longer need to participate in hash-table equality.The change:
Benchmark with 8,192 rows, 4,096 groups, one integer primary key, and four wide VARCHAR columns:
Validation:
make pbgo buildandgo vetforpkg/sql/plan,pkg/sql/colexec/group,pkg/sql/compile, andpkg/sql/plan/explainpkg/sql/colexec/group