Skip to content

fix binary secondary-index point lookup semantics - #26809

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
XuPeng-SH:agent/fix-binary-index-prefix-residual
Aug 9, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
XuPeng-SH:agent/fix-binary-index-prefix-residual

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #26807.

What changed

  • Retain the original typed residual predicate for CHAR/VARCHAR/BINARY/VARBINARY = and IN lookups that use a serial_full secondary-index prefix candidate.
  • Keep the encoded prefix predicate for candidate pruning, then apply exact SQL comparison semantics after serial_extract.
  • Add planner unit coverage and a BVT matrix covering empty bytes, NUL prefixes, embedded NULs, fixed/variable binary widths, textual byte strings, prepared parameters, NULL, composite-index order, backfill, indexed UPDATEs, and hidden physical-index cardinality.
  • Use a physically index-free mirror table as the textual scan oracle, so the regression cannot pass accidentally if an IGNORE INDEX hint is not honored.

Root cause

The encoded prefix_eq/prefix_in condition is a candidate range, not an exact semantic oracle for byte-string values: the tuple terminator can prefix an escaped embedded NUL. Covering index-only plans removed the original typed predicate and therefore returned false-positive rows. The fix preserves an exact residual only for affected byte-string point predicates; range and fixed-width numeric paths remain unchanged.

Validation

  • Pre-fix real-engine counterexample on an index-free oracle: VARCHAR '=' returned 2 through the covering index vs 1 by scan; IN returned 3 vs 2.
  • Focused planner counterexamples for BINARY, VARBINARY, CHAR, and VARCHAR, with range and INT64 controls.
  • Complete CGo pkg/sql/plan tests.
  • go build and go vet for ./pkg/sql/plan.
  • make build-with-prebuilt-native.
  • Isolated candidate-cluster BVT: 95/95 statements passed.
  • git diff --check and a complete pre-push self-review passed.

No partitioned-table behavior is involved.

@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Aug 9, 2026
@XuPeng-SH
XuPeng-SH force-pushed the agent/fix-binary-index-prefix-residual branch from 5581c38 to 4e65479 Compare August 9, 2026 02:50
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/XL Denotes a PR that changes [1000, 1999] lines labels Aug 9, 2026
@XuPeng-SH
XuPeng-SH marked this pull request as ready for review August 9, 2026 03:16
@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner August 9, 2026 03:16
@XuPeng-SH
XuPeng-SH requested a review from a user August 9, 2026 03:16
@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 →

@XuPeng-SH
XuPeng-SH merged commit 4b38c3f into matrixorigin:main Aug 9, 2026
25 checks passed
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Fixes matrixorigin#26807.

## What changed

- Retain the original typed residual predicate for
`CHAR`/`VARCHAR`/`BINARY`/`VARBINARY` `=` and `IN` lookups that use a
`serial_full` secondary-index prefix candidate.
- Keep the encoded prefix predicate for candidate pruning, then apply
exact SQL comparison semantics after `serial_extract`.
- Add planner unit coverage and a BVT matrix covering empty bytes, NUL
prefixes, embedded NULs, fixed/variable binary widths, textual byte
strings, prepared parameters, NULL, composite-index order, backfill,
indexed UPDATEs, and hidden physical-index cardinality.
- Use a physically index-free mirror table as the textual scan oracle,
so the regression cannot pass accidentally if an `IGNORE INDEX` hint is
not honored.

## Root cause

The encoded `prefix_eq`/`prefix_in` condition is a candidate range, not
an exact semantic oracle for byte-string values: the tuple terminator
can prefix an escaped embedded NUL. Covering index-only plans removed
the original typed predicate and therefore returned false-positive rows.
The fix preserves an exact residual only for affected byte-string point
predicates; range and fixed-width numeric paths remain unchanged.

## Validation

- Pre-fix real-engine counterexample on an index-free oracle: `VARCHAR
'='` returned `2` through the covering index vs `1` by scan; `IN`
returned `3` vs `2`.
- Focused planner counterexamples for `BINARY`, `VARBINARY`, `CHAR`, and
`VARCHAR`, with range and `INT64` controls.
- Complete CGo `pkg/sql/plan` tests.
- `go build` and `go vet` for `./pkg/sql/plan`.
- `make build-with-prebuilt-native`.
- Isolated candidate-cluster BVT: 95/95 statements passed.
- `git diff --check` and a complete pre-push self-review passed.

No partitioned-table behavior is involved.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Fixes matrixorigin#26807.

## What changed

- Retain the original typed residual predicate for
`CHAR`/`VARCHAR`/`BINARY`/`VARBINARY` `=` and `IN` lookups that use a
`serial_full` secondary-index prefix candidate.
- Keep the encoded prefix predicate for candidate pruning, then apply
exact SQL comparison semantics after `serial_extract`.
- Add planner unit coverage and a BVT matrix covering empty bytes, NUL
prefixes, embedded NULs, fixed/variable binary widths, textual byte
strings, prepared parameters, NULL, composite-index order, backfill,
indexed UPDATEs, and hidden physical-index cardinality.
- Use a physically index-free mirror table as the textual scan oracle,
so the regression cannot pass accidentally if an `IGNORE INDEX` hint is
not honored.

## Root cause

The encoded `prefix_eq`/`prefix_in` condition is a candidate range, not
an exact semantic oracle for byte-string values: the tuple terminator
can prefix an escaped embedded NUL. Covering index-only plans removed
the original typed predicate and therefore returned false-positive rows.
The fix preserves an exact residual only for affected byte-string point
predicates; range and fixed-width numeric paths remain unchanged.

## Validation

- Pre-fix real-engine counterexample on an index-free oracle: `VARCHAR
'='` returned `2` through the covering index vs `1` by scan; `IN`
returned `3` vs `2`.
- Focused planner counterexamples for `BINARY`, `VARBINARY`, `CHAR`, and
`VARCHAR`, with range and `INT64` controls.
- Complete CGo `pkg/sql/plan` tests.
- `go build` and `go vet` for `./pkg/sql/plan`.
- `make build-with-prebuilt-native`.
- Isolated candidate-cluster BVT: 95/95 statements passed.
- `git diff --check` and a complete pre-push self-review passed.

No partitioned-table behavior is involved.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Fixes matrixorigin#26807.

## What changed

- Retain the original typed residual predicate for
`CHAR`/`VARCHAR`/`BINARY`/`VARBINARY` `=` and `IN` lookups that use a
`serial_full` secondary-index prefix candidate.
- Keep the encoded prefix predicate for candidate pruning, then apply
exact SQL comparison semantics after `serial_extract`.
- Add planner unit coverage and a BVT matrix covering empty bytes, NUL
prefixes, embedded NULs, fixed/variable binary widths, textual byte
strings, prepared parameters, NULL, composite-index order, backfill,
indexed UPDATEs, and hidden physical-index cardinality.
- Use a physically index-free mirror table as the textual scan oracle,
so the regression cannot pass accidentally if an `IGNORE INDEX` hint is
not honored.

## Root cause

The encoded `prefix_eq`/`prefix_in` condition is a candidate range, not
an exact semantic oracle for byte-string values: the tuple terminator
can prefix an escaped embedded NUL. Covering index-only plans removed
the original typed predicate and therefore returned false-positive rows.
The fix preserves an exact residual only for affected byte-string point
predicates; range and fixed-width numeric paths remain unchanged.

## Validation

- Pre-fix real-engine counterexample on an index-free oracle: `VARCHAR
'='` returned `2` through the covering index vs `1` by scan; `IN`
returned `3` vs `2`.
- Focused planner counterexamples for `BINARY`, `VARBINARY`, `CHAR`, and
`VARCHAR`, with range and `INT64` controls.
- Complete CGo `pkg/sql/plan` tests.
- `go build` and `go vet` for `./pkg/sql/plan`.
- `make build-with-prebuilt-native`.
- Isolated candidate-cluster BVT: 95/95 statements passed.
- `git diff --check` and a complete pre-push self-review passed.

No partitioned-table behavior is involved.

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

size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: VARBINARY index-only equality treats empty and NUL values as prefixes

2 participants