Repository navigation
fix: align scalar expression vector cardinality - #27436
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.
Reviewed exact head bb4650da49c1.
The change restores the scalar-expression contract: parameter and variable vectors remain physically constant while their logical length tracks every input batch. This closes the cross-batch materialization/shuffle out-of-range path without introducing per-row payload allocation.
I checked non-NULL and NULL values, all-false masks, zero-row inputs, changing batch sizes, reuse/reset behavior, and the order materialization path. Full tests, build-only tests, and go vet passed for colexec, order, and hashbuild; an additional focused boundary regression also passed.
Merge Queue Status
This pull request spent 2 hours 48 minutes 2 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #27436 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
Failing checks:
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
aptend
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head bb4650da49c1cf18bc6476290ccbd89866987119. The scalar parameter and variable executors now preserve constant physical representation while updating logical cardinality on initial evaluation and cache reuse, including null and fully masked branches. I also checked row-count shrink/grow and zero-row transitions, masked variable resolution, prepared-parameter metadata behavior, and the retaining order consumer. Relevant colexec/hashbuild/order tests, focused adversarial repetitions, focused race runs, vet, and diff checks pass. No blocking issue found.
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` Approved by: @XuPeng-SH
## What type of PR is this? - [ ] API-change - [ ] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27415 ## What this PR does / why we need it: fix: align scalar expression vector cardinality --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [ ] API-change - [ ] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27415 ## What this PR does / why we need it: fix: align scalar expression vector cardinality --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [ ] API-change - [ ] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27415 ## What this PR does / why we need it: fix: align scalar expression vector cardinality --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…33453) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: #33452 Related to #27415. Backport of #27436 to `4.2-dev`. ## What this PR does / why we need it: A prepared scalar in the projection of a multi-row ordered insert has logical length one on 4.2.9. The sorter copies the projection into a flat batch that claims more rows than the copied scalar column, then returns SQL error 20101 when it permutes the rows. This blocks a tenant event backfill during upgrade. Use the input batch row count as the logical length of constant parameter and variable results, including cached values, NULL, and fully masked input. Scalar storage stays constant-size. The 4.2 variable executor clears the previous logical length before overwriting its cached scalar so allocation is based on a single stored value, even when the previous batch was large. Validation - Reproduced the upgrade event statement over MySQL TCP on 4.2.9 and on the 4.2-dev base. The fixed statement writes both expected events, and executing the same binary prepared statement again writes zero rows. - The maintained prepared projection BVT passed 35/35 statements twice on the same instance, with database cleanup verified after each run. The unmodified base fails the new ordered insert and its row checks. - Race tests passed in colexec, order, projection, filter, hashbuild, apply, frontend, and compile. The variable-capacity test verifies reuse across 8,192 and 2 logical rows. - Scoped go vet and incremental golangci-lint passed. Legacy molint reports the same seven diagnostics as the exact base. ### APPLY regression follow-up on `85f0688d` - `metadata_scan` now accepts nonempty scalar constants broadcast over an APPLY input batch while retaining rejection of flat multirow arguments. NULL and non-string inputs return an error before reading vector storage. - Added unit coverage for constant/mixed cardinality, empty input, NULL and fixed-width types. - Real embedded MySQL TCP probe failed before the fix and passes after it: singleton variables, two-row variable/literal APPLY with actual persisted metadata, and the flat-multirow rejection control. - `go test -race -count=1 ./pkg/sql/colexec/table_function`, scoped `go vet`, and incremental golangci-lint pass (0 new issues). Existing MOI prepared-insert TCP/BVT evidence remains valid. - Full-diff review of `85f0688d` approved with no actionable findings.
What type of PR is this?
Which issue(s) this PR fixes:
issue #27415
What this PR does / why we need it:
fix: align scalar expression vector cardinality