Skip to content

[4.2] fix(readutil): preserve nested PK OR branches - #27502

Merged
mergify[bot] merged 2 commits into
matrixorigin:4.2-devfrom
gouhongshen:backport/fix-nested-pk-or-4.2
Aug 23, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:4.2-devfrom
gouhongshen:backport/fix-nested-pk-or-4.2

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Aug 23, 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:

issue #27503

What this PR does / why we need it:

Prepared statements against information_schema.TABLES can return only a subset of the requested table names on 4.2 when the query contains a large parameterized IN list. For example, 132 existing names return only 2 rows, while the equivalent literal query returns all 132.

The composite primary-key predicate is folded into nested OR filters. A disjunctive BasePKFilter is a container whose zero-value Op happens to equal function.EQUAL. mergeFilters therefore treats two nested disjunction containers as atomic equality filters, compares their empty bounds, and drops the right-hand subtree.

This PR classifies disjunction containers before either connector enters the atomic merge path. OR can therefore flatten every branch, while AND conservatively keeps one safe atomic conjunct for early pruning and leaves the complete predicate to residual evaluation. The selected AND fallback also preserves its own OID when the container is the left operand.

Regression coverage includes (((eq1 OR eq2) OR (eq3 OR eq4)) OR eq5), both operand orders for an atomic range combined with a disjunction, and a public SQL prepared-statement BVT covering both the mixed AND/OR predicate and the original information_schema.TABLES shape.

This is not a cherry-pick because there is no existing upstream PR that fixes this merge bug. The behavior first appeared with #25596. Main started returning the expected rows after #26627 added a cast to the hidden composite key and thereby stopped this query from taking PK pruning; the underlying nested-OR bug was not fixed. #27436 and #27448 were also tested on 4.2 and do not fix the failure.

Validation on latest 4.2-dev (63c24f9180):

  • SQL PREPARE/EXECUTE: requested/found = 1/1, 2/2, 5/5, 10/10, 20/20, 50/50, 132/132
  • Go MySQL driver parameter binding: the same matrix passes, including 132/132
  • Literal 132-name control query: 132/132
  • Mixed range/disjunction prepared queries, in both operand orders: a, z
  • mo-tester BVT pk_filter_nested_boolean: 29/29 statements, 100%
  • go test ./pkg/vm/engine/readutil -count=1
  • go test -race ./pkg/vm/engine/readutil -run '^TestConstructBasePKFilterWithOr$' -count=10
  • go vet ./pkg/vm/engine/readutil
  • make build

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

Request changes: the same container/atomic confusion still produces false-negative pruning through the AND path (P1).

The new guard is inside case function.OR, but a BasePKFilter with Disjuncts can also reach mergeFilters(..., function.AND, ...). Its zero-value Op is still interpreted as EQUAL there. This is not only a synthetic struct case; I reproduced it through the real MySQL prepared-statement path on this exact head:

create table v (a varchar(20) primary key);
insert into v values (''), ('a'), ('b'), ('c'), ('z'), ('zz');

select a from v
where a <= ? and (a = ? or a > ?)
order by a;
-- bindings: 'z', 'a', 'm'

Expected: a, z. Actual on 36619a2e0c: zero rows.

The right operand becomes a disjunction container (a = 'a' OR a > 'm') with empty LB and zero Op. Because the container guard does not run for AND, the LESS_EQUAL/EQUAL atomic merge emits a valid EQUAL filter with an empty bound. Empty bytes are a valid varchar key, so both block and workspace PK pruning discard the real matches before the residual predicate can recover them. Small-domain exhaustion found the same false-negative shape for <, <=, and >= '' when the atomic operand precedes the container.

Please classify container operands before entering either atomic connector switch. For example, moving this guard after the existing unsafe-input validation but before switch connector lets the established AND deferred fallback keep one safe conjunct, while OR still falls back to flattening. Please add operand-order tests and a public prepared regression for a mixed range/disjunction, not only the nested-OR structural test.

Validation context: the target five-name information_schema prepared query passes 5/5 on the same embedded cluster, and the readutil full test, focused test x20, focused race x10, vet, and diff check all pass. Therefore this is a completeness gap in the fix, not a failure of its intended OR case.

Non-blocking performance/unhappy-path note: fallback flattening remains quadratic for left-deep OR trees. A local M4 benchmark measured 132 branches at ~210 us / 1.74 MB and 1024 branches at ~6.7 ms / 84.4 MB per construction, versus ~63 us / 247 KB and ~0.58 ms / 2.65 MB for balanced trees. The 132-parameter target is reasonable, but the left-deep builder is a concurrency-amplified memory risk and should be linearized or bounded in a follow-up.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

Fixed in 6372a0e986.

The P1 is valid. Container detection now runs after unsafe-input validation and before both atomic connector switches, so neither AND nor OR can interpret a disjunction container's zero-value Op as EQUAL. AND keeps the existing conservative atomic-conjunct fallback; when the container is the left operand, the fallback now preserves the selected right operand's OID.

Coverage added:

  • structural tests for both container/atomic operand orders;
  • prepared SQL BVT for a <= ? AND (a = ? OR a > ?) and the reversed order, both returning a, z;
  • prepared information_schema.TABLES nested-OR regression returning 5/5;
  • full readutil test, focused race x10, vet, build, and BVT 29/29 all pass.

The left-deep OR allocation concern is valid but has a separate performance/ownership risk surface, so it is tracked in #27505 instead of expanding this 4.2 correctness fix.

@gouhongshen gouhongshen added the size/M Denotes a PR that changes [100,499] lines label Aug 23, 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.

Deep review complete at 6372a0e: the previous container/atomic AND-path P1 is resolved. Full readutil tests, focused race stress, full-package race, and systematic boolean-tree validation passed. No remaining findings.

@mergify

mergify Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-23 14:53 UTC · Rule: release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-08-23 14:53 UTC · at 6372a0e986545efc3017330828045b1ba87d59c5 · squash

This pull request spent 41 seconds in the queue, including 2 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify
mergify Bot merged commit 5f4cd9d into matrixorigin:4.2-dev Aug 23, 2026
47 of 49 checks passed
@mergify mergify Bot removed the queued label Aug 23, 2026
mergify Bot pushed a commit that referenced this pull request Aug 24, 2026
This ports the root fix from #27502 to `main`. `main` contains the composite-PK block-pruning path introduced by #25596, but it does not contain either nested-disjunction guard from the 4.2 fix.

A `BasePKFilter` with `Disjuncts` is a container, not an atomic predicate. Its zero-value `Op` is `function.EQUAL`; allowing it into the atomic merge switch can compare empty bounds and drop an OR branch, producing a false-negative pruning filter.

The change rejects container merges before either AND or OR enters the atomic path. OR then flattens all disjuncts, while AND retains one safe atomic conjunct and leaves full predicate evaluation to the residual filter. The AND fallback now also preserves the selected atomic filter's OID.

Regression coverage adds nested OR and both AND operand orders to the `readutil` unit test, plus the prepared SQL BVT `pk_filter_nested_boolean`. The BVT result was generated against `main`; its three metadata-width entries differ from 4.2 while all SQL values remain identical.

Rebased onto `upstream/main` at `6a8e7ecc530539948663a35a52259224ee1d128a`.

Validation on that base plus this branch:

- `make build`
- `go test ./pkg/vm/engine/readutil -count=1`
- `go test -race ./pkg/vm/engine/readutil -run '^TestConstructBasePKFilterWithOr$' -count=10`
- `go vet ./pkg/vm/engine/readutil`
- `mo-tester` BVT `pk_filter_nested_boolean`: 29/29 statements, 100%

Approved by: @aptend, @XuPeng-SH
XuPeng-SH pushed a commit that referenced this pull request Sep 3, 2026
## What type of PR is this?

- [x] BUG
- [x] Test and CI

## Which issue(s) this PR fixes:

issue #27912

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

Adds canonical regression coverage for the `information_schema.COLUMNS`
query shape reported in #27912. The test compares three SQL
`PREPARE`/`EXECUTE` paths over the same six-column table:

- a fully literal predicate;
- bound `TABLE_SCHEMA` and `TABLE_NAME` without `COLUMN_NAME IN`;
- bound schema/table predicates combined with the six-value literal
`COLUMN_NAME IN` clause that returned only 2 of 6 rows on v4.2.0.

All paths assert the complete six-row result in deterministic ordinal
order. This is test-only coverage for behavior already fixed by #27502
on release-4.2 and #27521 on main; it does not change production code or
SQL semantics.

- QA required: yes. Keep #27912 open for formal release/current-version
verification after this regression is merged.
- BVT: added to
`test/distributed/cases/optimizer/pk_filter_nested_boolean.sql`.
- Historical behavior: v4.2.0 returned 2/6 rows for the mixed
bind/literal path.
- CI repair: normalized six continuation-line indentations in the
generated `.result` command record after exact-head BVT rejected the
indented record before executing the new case.
- Exact base: `ffc8d9f0625c76e87ba967984ce19db2d082b0ba`.
- Exact PR head: `fb45e2d063bdb67b5403a8932b53158d7ee56963`.
- Local exact-main SQL validation: PASS, 6/6 rows for literal,
bind-only, and mixed paths through the MySQL wire protocol.
- Local exact-format validation: PASS; the paired multiline command
blocks match after whitespace normalization, and only the six
result-file indentation characters changed.
- Full mo-tester BVT: pending on the new PR head.
- `git diff --check`: PASS.
- Semantic preflight: PASS for exact head and diff.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
This ports the root fix from matrixorigin#27502 to `main`. `main` contains the composite-PK block-pruning path introduced by matrixorigin#25596, but it does not contain either nested-disjunction guard from the 4.2 fix.

A `BasePKFilter` with `Disjuncts` is a container, not an atomic predicate. Its zero-value `Op` is `function.EQUAL`; allowing it into the atomic merge switch can compare empty bounds and drop an OR branch, producing a false-negative pruning filter.

The change rejects container merges before either AND or OR enters the atomic path. OR then flattens all disjuncts, while AND retains one safe atomic conjunct and leaves full predicate evaluation to the residual filter. The AND fallback now also preserves the selected atomic filter's OID.

Regression coverage adds nested OR and both AND operand orders to the `readutil` unit test, plus the prepared SQL BVT `pk_filter_nested_boolean`. The BVT result was generated against `main`; its three metadata-width entries differ from 4.2 while all SQL values remain identical.

Rebased onto `upstream/main` at `6a8e7ecc530539948663a35a52259224ee1d128a`.

Validation on that base plus this branch:

- `make build`
- `go test ./pkg/vm/engine/readutil -count=1`
- `go test -race ./pkg/vm/engine/readutil -run '^TestConstructBasePKFilterWithOr$' -count=10`
- `go vet ./pkg/vm/engine/readutil`
- `mo-tester` BVT `pk_filter_nested_boolean`: 29/29 statements, 100%

Approved by: @aptend, @XuPeng-SH
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28082)

## What type of PR is this?

- [x] BUG
- [x] Test and CI

## Which issue(s) this PR fixes:

issue matrixorigin#27912

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

Adds canonical regression coverage for the `information_schema.COLUMNS`
query shape reported in matrixorigin#27912. The test compares three SQL
`PREPARE`/`EXECUTE` paths over the same six-column table:

- a fully literal predicate;
- bound `TABLE_SCHEMA` and `TABLE_NAME` without `COLUMN_NAME IN`;
- bound schema/table predicates combined with the six-value literal
`COLUMN_NAME IN` clause that returned only 2 of 6 rows on v4.2.0.

All paths assert the complete six-row result in deterministic ordinal
order. This is test-only coverage for behavior already fixed by matrixorigin#27502
on release-4.2 and matrixorigin#27521 on main; it does not change production code or
SQL semantics.

- QA required: yes. Keep matrixorigin#27912 open for formal release/current-version
verification after this regression is merged.
- BVT: added to
`test/distributed/cases/optimizer/pk_filter_nested_boolean.sql`.
- Historical behavior: v4.2.0 returned 2/6 rows for the mixed
bind/literal path.
- CI repair: normalized six continuation-line indentations in the
generated `.result` command record after exact-head BVT rejected the
indented record before executing the new case.
- Exact base: `ffc8d9f0625c76e87ba967984ce19db2d082b0ba`.
- Exact PR head: `fb45e2d063bdb67b5403a8932b53158d7ee56963`.
- Local exact-main SQL validation: PASS, 6/6 rows for literal,
bind-only, and mixed paths through the MySQL wire protocol.
- Local exact-format validation: PASS; the paired multiline command
blocks match after whitespace normalization, and only the six
result-file indentation characters changed.
- Full mo-tester BVT: pending on the new PR head.
- `git diff --check`: PASS.
- Semantic preflight: PASS for exact head and diff.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
This ports the root fix from matrixorigin#27502 to `main`. `main` contains the composite-PK block-pruning path introduced by matrixorigin#25596, but it does not contain either nested-disjunction guard from the 4.2 fix.

A `BasePKFilter` with `Disjuncts` is a container, not an atomic predicate. Its zero-value `Op` is `function.EQUAL`; allowing it into the atomic merge switch can compare empty bounds and drop an OR branch, producing a false-negative pruning filter.

The change rejects container merges before either AND or OR enters the atomic path. OR then flattens all disjuncts, while AND retains one safe atomic conjunct and leaves full predicate evaluation to the residual filter. The AND fallback now also preserves the selected atomic filter's OID.

Regression coverage adds nested OR and both AND operand orders to the `readutil` unit test, plus the prepared SQL BVT `pk_filter_nested_boolean`. The BVT result was generated against `main`; its three metadata-width entries differ from 4.2 while all SQL values remain identical.

Rebased onto `upstream/main` at `6a8e7ecc530539948663a35a52259224ee1d128a`.

Validation on that base plus this branch:

- `make build`
- `go test ./pkg/vm/engine/readutil -count=1`
- `go test -race ./pkg/vm/engine/readutil -run '^TestConstructBasePKFilterWithOr$' -count=10`
- `go vet ./pkg/vm/engine/readutil`
- `mo-tester` BVT `pk_filter_nested_boolean`: 29/29 statements, 100%

Approved by: @aptend, @XuPeng-SH
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28082)

## What type of PR is this?

- [x] BUG
- [x] Test and CI

## Which issue(s) this PR fixes:

issue matrixorigin#27912

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

Adds canonical regression coverage for the `information_schema.COLUMNS`
query shape reported in matrixorigin#27912. The test compares three SQL
`PREPARE`/`EXECUTE` paths over the same six-column table:

- a fully literal predicate;
- bound `TABLE_SCHEMA` and `TABLE_NAME` without `COLUMN_NAME IN`;
- bound schema/table predicates combined with the six-value literal
`COLUMN_NAME IN` clause that returned only 2 of 6 rows on v4.2.0.

All paths assert the complete six-row result in deterministic ordinal
order. This is test-only coverage for behavior already fixed by matrixorigin#27502
on release-4.2 and matrixorigin#27521 on main; it does not change production code or
SQL semantics.

- QA required: yes. Keep matrixorigin#27912 open for formal release/current-version
verification after this regression is merged.
- BVT: added to
`test/distributed/cases/optimizer/pk_filter_nested_boolean.sql`.
- Historical behavior: v4.2.0 returned 2/6 rows for the mixed
bind/literal path.
- CI repair: normalized six continuation-line indentations in the
generated `.result` command record after exact-head BVT rejected the
indented record before executing the new case.
- Exact base: `ffc8d9f0625c76e87ba967984ce19db2d082b0ba`.
- Exact PR head: `fb45e2d063bdb67b5403a8932b53158d7ee56963`.
- Local exact-main SQL validation: PASS, 6/6 rows for literal,
bind-only, and mixed paths through the MySQL wire protocol.
- Local exact-format validation: PASS; the paired multiline command
blocks match after whitespace normalization, and only the six
result-file indentation characters changed.
- Full mo-tester BVT: pending on the new PR head.
- `git diff --check`: PASS.
- Semantic preflight: PASS for exact head and diff.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
This ports the root fix from matrixorigin#27502 to `main`. `main` contains the composite-PK block-pruning path introduced by matrixorigin#25596, but it does not contain either nested-disjunction guard from the 4.2 fix.

A `BasePKFilter` with `Disjuncts` is a container, not an atomic predicate. Its zero-value `Op` is `function.EQUAL`; allowing it into the atomic merge switch can compare empty bounds and drop an OR branch, producing a false-negative pruning filter.

The change rejects container merges before either AND or OR enters the atomic path. OR then flattens all disjuncts, while AND retains one safe atomic conjunct and leaves full predicate evaluation to the residual filter. The AND fallback now also preserves the selected atomic filter's OID.

Regression coverage adds nested OR and both AND operand orders to the `readutil` unit test, plus the prepared SQL BVT `pk_filter_nested_boolean`. The BVT result was generated against `main`; its three metadata-width entries differ from 4.2 while all SQL values remain identical.

Rebased onto `upstream/main` at `6a8e7ecc530539948663a35a52259224ee1d128a`.

Validation on that base plus this branch:

- `make build`
- `go test ./pkg/vm/engine/readutil -count=1`
- `go test -race ./pkg/vm/engine/readutil -run '^TestConstructBasePKFilterWithOr$' -count=10`
- `go vet ./pkg/vm/engine/readutil`
- `mo-tester` BVT `pk_filter_nested_boolean`: 29/29 statements, 100%

Approved by: @aptend, @XuPeng-SH
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28082)

## What type of PR is this?

- [x] BUG
- [x] Test and CI

## Which issue(s) this PR fixes:

issue matrixorigin#27912

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

Adds canonical regression coverage for the `information_schema.COLUMNS`
query shape reported in matrixorigin#27912. The test compares three SQL
`PREPARE`/`EXECUTE` paths over the same six-column table:

- a fully literal predicate;
- bound `TABLE_SCHEMA` and `TABLE_NAME` without `COLUMN_NAME IN`;
- bound schema/table predicates combined with the six-value literal
`COLUMN_NAME IN` clause that returned only 2 of 6 rows on v4.2.0.

All paths assert the complete six-row result in deterministic ordinal
order. This is test-only coverage for behavior already fixed by matrixorigin#27502
on release-4.2 and matrixorigin#27521 on main; it does not change production code or
SQL semantics.

- QA required: yes. Keep matrixorigin#27912 open for formal release/current-version
verification after this regression is merged.
- BVT: added to
`test/distributed/cases/optimizer/pk_filter_nested_boolean.sql`.
- Historical behavior: v4.2.0 returned 2/6 rows for the mixed
bind/literal path.
- CI repair: normalized six continuation-line indentations in the
generated `.result` command record after exact-head BVT rejected the
indented record before executing the new case.
- Exact base: `ffc8d9f0625c76e87ba967984ce19db2d082b0ba`.
- Exact PR head: `fb45e2d063bdb67b5403a8932b53158d7ee56963`.
- Local exact-main SQL validation: PASS, 6/6 rows for literal,
bind-only, and mixed paths through the MySQL wire protocol.
- Local exact-format validation: PASS; the paired multiline command
blocks match after whitespace normalization, and only the six
result-file indentation characters changed.
- Full mo-tester BVT: pending on the new PR head.
- `git diff --check`: PASS.
- Semantic preflight: PASS for exact head and diff.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants