Skip to content

fix: preserve prefix predicates through pruning and row reordering - #32825

Merged
XuPeng-SH merged 7 commits into
4.2-devfrom
fix/32822-prefix-in-null-42dev
Nov 17, 2026
Merged

XuPeng-SH merged 7 commits into
4.2-devfrom
fix/32822-prefix-in-null-42dev

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 16, 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:

Fixes #32822.

What this PR does / why we need it:

Persisted prefix-IN pruning needs ordered, nonoverlapping candidates before binary membership and first/last bounds are safe. Encoded NULL bytes can disturb that order. Treating every empty or zero-leading payload as NULL also discards valid raw prefixes and produces false negatives after flush.

  • Use one checked candidate-preparation API for readutil and expression ZoneMap evaluation. Preserve opaque bytes, sort and remove subsumed prefixes on a private copy when needed, and leave unsafe NULL/malformed representations to residual evaluation.
  • Reuse existing AuxId scratch within its owning scan or RESULT_SCAN reader generation. Release it on close, rebind and pool change; keep function temporaries local and use the existing owned-result API for constant arguments.
  • Keep unknown summaries conservative in object/block filtering, seek and early stop. Prepared membership remains logarithmic; seek stops at the first unknown block.
  • Preserve valid ascending metadata through nondecreasing row selections and clear it after arbitrary permutations. Both Shuffle variants decide this before mutating input and publish the flag only on success. Remap buffered grouping/NULL bitmaps before overwriting data that selectors may reference. This also fixes incorrect scalar prefix results after ORDER BY, reproduced on the base branch.

No SQL syntax, persisted format or protocol change. No new cache, worker or per-permutation allocation.

Validation on host 10.222.1.57, Go 1.26.4, matching CPU CGo libraries:

  • Full normal/race tests cover the original vector/index/readutil/colexec/external/disttae owners. Final row-permutation changes additionally passed full normal/race tests for vector, batch, function, readutil, order, top, mergetop and mergeutil.
  • Final 12-package vet, pinned molint and incremental golangci-lint passed; lint reports 0 issues. Service build passed.
  • Independent prefix oracles; malformed/NULL/constant inputs; immutable plan bytes; unknown metadata; reader reuse, close and pool changes; cancellation, I/O and allocation failures. Row-permutation tests include nondecreasing, duplicate, empty, constant and disordered selections; failed admission preserves sortedness; shared-selector controls verify values, NULLs and grouping alignment.
  • Real MySQL checks with 800 constructed rows and 400 matches cover FORCE/IGNORE exact rows, primary/secondary-index flush, process restart and binary prepared-statement rebinding. The review's exact empty/NUL-prefix witnesses pass against scalar row oracles before flush, after flush and after restart; the old implementation loses those rows after restart.
  • Final rebuilt binary: optimizer BVT 193/193 twice, teardown verified. Eight scalar projection and four WHERE controls pass after flush and process restart. Expected scalar output was checked independently.

Same-machine pruning benchmarks against base fc6c7fee10f1, five samples:

Work Base Updated
16,384 candidates, 4,096-block expression scan, including first preparation and release 74–77 ms 0.45–0.46 ms
Sorted 16,384-candidate cold preparation 20.8 µs 64.1 µs
Unsorted 16,384-candidate preparation 376 µs 347 µs

The scan allocates about 99 KB versus 885 KB. Prepared ZoneMap probes remain allocation-free, with about 1–4 ns added for guards. Cold verification is retained because the sorted flag does not prove order or prefix freedom. Safe seek is linear: about 33 µs for 4,096 skipped blocks; the previous binary seek was unsafe with unknown summaries. Complete traversal measured about 32 µs with safe seek versus 79 µs without it for a late match. These measurements cover pruning, not whole-query throughput.

The final row-permutation correction was measured separately against published 9393b21b4c55: pinned CPU, single thread, bounded ABBA order and six samples per variant. Across 16 three-column shuffle cases (128/8,192 rows, buffered/allocating, sorted/unproven, ordered/permuted), median changes range from -3.9% to +9.3%, with no added allocations. The 8,192-row/128-prefix ordered pipeline is 141.62 → 143.45 µs (+1.3%); always clearing sortedness instead takes 356.10 µs. The corrected permuted pipeline takes 351.19 µs; the previous incorrect output is excluded from performance comparisons.

The original preserved macOS dataset was unavailable. Validation uses constructed persisted data and deterministic metadata counterexamples. Updated-commit remote CI remains pending.

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

@mergify

mergify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · superseded

Commit: 6b139d6807b8696b0e150c97229230323e3ae050

"interrupted"

@mergify mergify Bot added the kind/refactor Code refactor label Nov 17, 2026
@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 9393b21b4c5589ef5cde1baf6c1be541f7783371

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 9393b21b4c5589ef5cde1baf6c1be541f7783371

Assessment: approve

The prior raw-prefix defect is resolved. Shared checked preparation and reuse of existing scan scratch preserve prefix semantics with bounded ownership and justified pruning gains. No actionable findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • All six owning packages passed build, vet and normal tests. Both colexec packages passed full race runs; four focused lifecycle tests each passed 100 race repetitions. Receipt/log mappings are retained in validation-summary.json.

  • All 12 focused tests passed. The baseline production overlay fails overlap and encoded-order cases while empty/NUL controls pass; the candidate passes all cases.

  • Independent SQLite/scalar evaluation verified 15 added SQL fixture results; this does not exercise MatrixOne flush/restart.

  • Final audit passed: checks/1794884002491722949-2.json matches review-source-audit.log, verifying frozen sources, 15 patch/blob indexes, formatting, discussion coverage, native provenance and validation receipts.

Limitations:

  • The original macOS persisted dataset was unavailable. No local MySQL/restart/BVT or benchmark campaign was run; author-reported lifecycle and performance results remain attributed evidence.

  • Owning CI checks were pending in the supplied snapshot and were not counted as passes.

Invalidate ascending metadata only for successful disordered selections.
Consume selection-derived metadata and bitmaps before replacing input data.
Cover scalar prefix results after ORDER BY, shared selections and failed admission.
@XuPeng-SH XuPeng-SH changed the title fix: canonicalize prefix IN pruning and reuse scan scratch fix: preserve prefix predicates through pruning and row reordering Nov 17, 2026
@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: f502da16296fde9fd103df45dd3e4a6b1e1de8a7

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: f502da16296fde9fd103df45dd3e4a6b1e1de8a7

Assessment: approve

The prior raw-prefix defect is resolved. Shared checked preparation and existing scan scratch preserve prefix semantics with bounded ownership; shuffle corrections keep sortedness and row bitmaps consistent. No actionable findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • All 24 focused test functions passed. Twelve affected owner/dependent packages passed build, vet, full normal tests and full race tests. Eight suite tests skipped in each mode; none were focused tests.

  • Four lifecycle tests each passed 100 race repetitions; measured T/B/N and logs are retained.

  • The merge-base vector.go control failed the three intended regression tests; the candidate passed. An independent scalar oracle verified 18 SQL expectations.

  • Isolation preflight, formatting, diff-check and frozen-source/native/receipt audit passed. Final receipt: checks/1794889237428385852-2.json; detailed reconciliation: validation-summary.json.

Limitations:

  • The original macOS dataset was unavailable. No local MySQL/BVT, restart or benchmark campaign ran; author-reported results remain attributed evidence.

  • Owning CI checks were pending in the supplied snapshot.

@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · superseded

Commit: 97b52bb743f7dd3d6dfed7a5c0ecf0db7e4766a5

"interrupted"

@XuPeng-SH
XuPeng-SH merged commit dcf3965 into 4.2-dev Nov 17, 2026
@XuPeng-SH
XuPeng-SH deleted the fix/32822-prefix-in-null-42dev branch November 17, 2026 08:14
XuPeng-SH added a commit that referenced this pull request Nov 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #30420 (native-reset fix on main: #30426) and #28452 (related
HAKeeper transport recovery).

Related: #32825 and its [failed UT
run](https://github.com/matrixorigin/matrixone/actions/runs/44011324458/job/133798814581).

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

A native connection reset can escape HAKeeper recovery during ID
allocation, making an operation such as CREATE DATABASE fail. Recognize
wrapped `ECONNRESET` and the relevant typed backend connection errors in
the existing retry path; preserve the MORPC backend-creation timeout
sentinel as a non-retryable result.

Keep client ownership in the managed client: closing it now ends
admission and wakes retry waiters, and a late failure only resets the
client generation that actually failed. This prevents a retry from
recreating a client after `Close` and prevents a stale failure from
closing its replacement. Honor cancellation before issuing cached IDs or
publishing a newly constructed client, and pass the caller context
through reverse-proxy discovery while retaining discovery's own RPC
options.

For callers with an explicit MORPC backend-wait deadline, newly
retryable transport failures return their original error after the
current failed attempt rather than starting another HAKeeper-level dial.
Existing EOF/NoHAKeeper retry behavior is preserved. An already-running
synchronous dial or client cleanup can still overrun a caller or
backend-wait deadline; this PR does not claim a hard end-to-end timeout.
Lost allocation responses can still produce ID gaps, and the initiating
server-side reset in the reported CI run is not established.

Validation on 10.222.1.57, Linux/amd64, Go 1.26.4 and matching CPU CGo
libraries:

- Reproduced retry after `Close` and late-generation failure; regression
coverage exercises terminal close, concurrent callers, cleanup errors,
context cancellation and recovery, including a real MORPC
backend-creation timeout.
- `pkg/logservice` in normal and race modes (`-short -tags
matrixone_test -count=1`): 307 passing root tests / 463 named passes,
zero failures and one existing skip in each mode. Each of 17 changed/new
roots also passed 100 race repetitions.
- Existing three-CN `TestTableFeatures` passed with race and its
original topology and assertions; existing MORPC backend-wait and
HAKeeper ID-state-machine controls passed under race.
- Formatting/diff checks, vet, pinned molint and incremental
golangci-lint passed for the owner and direct constructor/consumer
closure (nine packages).

The logservice suites used isolated user/network namespaces after a
pre-existing host listener prevented an unrelated Gossip test from
binding its port; no test assertion or port was changed. Cached ID
admission adds a context/close check under the existing lock; a
single-CPU microbenchmark measured roughly 2 ns/op extra and zero
allocations, not an end-to-end throughput measurement.

CI for the updated head is pending.

This branch was successfully deployed

No deployments
ci — 97b52bb7 Deployed Nov 17, 2026 by XuPeng-SH
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 kind/enhancement kind/refactor Code refactor kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants