Skip to content

fix: align scalar expression vector cardinality - #27436

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
iamlinjunhong:m-27415
Aug 21, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
iamlinjunhong:m-27415

Conversation

@iamlinjunhong

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 #27415

What this PR does / why we need it:

fix: align scalar expression vector cardinality

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

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.

@mergify mergify Bot added the queued label Aug 21, 2026
@mergify

mergify Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-21 08:39 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-21 11:27 UTC · at c35d10c520185cfccced88cf7aa57dc5f8b7ded1

This pull request spent 2 hours 48 minutes 2 seconds in the queue, with no time running CI.

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

Reason

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

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You 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.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

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

@XuPeng-SH
XuPeng-SH merged commit 087092c into matrixorigin:main Aug 21, 2026
24 of 25 checks passed
@mergify mergify Bot added dequeued and removed queued labels Aug 21, 2026
mergify Bot pushed a commit that referenced this pull request Aug 23, 2026
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
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
- [ ] 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>
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
- [ ] 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>
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
- [ ] 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>
XuPeng-SH added a commit that referenced this pull request Nov 29, 2026
…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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants