pkg/expression/grouping_sets.go — pairwise intersection check in NeedCloneColumn()
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
Location:
- pkg/expression/grouping_sets.go:203-214
Current pattern:
- Builds setIDs, then checks every pair for intersection.
Estimated current complexity:
- O(N²) set intersection checks across grouping sets.
Recommended change:
- Single pass with a cumulative seen set:
- if current set intersects seen, return true
- otherwise union it into seen
Estimated after:
- O(N) intersections/unions.
Risk:
- Low. The logic only asks: “does any column appear in more than one grouping set?”
Tests needed:
- Existing grouping-set tests may cover this.
- Add explicit overlap/non-overlap cases if absent.
NeedCloneColumn() currently performs pairwise intersection (pkg/expression/grouping_sets.go:200). Changing it to "cumulative single-pass checking of seen sets" is logically equivalent, has low risk, and is a clean optimization.
Contributor guide
Assessment
This issue has not been assessed yet.