Skip to content

fix(frontend): support native bit pick keys - #26611

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26074-f89f631d
Aug 3, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26074-f89f631d

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Aug 3, 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 #26074

What this PR does / why we need it:

Root cause

Current main accepts BOOL literals and decimal BIT keys, but a native BIT literal is represented by the MySQL parser as a tree.P_bit NumVal whose canonical string is 0b.... The literal-key path sent that string to the generic BIT coercion function, which parses already-normalized decimal values in base 10. It therefore rejected the binary prefix before key materialization, while typed subquery values already arrived as normalized decimal strings.

The same mismatch affected transparent AST wrappers. Unary +b'1' became +0b1, but exact integer normalization was limited to Go integer target OIDs and types.T_bit.IsInteger() is false. Parentheses then introduced tree.ParenExpr nodes that the literal classifier did not peel, so equivalent forms such as +(b'1'), (+b'1'), and a parenthesized BIT component in a composite key were rejected based only on AST shape.

Finally, the scanner intentionally accepts the empty native BIT literal b'' and canonicalizes it to 0b, matching the normal typed SQL meaning of zero. The native-literal decoder required at least one binary digit after the prefix, so PICK incorrectly classified this valid parser output as malformed.

Changes

  • Use one shared predicate for numeric AST forms that require exact integer normalization, preserving existing hexadecimal/fractional-number behavior and adding tree.P_bit only for BIT primary keys.
  • Decode native BIT literals as exact base-2 integers at the AST boundary, then feed their normalized decimal value into the existing BIT width/range check and vector append path.
  • Normalize the parser's canonical empty P_bit value to zero while retaining rejection of malformed programmatic P_bit AST strings.
  • Peel all transparent tree.ParenExpr layers before classifying the literal and again before classifying a unary operand. Arbitrary non-literal expressions remain unsupported.
  • Apply the same conversion to direct and unary-wrapped BIT literals: unary plus preserves the value, while unary minus remains invalid through the existing unsigned BIT range check.
  • Extend parser-to-vector unit and public BVT coverage across direct, unary, parenthesized, empty, composite, boundary, malformed, overflow, negative, and failure-atomicity cases.

Issue-to-test proof

Issue behavior Executable proof
BOOL literal and numeric keys BVT covers false, true, 0, and 1, including update, delete, and conflict modes.
Decimal BIT literal vs typed subquery BVT applies key 1, then applies the other BIT key through a typed subquery and verifies identical row semantics.
Native b'...' / B'...' BIT literals Unit tests parse full DATA BRANCH PICK ... KEYS(...) statements; BVT verifies single and composite PK application.
Empty native BIT literal Unit/BVT verify KEYS(b'') selects only the BIT zero key.
Unary and transparent-parenthesis forms Unit/BVT verify +b'1', +(b'1'), (+b'1'), nested parentheses, and parenthesized BIT components in composite keys.
BIT boundaries Unit/BVT cover BIT(1), BIT(8) zero/max, BIT(64) zero/signed boundary/uint64 max, including unary-plus BIT(8) max.
Invalid values and atomicity Unit tests verify negative, overflow, non-literal, and malformed programmatic P_bit inputs fail without vector mutation; BVT puts a rejected key after a valid key and verifies the destination remains unchanged.

Tests run

  • Pre-fix focused parser-to-vector regression reproduced the empty/parenthesized failures.
  • make build
  • go vet -mod=readonly ./pkg/frontend with the repository CGo environment
  • Focused parser-to-vector tests for direct, unary, parenthesized, empty, malformed, boundary, and sign cases: pass
  • Focused test selection explicitly listed all four intended tests
  • Focused parser-to-vector race run: -race -count=3 pass
  • Focused coverage profile: unwrapPickKeyParens 100%
  • Full controlled CGo package test: ./pkg/frontend pass
  • Focused public BVT against the locally built server: 89/89 strict comparisons pass; every added expected row set was manually checked for selection semantics and failure atomicity

CI follow-up

The first Coverage job failed because only 4/6 changed production-code blocks were exercised (66.67%, below the required >75%). Commit c5ff0283af added malformed-AST tests for the defensive error branches. A later Ubuntu/x86 UT failure was unrelated (TestDeleterConcurrentDelete, tracked by #26643); the single permitted failed-job rerun completed successfully.

Residual risks

The change adds an O(parenthesis depth), allocation-free AST walk plus one short-lived big.Int parse per native BIT literal. Parsed statement size bounds both costs. It does not alter APIs, storage, wire formats, concurrency, or generic string/subquery coercion, and non-BIT targets retain their prior behavior. No known functional residual remains for #26074.

@gouhongshen

gouhongshen commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

The unrelated Ubuntu/x86 UT blocker tracked by #26643 is resolved for this PR: the single permitted failed-job rerun completed successfully. There are no unresolved unrelated CI blockers. Successful rerun: https://github.com/matrixorigin/matrixone/actions/runs/30802660355/job/91661483282

@gouhongshen
gouhongshen marked this pull request as ready for review August 3, 2026 07:49
@gouhongshen
gouhongshen requested a review from XuPeng-SH as a code owner August 3, 2026 07:49
@gouhongshen
gouhongshen requested a review from a user August 3, 2026 07:49
@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 →

@gouhongshen

Copy link
Copy Markdown
Contributor Author

Addressed both P1 findings from XuPeng-SH's review in c07af6a301.

The findings were valid and in scope:

  • appendExprToVec now peels every transparent tree.ParenExpr before classifying the key and before classifying a unary operand. This covers +(b'1'), (+b'1'), nested wrappers, and a parenthesized BIT component in a composite key without admitting arbitrary expressions.
  • The parser's canonical empty P_bit value 0b now normalizes to zero. Malformed programmatic prefixes/digits, unary minus, and BIT-width overflow still fail before vector/hashmap application.

Executable proof on the updated head:

  • pre-fix focused UT reproduced every reported failure; post-fix focused UT passes
  • focused test selection lists all four intended parser-to-vector tests
  • focused -race -count=3: pass
  • full pkg/frontend: pass
  • go vet -mod=readonly ./pkg/frontend: pass
  • strict public BVT: 89/89, including KEYS(b''), both reported parenthesized unary forms, a composite parenthesized BIT component, and failure atomicity
  • make build: pass

There is no inline review thread to resolve, so I am re-requesting review on c07af6a301.

@gouhongshen
gouhongshen requested a review from XuPeng-SH August 3, 2026 12:26
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Aug 3, 2026

@XuPeng-SH XuPeng-SH 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.

Reviewed exact head c07af6a. The BIT literal conversion preserves unsigned width/range checks, unary signs, and transparent parentheses; focused frontend conversion tests passed, and the SQL regression covers public PICK behavior and atomic failure. No blocking issue found.

@XuPeng-SH
XuPeng-SH merged commit bb011f2 into matrixorigin:main Aug 3, 2026
25 checks passed
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
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26074

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

### Root cause

Current `main` accepts BOOL literals and decimal BIT keys, but a native
BIT literal is represented by the MySQL parser as a `tree.P_bit`
`NumVal` whose canonical string is `0b...`. The literal-key path sent
that string to the generic BIT coercion function, which parses
already-normalized decimal values in base 10. It therefore rejected the
binary prefix before key materialization, while typed subquery values
already arrived as normalized decimal strings.

The same mismatch affected transparent AST wrappers. Unary `+b'1'`
became `+0b1`, but exact integer normalization was limited to Go integer
target OIDs and `types.T_bit.IsInteger()` is false. Parentheses then
introduced `tree.ParenExpr` nodes that the literal classifier did not
peel, so equivalent forms such as `+(b'1')`, `(+b'1')`, and a
parenthesized BIT component in a composite key were rejected based only
on AST shape.

Finally, the scanner intentionally accepts the empty native BIT literal
`b''` and canonicalizes it to `0b`, matching the normal typed SQL
meaning of zero. The native-literal decoder required at least one binary
digit after the prefix, so PICK incorrectly classified this valid parser
output as malformed.

### Changes

- Use one shared predicate for numeric AST forms that require exact
integer normalization, preserving existing hexadecimal/fractional-number
behavior and adding `tree.P_bit` only for BIT primary keys.
- Decode native BIT literals as exact base-2 integers at the AST
boundary, then feed their normalized decimal value into the existing BIT
width/range check and vector append path.
- Normalize the parser's canonical empty `P_bit` value to zero while
retaining rejection of malformed programmatic `P_bit` AST strings.
- Peel all transparent `tree.ParenExpr` layers before classifying the
literal and again before classifying a unary operand. Arbitrary
non-literal expressions remain unsupported.
- Apply the same conversion to direct and unary-wrapped BIT literals:
unary plus preserves the value, while unary minus remains invalid
through the existing unsigned BIT range check.
- Extend parser-to-vector unit and public BVT coverage across direct,
unary, parenthesized, empty, composite, boundary, malformed, overflow,
negative, and failure-atomicity cases.

### Issue-to-test proof

| Issue behavior | Executable proof |
| --- | --- |
| BOOL literal and numeric keys | BVT covers `false`, `true`, `0`, and
`1`, including update, delete, and conflict modes. |
| Decimal BIT literal vs typed subquery | BVT applies key `1`, then
applies the other BIT key through a typed subquery and verifies
identical row semantics. |
| Native `b'...'` / `B'...'` BIT literals | Unit tests parse full `DATA
BRANCH PICK ... KEYS(...)` statements; BVT verifies single and composite
PK application. |
| Empty native BIT literal | Unit/BVT verify `KEYS(b'')` selects only
the BIT zero key. |
| Unary and transparent-parenthesis forms | Unit/BVT verify `+b'1'`,
`+(b'1')`, `(+b'1')`, nested parentheses, and parenthesized BIT
components in composite keys. |
| BIT boundaries | Unit/BVT cover BIT(1), BIT(8) zero/max, BIT(64)
zero/signed boundary/uint64 max, including unary-plus BIT(8) max. |
| Invalid values and atomicity | Unit tests verify negative, overflow,
non-literal, and malformed programmatic `P_bit` inputs fail without
vector mutation; BVT puts a rejected key after a valid key and verifies
the destination remains unchanged. |

### Tests run

- Pre-fix focused parser-to-vector regression reproduced the
empty/parenthesized failures.
- `make build`
- `go vet -mod=readonly ./pkg/frontend` with the repository CGo
environment
- Focused parser-to-vector tests for direct, unary, parenthesized,
empty, malformed, boundary, and sign cases: pass
- Focused test selection explicitly listed all four intended tests
- Focused parser-to-vector race run: `-race -count=3` pass
- Focused coverage profile: `unwrapPickKeyParens` 100%
- Full controlled CGo package test: `./pkg/frontend` pass
- Focused public BVT against the locally built server: 89/89 strict
comparisons pass; every added expected row set was manually checked for
selection semantics and failure atomicity

### CI follow-up

The first Coverage job failed because only 4/6 changed production-code
blocks were exercised (66.67%, below the required >75%). Commit
`c5ff0283af` added malformed-AST tests for the defensive error branches.
A later Ubuntu/x86 UT failure was unrelated
(`TestDeleterConcurrentDelete`, tracked by matrixorigin#26643); the single permitted
failed-job rerun completed successfully.

### Residual risks

The change adds an O(parenthesis depth), allocation-free AST walk plus
one short-lived `big.Int` parse per native BIT literal. Parsed statement
size bounds both costs. It does not alter APIs, storage, wire formats,
concurrency, or generic string/subquery coercion, and non-BIT targets
retain their prior behavior. No known functional residual remains for
matrixorigin#26074.

---------

Co-authored-by: XuPeng-SH <[email protected]>
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
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26074

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

### Root cause

Current `main` accepts BOOL literals and decimal BIT keys, but a native
BIT literal is represented by the MySQL parser as a `tree.P_bit`
`NumVal` whose canonical string is `0b...`. The literal-key path sent
that string to the generic BIT coercion function, which parses
already-normalized decimal values in base 10. It therefore rejected the
binary prefix before key materialization, while typed subquery values
already arrived as normalized decimal strings.

The same mismatch affected transparent AST wrappers. Unary `+b'1'`
became `+0b1`, but exact integer normalization was limited to Go integer
target OIDs and `types.T_bit.IsInteger()` is false. Parentheses then
introduced `tree.ParenExpr` nodes that the literal classifier did not
peel, so equivalent forms such as `+(b'1')`, `(+b'1')`, and a
parenthesized BIT component in a composite key were rejected based only
on AST shape.

Finally, the scanner intentionally accepts the empty native BIT literal
`b''` and canonicalizes it to `0b`, matching the normal typed SQL
meaning of zero. The native-literal decoder required at least one binary
digit after the prefix, so PICK incorrectly classified this valid parser
output as malformed.

### Changes

- Use one shared predicate for numeric AST forms that require exact
integer normalization, preserving existing hexadecimal/fractional-number
behavior and adding `tree.P_bit` only for BIT primary keys.
- Decode native BIT literals as exact base-2 integers at the AST
boundary, then feed their normalized decimal value into the existing BIT
width/range check and vector append path.
- Normalize the parser's canonical empty `P_bit` value to zero while
retaining rejection of malformed programmatic `P_bit` AST strings.
- Peel all transparent `tree.ParenExpr` layers before classifying the
literal and again before classifying a unary operand. Arbitrary
non-literal expressions remain unsupported.
- Apply the same conversion to direct and unary-wrapped BIT literals:
unary plus preserves the value, while unary minus remains invalid
through the existing unsigned BIT range check.
- Extend parser-to-vector unit and public BVT coverage across direct,
unary, parenthesized, empty, composite, boundary, malformed, overflow,
negative, and failure-atomicity cases.

### Issue-to-test proof

| Issue behavior | Executable proof |
| --- | --- |
| BOOL literal and numeric keys | BVT covers `false`, `true`, `0`, and
`1`, including update, delete, and conflict modes. |
| Decimal BIT literal vs typed subquery | BVT applies key `1`, then
applies the other BIT key through a typed subquery and verifies
identical row semantics. |
| Native `b'...'` / `B'...'` BIT literals | Unit tests parse full `DATA
BRANCH PICK ... KEYS(...)` statements; BVT verifies single and composite
PK application. |
| Empty native BIT literal | Unit/BVT verify `KEYS(b'')` selects only
the BIT zero key. |
| Unary and transparent-parenthesis forms | Unit/BVT verify `+b'1'`,
`+(b'1')`, `(+b'1')`, nested parentheses, and parenthesized BIT
components in composite keys. |
| BIT boundaries | Unit/BVT cover BIT(1), BIT(8) zero/max, BIT(64)
zero/signed boundary/uint64 max, including unary-plus BIT(8) max. |
| Invalid values and atomicity | Unit tests verify negative, overflow,
non-literal, and malformed programmatic `P_bit` inputs fail without
vector mutation; BVT puts a rejected key after a valid key and verifies
the destination remains unchanged. |

### Tests run

- Pre-fix focused parser-to-vector regression reproduced the
empty/parenthesized failures.
- `make build`
- `go vet -mod=readonly ./pkg/frontend` with the repository CGo
environment
- Focused parser-to-vector tests for direct, unary, parenthesized,
empty, malformed, boundary, and sign cases: pass
- Focused test selection explicitly listed all four intended tests
- Focused parser-to-vector race run: `-race -count=3` pass
- Focused coverage profile: `unwrapPickKeyParens` 100%
- Full controlled CGo package test: `./pkg/frontend` pass
- Focused public BVT against the locally built server: 89/89 strict
comparisons pass; every added expected row set was manually checked for
selection semantics and failure atomicity

### CI follow-up

The first Coverage job failed because only 4/6 changed production-code
blocks were exercised (66.67%, below the required >75%). Commit
`c5ff0283af` added malformed-AST tests for the defensive error branches.
A later Ubuntu/x86 UT failure was unrelated
(`TestDeleterConcurrentDelete`, tracked by matrixorigin#26643); the single permitted
failed-job rerun completed successfully.

### Residual risks

The change adds an O(parenthesis depth), allocation-free AST walk plus
one short-lived `big.Int` parse per native BIT literal. Parsed statement
size bounds both costs. It does not alter APIs, storage, wire formats,
concurrency, or generic string/subquery coercion, and non-BIT targets
retain their prior behavior. No known functional residual remains for
matrixorigin#26074.

---------

Co-authored-by: XuPeng-SH <[email protected]>
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
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26074

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

### Root cause

Current `main` accepts BOOL literals and decimal BIT keys, but a native
BIT literal is represented by the MySQL parser as a `tree.P_bit`
`NumVal` whose canonical string is `0b...`. The literal-key path sent
that string to the generic BIT coercion function, which parses
already-normalized decimal values in base 10. It therefore rejected the
binary prefix before key materialization, while typed subquery values
already arrived as normalized decimal strings.

The same mismatch affected transparent AST wrappers. Unary `+b'1'`
became `+0b1`, but exact integer normalization was limited to Go integer
target OIDs and `types.T_bit.IsInteger()` is false. Parentheses then
introduced `tree.ParenExpr` nodes that the literal classifier did not
peel, so equivalent forms such as `+(b'1')`, `(+b'1')`, and a
parenthesized BIT component in a composite key were rejected based only
on AST shape.

Finally, the scanner intentionally accepts the empty native BIT literal
`b''` and canonicalizes it to `0b`, matching the normal typed SQL
meaning of zero. The native-literal decoder required at least one binary
digit after the prefix, so PICK incorrectly classified this valid parser
output as malformed.

### Changes

- Use one shared predicate for numeric AST forms that require exact
integer normalization, preserving existing hexadecimal/fractional-number
behavior and adding `tree.P_bit` only for BIT primary keys.
- Decode native BIT literals as exact base-2 integers at the AST
boundary, then feed their normalized decimal value into the existing BIT
width/range check and vector append path.
- Normalize the parser's canonical empty `P_bit` value to zero while
retaining rejection of malformed programmatic `P_bit` AST strings.
- Peel all transparent `tree.ParenExpr` layers before classifying the
literal and again before classifying a unary operand. Arbitrary
non-literal expressions remain unsupported.
- Apply the same conversion to direct and unary-wrapped BIT literals:
unary plus preserves the value, while unary minus remains invalid
through the existing unsigned BIT range check.
- Extend parser-to-vector unit and public BVT coverage across direct,
unary, parenthesized, empty, composite, boundary, malformed, overflow,
negative, and failure-atomicity cases.

### Issue-to-test proof

| Issue behavior | Executable proof |
| --- | --- |
| BOOL literal and numeric keys | BVT covers `false`, `true`, `0`, and
`1`, including update, delete, and conflict modes. |
| Decimal BIT literal vs typed subquery | BVT applies key `1`, then
applies the other BIT key through a typed subquery and verifies
identical row semantics. |
| Native `b'...'` / `B'...'` BIT literals | Unit tests parse full `DATA
BRANCH PICK ... KEYS(...)` statements; BVT verifies single and composite
PK application. |
| Empty native BIT literal | Unit/BVT verify `KEYS(b'')` selects only
the BIT zero key. |
| Unary and transparent-parenthesis forms | Unit/BVT verify `+b'1'`,
`+(b'1')`, `(+b'1')`, nested parentheses, and parenthesized BIT
components in composite keys. |
| BIT boundaries | Unit/BVT cover BIT(1), BIT(8) zero/max, BIT(64)
zero/signed boundary/uint64 max, including unary-plus BIT(8) max. |
| Invalid values and atomicity | Unit tests verify negative, overflow,
non-literal, and malformed programmatic `P_bit` inputs fail without
vector mutation; BVT puts a rejected key after a valid key and verifies
the destination remains unchanged. |

### Tests run

- Pre-fix focused parser-to-vector regression reproduced the
empty/parenthesized failures.
- `make build`
- `go vet -mod=readonly ./pkg/frontend` with the repository CGo
environment
- Focused parser-to-vector tests for direct, unary, parenthesized,
empty, malformed, boundary, and sign cases: pass
- Focused test selection explicitly listed all four intended tests
- Focused parser-to-vector race run: `-race -count=3` pass
- Focused coverage profile: `unwrapPickKeyParens` 100%
- Full controlled CGo package test: `./pkg/frontend` pass
- Focused public BVT against the locally built server: 89/89 strict
comparisons pass; every added expected row set was manually checked for
selection semantics and failure atomicity

### CI follow-up

The first Coverage job failed because only 4/6 changed production-code
blocks were exercised (66.67%, below the required >75%). Commit
`c5ff0283af` added malformed-AST tests for the defensive error branches.
A later Ubuntu/x86 UT failure was unrelated
(`TestDeleterConcurrentDelete`, tracked by matrixorigin#26643); the single permitted
failed-job rerun completed successfully.

### Residual risks

The change adds an O(parenthesis depth), allocation-free AST walk plus
one short-lived `big.Int` parse per native BIT literal. Parsed statement
size bounds both costs. It does not alter APIs, storage, wire formats,
concurrency, or generic string/subquery coercion, and non-BIT targets
retain their prior behavior. No known functional residual remains for
matrixorigin#26074.

---------

Co-authored-by: XuPeng-SH <[email protected]>

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]: DATA BRANCH PICK literal KEYS rejects BOOL and BIT primary keys

3 participants