Skip to content

fix(plan): preserve decimal pruning for integer-backed DOUBLE parameters - #30817

Merged
XuPeng-SH merged 4 commits into
mainfrom
fix/29661-int64-double-pruning-20261022
Oct 22, 2026
Merged

XuPeng-SH merged 4 commits into
mainfrom
fix/29661-int64-double-pruning-20261022

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Addresses the remaining explicit DOUBLE / integer-source path of #29661. Keep the issue open pending merged-nightly confirmation.

What this PR does / why we need it:

Summary

Addresses the remaining integer-backed explicit DOUBLE comparison in #29661. Earlier fixes cover direct integer/TEXT DECIMAL comparisons, but d = CAST(? AS DOUBLE) with an integer source still scans every persisted block and loses native secondary-index access.

On frozen main ada0bde326adec3c3906d2f417c266d0ada5b054, both binary Prepared and SQL EXECUTE return the correct row for 16001, but read 4 blocks / 32,768 rows rather than the literal control's 1 block / 8,192 rows. The unchanged Daily MOTR pruning contract fails on precisely this residual.

Design

  • Admit only SELECT scalar comparisons of a native DECIMAL64/128 column with a plain DOUBLE cast of a parameter through an injective integer cast chain.
  • Reuse the existing DECIMAL-to-DOUBLE uniqueness proof; preserve the original executable DOUBLE cast and ParamRef. A successful cast alone is not sufficient: adjacent decimal values around 2^53 can compare equal in DOUBLE.
  • Pair a small immutable proof with the existing single-slot prepared plan cache. Both the native and generic fallback plans recheck their expected uniqueness class against the current typed binding. Repeated safe and repeated wide bindings reuse their plan; a class transition replans once.
  • Publish proof and plan only after successful compilation. Keep existing diagnostic checks, AP logical-only cache behavior and cleanup ownership. No new cache, key hashing, worker, per-row condition, storage/wire change or general CAST executor path.
  • Leave DML, arbitrary derived expressions, fixed-scale DOUBLE, non-injective casts and DECIMAL256 unchanged.

Regression coverage

Existing planner tests now check selective typed plans and negative controls. Focused frontend tests require plan/compile identity from an independent expected-class oracle, including both initial binding orders, same-class different values, failed compilation, NULL/type changes, AP logical-only reuse and Close.

The existing issue_29514_decimal_expression_filter BVT reuses its table and secondary index for safe/wide/safe execution. Four new physical-work assertions accompany independent count/min results; existing floating-collision and diagnostic checks remain.

Local validation on server 50

  • Clean-base negative: 312/312 results correct, 16 capability failures; new BVT fails exactly its 4 added physical-work checks while all row goldens pass. Unchanged pinned Daily MOTR pruning reproduces the same explicit-DOUBLE/INT64 failure.
  • Candidate: 312/312 results and 108/108 capability checks pass, including both protocols and native secondary-index lookup (1 index row).
  • Independent 21-row boundary fixture: 100/100 frozen result-ID checks pass, covering signed/unsigned limits, DECIMAL64/128 floating collisions, high scales, comparisons in both directions and repeated rebindings. Exact stored decimal values are checked before queries.
  • Unchanged Daily MOTR df62a1b639c2c2af319438a09a3d4486beede371, pruning mode: PASS.
  • BVT: 299/299 twice, zero ignored/abnormal results; database cleanup independently verified after each execution.
  • Final owning packages normal with -vet=all: pkg/sql/plan (27.361 s) and pkg/frontend (15.661 s) PASS.
  • Single-slot lifecycle and multiple-proof exact tests: each 100 repetitions under -race, PASS. Frontend owning package under -race: PASS (36.186 s).
  • Configured lint on both owning packages, including new files: PASS, 0 issues.

Quiet baseline/candidate timing used the same 12 shapes/protocols, 5 alternating batches of 200 result-checked operations each (12,000 operations per version), without concurrent task compilation:

Median microseconds / operation Binary before / after SQL EXECUTE before / after
Persisted explicit-DOUBLE lookup 26,275 / 386 25,873 / 401
Tiny safe explicit-DOUBLE lookup 329 / 296 338 / 329
Tiny repeated-wide fallback 331 / 312 289 / 298
Unchanged tiny integer control 319 / 328 336 / 320

This is a bounded shared-host comparison, not a general performance guarantee. The wide/control normalized ratios are 0.915 and 1.081; SQL wide fallback is about 9 microseconds slower in this sample. There is no recurrence of the rejected prototype's roughly 2x repeated-wide replanning cost; cache-identity assertions independently prove reuse. Native pruning and indexed access are the primary deterministic improvement oracles.

No claim of full remote CI or multi-CN nightly acceptance is made by these local checks. All test-owned containers exited normally, and fixture database counts are zero after cleanup. Base is frozen at ada0bde3; the subsequently fetched Main 6495ce99 changes unrelated closures and does not contain this residual fix.

Risk and scope

The principal risks are unsound float narrowing and stale prepared-plan reuse. Actual collision results, source-type transitions, failed-publication checks and repeated-wide latency controls cover these directly. The proof retains only bounded per-expression metadata, no parameter vectors or previous cache generations. The change does not modify unrelated execution domains. Keep #29661 open for final merged-nightly confirmation rather than interpreting every prepared wrapper as covered.

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

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Code-review verdict: no blocking findings; approval recommendation for d96a07b against main/merge-base 6495ce9. The authenticated account is the PR author, so this is a COMMENT review, not a formal self-approval.

Reviewed all 12 changed files and the related #29661 discussion, including the rejected prototype's repeated-wide-binding performance regression. There are currently no inline review threads to reconcile.

Design/correctness:

  • This is a focused fix at the existing prepared-consumer binding and single-slot cache owners, not another execution/cache subsystem. Native DECIMAL admission requires the existing executor-aligned uniqueness proof; successful conversion alone does not authorize narrowing. The executable DOUBLE conversion and ParamRef remain present.
  • Checked the integer transport decoding against numericToNumeric, injective integer-cast-chain restrictions, both comparison orientations, ordering predicates, signed/unsigned boundaries, NULL/type changes, and DECIMAL64/128 floating collisions. Fixed-scale DOUBLE, non-injective/intervening expressions, DML and DECIMAL256 do not enter the new admission.
  • Both native and fallback plans retain their expected proof class. Every relevant proof must match the current typed binding before cache reuse; same-class different values do not force replanning. Existing field-type and diagnostic guards remain in place.

Lifecycle/performance closure:

Check Result
Q1 ownership Proof metadata is published with the plan only after successful compilation; failure discards the candidate without replacing the previous plan/proof. Existing retirement, invalidation, AP logical-only caching and Close ownership remain intact.
Q2 waits The new admission/reuse check is synchronous bounded computation; it introduces no lock, I/O, goroutine or retry/wait edge.
Q3 growth Metadata is bounded by comparisons in the current plan, contains no parameter-vector references, and replaces the same cache slot rather than accumulating generations.

Evidence checked and reused, not rerun as duplicate heavy work:

  • Read the original Shanghai50 logs under /tmp/mo-29661-int-double-20261022.og3hXsF4/evidence and matched SHA256 for all 12 delivered files. Planner/frontend normal tests with vet pass; frontend owning-package race passes; focused cache/proof tests have terminal passing results.
  • Unfixed baseline fails exactly the four new BVT access-path assertions (295/299); candidate passes 299/299 twice, with independently checked zero leftover fixture databases. The unchanged pinned MOTR pruning contract fails on baseline and passes on candidate.
  • Inspected the independent 21-row boundary harness with frozen expected IDs: 100 result checks pass, including floating-collision rows, high scales, integer extrema and rebindings. Existing broader protocol/access-path checks report no capability failures.
  • The same-class plan/compile identity assertions directly cover the previous replanning regression. Shared-host timings do not show its former ~2x slowdown; SQL repeated-wide median is 289 -> 298 us, so this is not a zero-overhead or universal no-regression claim.
  • These execution results belong to the pre-merge ada0bde-based candidate, not a newly executed full suite at the merge head. Inspected the intervening main changes (mixed text/binary set operations, functional JSON indexes, index-join view authorization, result/export handling); they do not change the reviewed decimal-admission/proof/cache closure. Final-head full CI remains separate. Local diff --check passes and the review worktree is clean.

The observed Connector/J Pool Reset E2E failure is Maven bootstrap download failure (wget: Failed to fetch .../apache-maven-3.9.9-bin.zip, make jstfu), before the E2E tests execute: https://github.com/matrixorigin/matrixone/actions/runs/39745963939/job/119714361432. It is not evidence of a regression in this patch. Other checks were still running when inspected; this review does not claim all CI green. Keep #29661 open until the planned merged-nightly confirmation.

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: d96a07b6800957d978b348aa53c79062dfc2dd27

Review completed. Read the assessment.

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

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

Commit: d96a07b6800957d978b348aa53c79062dfc2dd27

Assessment: approve

Reviewed the complete 12-file delta and affected callers. No actionable defects found. The design coherently extends the existing binder and single-slot cache: uniqueness proofs preserve DOUBLE semantics, permit same-class reuse, and remain paired with their plans through compilation failure, invalidation and cleanup.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Isolation preflight passed. Native prerequisites were built through the repository owner; 194 source inputs and seven native artifact hashes were reconciled.

  • Focused planner and frontend tests passed with -vet=all and -count=1 through test-exec, covering admission, fallback, cache transitions, failed publication, NULL/type changes, AP reuse and Close.

  • An independent diagnostic overlay passed 272 parsed-SQL-to-expression-execution cases covering all comparison operators, both orientations, high scales, floating collisions and integer extrema.

  • The frozen CI snapshot reports successful unit tests, static analysis, build, both BVT groups and Connector/J E2E.

  • Command/source/exit receipts matched retained logs; source remained clean and diff --check passed. Evidence and review details are retained under /home/xupeng/.local/state/mo-bot/jobs/c753b66daf9d4f5077c52fcf/attempt-1/ in validation-manifest.json and review-report.txt.

Limitations:

  • Full suites, distributed BVT and race checks were not rerun locally; raw CI logs and the author's remote validation artifacts were unavailable.

  • No local latency benchmark was performed. Proof checking adds per-comparison admission work, with no new per-row work, I/O or goroutines; author timing claims were not independently reproduced.

  • Issue #29661 remains open for the explicitly planned merged-nightly confirmation; this assessment covers the assigned residual path.

@mergify mergify Bot added the queued label Oct 22, 2026
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-22 15:37 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-22 17:32 UTC · at 0995b3fc654ee6dc814facb168278095be123459

This pull request spent 1 hour 54 minutes 57 seconds in the queue, with no time running CI.

Reason

Pull request #30817 has been merged manually at ecdeffc

Hint

You were too fast!

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

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

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — 0995b3fc Deployed Oct 22, 2026 by mergify[bot]
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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants