Skip to content

fix(plan): preserve grouped ENUM/SET numeric semantics - #28751

Merged
XuPeng-SH merged 4 commits into
mainfrom
codex/issue-28687-enum-set-grouped-numeric
Sep 12, 2026
Merged

XuPeng-SH merged 4 commits into
mainfrom
codex/issue-28687-enum-set-grouped-numeric

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 12, 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 #28687

What this PR does / why we need it:

Root cause

ENUM/SET values are bound through their visible labels for ordinary string semantics. After GROUP BY, the grouped value is represented by an output reference rather than the original display wrapper, so the numeric binder path loses the original type provenance and attempts to convert labels such as red or a to integers. This breaks e + 0 and s + 0 after grouping even though the row-level forms work.

Changes

  • Recover the original ENUM ordinal or SET bitmap only for numeric consumers of a reversible grouped value; leave group keys, visible labels, direct row-level conversion, and explicit lexical casts unchanged.
  • Apply the same operand-type contract to all-numeric IN/NOT IN lists, scalar subqueries in either direction, quantified comparisons, and tuple positions. Stage conversions before publishing subquery changes and preserve hidden projections used by flattening.
  • Add an internal-only zero-aware ENUM conversion mode so an invalid ENUM stored at ordinal 0 (displayed as an empty string) remains numeric 0 when the definition has no empty label. The existing public two-argument conversion behavior is unchanged.
  • Add planner/function regression tests and a SQL BVT covering grouped ENUM/SET values, NULL, ordinal 0, list/subquery/tuple/ANY comparisons, and a derived-table boundary.

Validation

  • make build NATIVE_BUILD_JOBS=8 — passed.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 ./pkg/sql/plan ./pkg/sql/plan/function — passed (plan 4.598s; plan/function 15.017s).
  • GOWORK=off go vet -mod=readonly ./pkg/sql/plan ./pkg/sql/plan/function — passed.
  • GOWORK=off golangci-lint run -c .golangci.yml --new-from-rev origin/main ./pkg/sql/plan ./pkg/sql/plan/function — 0 issues.
  • git diff --check — passed.
  • On a fresh task-local service built from this branch, mo-tester genrs produced the BVT result; normal comparison passed twice, 17/17 statements and 100% each run.

Performance and limitations

  • No aggregate state or group key is added. Recovery runs only for eligible grouped output values, not for every input row. No dedicated performance benchmark was run, so this PR does not claim zero performance impact.
  • Numeric recovery is deliberately disabled for ENUM definitions with a declared empty label: GROUP BY can merge that valid member with invalid ordinal 0, so the grouped display no longer identifies one unique stored value. Changing that grouping behavior is outside this PR.
  • Runtime BVT does not directly exercise CTE recovery or SET-valued subquery comparisons. CTE binding is covered by planner tests; SQL BVT covers SET grouped arithmetic and ENUM subquery comparisons.

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

@mergify mergify Bot added the kind/bug Something isn't working label Sep 12, 2026
@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Sep 12, 2026

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed head 99da16f against main e2580f9. COMMENT only for this self-authored PR.

P2 — Gate the new CAST_VALUE_TO_INDEX overload before remote execution. makeMySQLSpecialNumericValue now emits overload 1 (three arguments) for grouped ENUM numeric consumers, but the base revision only registers overload 0 and this change supplies no worker capability/version gate or local fallback. During a rolling upgrade, a new coordinator can send a projection containing this expression (for example a derived grouped ENUM consumed by numeric arithmetic) to a base-version CN; its GetFunctionById rejects the unknown overload with function overload id not found. A planner-internal-only flag does not protect the serialized executable expression. Please either express the zero-aware recovery using existing wire-compatible operators, or advertise/check a new capability and keep affected scopes local when a selected worker lacks it. Include an old-worker dispatch control for the generated expression.

The remaining review covered provenance/reversibility guards, preservation of display/group keys and explicit lexical casts, positional tuple/subquery rewrites and delayed publication, NULL/ordinal-zero/empty-batch behavior, legacy two-argument behavior, per-group conversion cost, and the planner/function/BVT oracles. No additional confirmed blocker. This is source-derived review; author-reported plan/function and normal-comparison BVT results were inspected, not independently rerun; no CI wait or native suite.

@XuPeng-SH
XuPeng-SH merged commit afe0f1a into main Sep 12, 2026
22 of 25 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/issue-28687-enum-set-grouped-numeric branch September 12, 2026 10:47
XuPeng-SH added a commit that referenced this pull request Sep 12, 2026
## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes #28781

## What this PR does / why we need it:

- Reduce the functional Arrow record-batch fanout fixture from 100,000
to 25,600 rows while retaining all 100 IPC record batches. A runtime
size assertion keeps it above the 1 MiB LOAD threshold, and the full row
identity/payload checks remain. The 100,000-row benchmark fixture is
unchanged.
- Make LocalMinIO bucket setup idempotent only for
`BucketAlreadyOwnedByYou`, which can follow a server-side bucket create
whose response was lost. Other errors remain failures.
- Add a deterministic lost-response test using the MinIO SDK and an
in-process HTTP server.
- No production SQL behavior changes.

## Test Plan

- On the 55 Linux/x86 host: full `TestArrowLoadBVT` (including
`DistributedRecordBatchFanout` and `LocalMinIO`) passed;
`TestArrowLoadForceMaterializeFallback` passed.
- `TestArrowLoadBucketCreateComplete`,
`TestArrowLoadBucketRetryAfterLostCreateResponse`, and
`TestRetryArrowLoadBucketStopsOnCancellation` passed normally and under
`-race`.
- `go vet -mod=readonly ./pkg/tests/arrowload`, gofmt, and `git diff
--check` passed.
- The 55-host test evidence used the unchanged source diff before
rebasing; the rebase added only upstream #28751 and #28760, which do not
touch the Arrow LOAD test paths. CI on the final head has not been
awaited.
- Local golangci-lint could not run because the installed binary targets
Go 1.24.4 while this repository requires Go 1.26.4; CI static analysis
remains the final check.
- The fanout case is smaller by row count while preserving its batch
count and LOAD path. Timing samples varied, so this PR does not claim a
statistically established end-to-end suite speedup.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…28751)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28687

## What this PR does / why we need it:

### Root cause

ENUM/SET values are bound through their visible labels for ordinary
string semantics. After `GROUP BY`, the grouped value is represented by
an output reference rather than the original display wrapper, so the
numeric binder path loses the original type provenance and attempts to
convert labels such as `red` or `a` to integers. This breaks `e + 0` and
`s + 0` after grouping even though the row-level forms work.

### Changes

- Recover the original ENUM ordinal or SET bitmap only for numeric
consumers of a reversible grouped value; leave group keys, visible
labels, direct row-level conversion, and explicit lexical casts
unchanged.
- Apply the same operand-type contract to all-numeric `IN`/`NOT IN`
lists, scalar subqueries in either direction, quantified comparisons,
and tuple positions. Stage conversions before publishing subquery
changes and preserve hidden projections used by flattening.
- Add an internal-only zero-aware ENUM conversion mode so an invalid
ENUM stored at ordinal 0 (displayed as an empty string) remains numeric
0 when the definition has no empty label. The existing public
two-argument conversion behavior is unchanged.
- Add planner/function regression tests and a SQL BVT covering grouped
ENUM/SET values, NULL, ordinal 0, list/subquery/tuple/ANY comparisons,
and a derived-table boundary.

### Validation

- `make build NATIVE_BUILD_JOBS=8` — passed.
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 ./pkg/sql/plan
./pkg/sql/plan/function` — passed (`plan` 4.598s; `plan/function`
15.017s).
- `GOWORK=off go vet -mod=readonly ./pkg/sql/plan
./pkg/sql/plan/function` — passed.
- `GOWORK=off golangci-lint run -c .golangci.yml --new-from-rev
origin/main ./pkg/sql/plan ./pkg/sql/plan/function` — 0 issues.
- `git diff --check` — passed.
- On a fresh task-local service built from this branch, `mo-tester
genrs` produced the BVT result; normal comparison passed twice, 17/17
statements and 100% each run.

### Performance and limitations

- No aggregate state or group key is added. Recovery runs only for
eligible grouped output values, not for every input row. No dedicated
performance benchmark was run, so this PR does not claim zero
performance impact.
- Numeric recovery is deliberately disabled for ENUM definitions with a
declared empty label: `GROUP BY` can merge that valid member with
invalid ordinal 0, so the grouped display no longer identifies one
unique stored value. Changing that grouping behavior is outside this PR.
- Runtime BVT does not directly exercise CTE recovery or SET-valued
subquery comparisons. CTE binding is covered by planner tests; SQL BVT
covers SET grouped arithmetic and ENUM subquery comparisons.
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
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28781

## What this PR does / why we need it:

- Reduce the functional Arrow record-batch fanout fixture from 100,000
to 25,600 rows while retaining all 100 IPC record batches. A runtime
size assertion keeps it above the 1 MiB LOAD threshold, and the full row
identity/payload checks remain. The 100,000-row benchmark fixture is
unchanged.
- Make LocalMinIO bucket setup idempotent only for
`BucketAlreadyOwnedByYou`, which can follow a server-side bucket create
whose response was lost. Other errors remain failures.
- Add a deterministic lost-response test using the MinIO SDK and an
in-process HTTP server.
- No production SQL behavior changes.

## Test Plan

- On the 55 Linux/x86 host: full `TestArrowLoadBVT` (including
`DistributedRecordBatchFanout` and `LocalMinIO`) passed;
`TestArrowLoadForceMaterializeFallback` passed.
- `TestArrowLoadBucketCreateComplete`,
`TestArrowLoadBucketRetryAfterLostCreateResponse`, and
`TestRetryArrowLoadBucketStopsOnCancellation` passed normally and under
`-race`.
- `go vet -mod=readonly ./pkg/tests/arrowload`, gofmt, and `git diff
--check` passed.
- The 55-host test evidence used the unchanged source diff before
rebasing; the rebase added only upstream matrixorigin#28751 and matrixorigin#28760, which do not
touch the Arrow LOAD test paths. CI on the final head has not been
awaited.
- Local golangci-lint could not run because the installed binary targets
Go 1.24.4 while this repository requires Go 1.26.4; CI static analysis
remains the final check.
- The fanout case is smaller by row count while preserving its batch
count and LOAD path. Timing samples varied, so this PR does not claim a
statistically established end-to-end suite speedup.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…28751)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28687

## What this PR does / why we need it:

### Root cause

ENUM/SET values are bound through their visible labels for ordinary
string semantics. After `GROUP BY`, the grouped value is represented by
an output reference rather than the original display wrapper, so the
numeric binder path loses the original type provenance and attempts to
convert labels such as `red` or `a` to integers. This breaks `e + 0` and
`s + 0` after grouping even though the row-level forms work.

### Changes

- Recover the original ENUM ordinal or SET bitmap only for numeric
consumers of a reversible grouped value; leave group keys, visible
labels, direct row-level conversion, and explicit lexical casts
unchanged.
- Apply the same operand-type contract to all-numeric `IN`/`NOT IN`
lists, scalar subqueries in either direction, quantified comparisons,
and tuple positions. Stage conversions before publishing subquery
changes and preserve hidden projections used by flattening.
- Add an internal-only zero-aware ENUM conversion mode so an invalid
ENUM stored at ordinal 0 (displayed as an empty string) remains numeric
0 when the definition has no empty label. The existing public
two-argument conversion behavior is unchanged.
- Add planner/function regression tests and a SQL BVT covering grouped
ENUM/SET values, NULL, ordinal 0, list/subquery/tuple/ANY comparisons,
and a derived-table boundary.

### Validation

- `make build NATIVE_BUILD_JOBS=8` — passed.
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 ./pkg/sql/plan
./pkg/sql/plan/function` — passed (`plan` 4.598s; `plan/function`
15.017s).
- `GOWORK=off go vet -mod=readonly ./pkg/sql/plan
./pkg/sql/plan/function` — passed.
- `GOWORK=off golangci-lint run -c .golangci.yml --new-from-rev
origin/main ./pkg/sql/plan ./pkg/sql/plan/function` — 0 issues.
- `git diff --check` — passed.
- On a fresh task-local service built from this branch, `mo-tester
genrs` produced the BVT result; normal comparison passed twice, 17/17
statements and 100% each run.

### Performance and limitations

- No aggregate state or group key is added. Recovery runs only for
eligible grouped output values, not for every input row. No dedicated
performance benchmark was run, so this PR does not claim zero
performance impact.
- Numeric recovery is deliberately disabled for ENUM definitions with a
declared empty label: `GROUP BY` can merge that valid member with
invalid ordinal 0, so the grouped display no longer identifies one
unique stored value. Changing that grouping behavior is outside this PR.
- Runtime BVT does not directly exercise CTE recovery or SET-valued
subquery comparisons. CTE binding is covered by planner tests; SQL BVT
covers SET grouped arithmetic and ENUM subquery comparisons.
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
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28781

## What this PR does / why we need it:

- Reduce the functional Arrow record-batch fanout fixture from 100,000
to 25,600 rows while retaining all 100 IPC record batches. A runtime
size assertion keeps it above the 1 MiB LOAD threshold, and the full row
identity/payload checks remain. The 100,000-row benchmark fixture is
unchanged.
- Make LocalMinIO bucket setup idempotent only for
`BucketAlreadyOwnedByYou`, which can follow a server-side bucket create
whose response was lost. Other errors remain failures.
- Add a deterministic lost-response test using the MinIO SDK and an
in-process HTTP server.
- No production SQL behavior changes.

## Test Plan

- On the 55 Linux/x86 host: full `TestArrowLoadBVT` (including
`DistributedRecordBatchFanout` and `LocalMinIO`) passed;
`TestArrowLoadForceMaterializeFallback` passed.
- `TestArrowLoadBucketCreateComplete`,
`TestArrowLoadBucketRetryAfterLostCreateResponse`, and
`TestRetryArrowLoadBucketStopsOnCancellation` passed normally and under
`-race`.
- `go vet -mod=readonly ./pkg/tests/arrowload`, gofmt, and `git diff
--check` passed.
- The 55-host test evidence used the unchanged source diff before
rebasing; the rebase added only upstream matrixorigin#28751 and matrixorigin#28760, which do not
touch the Arrow LOAD test paths. CI on the final head has not been
awaited.
- Local golangci-lint could not run because the installed binary targets
Go 1.24.4 while this repository requires Go 1.26.4; CI static analysis
remains the final check.
- The fanout case is smaller by row count while preserving its batch
count and LOAD path. Timing samples varied, so this PR does not claim a
statistically established end-to-end suite speedup.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…28751)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28687

## What this PR does / why we need it:

### Root cause

ENUM/SET values are bound through their visible labels for ordinary
string semantics. After `GROUP BY`, the grouped value is represented by
an output reference rather than the original display wrapper, so the
numeric binder path loses the original type provenance and attempts to
convert labels such as `red` or `a` to integers. This breaks `e + 0` and
`s + 0` after grouping even though the row-level forms work.

### Changes

- Recover the original ENUM ordinal or SET bitmap only for numeric
consumers of a reversible grouped value; leave group keys, visible
labels, direct row-level conversion, and explicit lexical casts
unchanged.
- Apply the same operand-type contract to all-numeric `IN`/`NOT IN`
lists, scalar subqueries in either direction, quantified comparisons,
and tuple positions. Stage conversions before publishing subquery
changes and preserve hidden projections used by flattening.
- Add an internal-only zero-aware ENUM conversion mode so an invalid
ENUM stored at ordinal 0 (displayed as an empty string) remains numeric
0 when the definition has no empty label. The existing public
two-argument conversion behavior is unchanged.
- Add planner/function regression tests and a SQL BVT covering grouped
ENUM/SET values, NULL, ordinal 0, list/subquery/tuple/ANY comparisons,
and a derived-table boundary.

### Validation

- `make build NATIVE_BUILD_JOBS=8` — passed.
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 ./pkg/sql/plan
./pkg/sql/plan/function` — passed (`plan` 4.598s; `plan/function`
15.017s).
- `GOWORK=off go vet -mod=readonly ./pkg/sql/plan
./pkg/sql/plan/function` — passed.
- `GOWORK=off golangci-lint run -c .golangci.yml --new-from-rev
origin/main ./pkg/sql/plan ./pkg/sql/plan/function` — 0 issues.
- `git diff --check` — passed.
- On a fresh task-local service built from this branch, `mo-tester
genrs` produced the BVT result; normal comparison passed twice, 17/17
statements and 100% each run.

### Performance and limitations

- No aggregate state or group key is added. Recovery runs only for
eligible grouped output values, not for every input row. No dedicated
performance benchmark was run, so this PR does not claim zero
performance impact.
- Numeric recovery is deliberately disabled for ENUM definitions with a
declared empty label: `GROUP BY` can merge that valid member with
invalid ordinal 0, so the grouped display no longer identifies one
unique stored value. Changing that grouping behavior is outside this PR.
- Runtime BVT does not directly exercise CTE recovery or SET-valued
subquery comparisons. CTE binding is covered by planner tests; SQL BVT
covers SET grouped arithmetic and ENUM subquery comparisons.
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
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28781

## What this PR does / why we need it:

- Reduce the functional Arrow record-batch fanout fixture from 100,000
to 25,600 rows while retaining all 100 IPC record batches. A runtime
size assertion keeps it above the 1 MiB LOAD threshold, and the full row
identity/payload checks remain. The 100,000-row benchmark fixture is
unchanged.
- Make LocalMinIO bucket setup idempotent only for
`BucketAlreadyOwnedByYou`, which can follow a server-side bucket create
whose response was lost. Other errors remain failures.
- Add a deterministic lost-response test using the MinIO SDK and an
in-process HTTP server.
- No production SQL behavior changes.

## Test Plan

- On the 55 Linux/x86 host: full `TestArrowLoadBVT` (including
`DistributedRecordBatchFanout` and `LocalMinIO`) passed;
`TestArrowLoadForceMaterializeFallback` passed.
- `TestArrowLoadBucketCreateComplete`,
`TestArrowLoadBucketRetryAfterLostCreateResponse`, and
`TestRetryArrowLoadBucketStopsOnCancellation` passed normally and under
`-race`.
- `go vet -mod=readonly ./pkg/tests/arrowload`, gofmt, and `git diff
--check` passed.
- The 55-host test evidence used the unchanged source diff before
rebasing; the rebase added only upstream matrixorigin#28751 and matrixorigin#28760, which do not
touch the Arrow LOAD test paths. CI on the final head has not been
awaited.
- Local golangci-lint could not run because the installed binary targets
Go 1.24.4 while this repository requires Go 1.26.4; CI static analysis
remains the final check.
- The fanout case is smaller by row count while preserving its batch
count and LOAD path. Timing samples varied, so this PR does not claim a
statistically established end-to-end suite speedup.
XuPeng-SH added a commit that referenced this pull request Nov 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes #32819

## What this PR does / why we need it:

On 4.2-dev, numeric operations on a grouped ENUM or SET can attempt to
convert its display label instead of using its ordinal or bitmap. For
example, grouping `ENUM('a','b')` and selecting `e + 0` fails on the
label `a` even though the corresponding row-level expression succeeds.

Adapt the approach from #28751 to 4.2's existing ENUM encoding and
provenance rules. Recover the stored numeric value only when the
original domain is known and reversible, including numeric casts, scalar
comparisons, IN/quantified subqueries, and the correlated scalar and
projection forms covered by the regression tests. Keep string
comparisons and ambiguous domains on their existing paths. A numeric IN
list may contain NULL without losing its numeric comparison semantics.

This reuses existing conversion overloads and does not change persisted
formats. Numeric operations on grouped or projected values add
conversion work for those expressions only. The general correlated
scalar projection path for a subquery with its own FROM remains
unsupported by the existing executor; the same query shape also fails
with ordinary integer columns on the exact 4.2-dev base. Legacy overload
compatibility was checked against the source and serialized plans;
mixed-version execution was not tested.

Validation on the 57 host (Go 1.26.4, isolated single-CN instance):

- `./pkg/sql/plan`: full normal and race runs, plus focused race tests.
- New SQL BVT: 39/39 twice, with teardown verified; existing ENUM domain
BVT: 137/137. The normal mo-tester comparison ignores result metadata.
- `gofmt`, `go vet`, and incremental golangci-lint: passed. The
4.2-pinned molint reports five existing findings identical to the clean
base.

GitHub CI will provide the remaining integration checks.

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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: grouped ENUM and SET values lose numeric ordinal semantics

2 participants