Repository navigation
[4.2] fix(readutil): preserve nested PK OR branches - #27502
mergify[bot] merged 2 commits into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
|
Fixed in The P1 is valid. Container detection now runs after unsafe-input validation and before both atomic connector switches, so neither Coverage added:
The left-deep |
Merge Queue Status
This pull request spent 41 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
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
## 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>
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
…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 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
…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 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
…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>
What type of PR is this?
Which issue(s) this PR fixes:
issue #27503
What this PR does / why we need it:
Prepared statements against
information_schema.TABLEScan return only a subset of the requested table names on 4.2 when the query contains a large parameterizedINlist. 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
ORfilters. A disjunctiveBasePKFilteris a container whose zero-valueOphappens to equalfunction.EQUAL.mergeFilterstherefore 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.
ORcan therefore flatten every branch, whileANDconservatively keeps one safe atomic conjunct for early pruning and leaves the complete predicate to residual evaluation. The selectedANDfallback 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 mixedAND/ORpredicate and the originalinformation_schema.TABLESshape.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-
ORbug 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):PREPARE/EXECUTE: requested/found = 1/1, 2/2, 5/5, 10/10, 20/20, 50/50, 132/132a, zmo-testerBVTpk_filter_nested_boolean: 29/29 statements, 100%go test ./pkg/vm/engine/readutil -count=1go test -race ./pkg/vm/engine/readutil -run '^TestConstructBasePKFilterWithOr$' -count=10go vet ./pkg/vm/engine/readutilmake build