Skip to content

fix(sql): retain DECIMAL access for prepared integer consumers - #29920

Merged
XuPeng-SH merged 2 commits into
mainfrom
fix/29661-decimal-consumer-completion
Oct 11, 2026
Merged

XuPeng-SH merged 2 commits into
mainfrom
fix/29661-decimal-consumer-completion

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • BUG
  • Test and CI

Which issue(s) this PR fixes:

Part of #29661; follow-up to #29667. Does not close #29661.

What this PR does / why we need it:

Two independent boundaries prevent meaningful prepared-DECIMAL pruning coverage:

  1. The existing exact integer admission covers a direct binary comparison, but not integer lists/ranges or a value-preserving explicit SIGNED peer. Overload resolution can widen the DECIMAL column and lose block pruning or secondary-index access.
  2. OperatorStats.InputBlocks has json:"-". Remote terminal analysis preserves input rows but drops the actual block count, so aggregation can report Rows=32768, Blocks=0. That diagnostic failure blocks the nightly fixture before its prepared comparisons are exercised; it is not proof that a storage scan read zero blocks.

This patch shares the existing exact-domain admission across SELECT comparisons, IN/NOT IN and BETWEEN. It admits only a native DECIMAL column and integer literals/parameters, including injective integer cast chains. All peers must fit before any conversion guard is published. Original executable parameter/cast expressions, wide-value fallback, earlier value dependencies, and existing cache ownership are retained. A declared-precision conversion guard protects subsequent EXECUTEs; an unsafe binding cannot replace the reusable safe plan.

The diagnostic fix is one optional JSON field. Real remote-terminal producer/consumer tests cover round-trip, idempotent terminal delivery, mixed local/remote aggregation, and legacy missing-field inputs. Missing data stays zero; counts are never invented from row counts. No storage format, RPC protocol version, reader implementation, global type-coercion policy, or DML behavior changes.

Validation scope

Base: freshly verified Main f42af4dfcba210fd91b6f1fc5d7b5a72704502ee.

Actual SQL is tested on server 50 in task-owned single-CN instances (4 CPU / 8 GiB), using identical persisted data and independent fixed-row expected results, with both binary Prepared Statements and SQL EXECUTE. Existing user services and nightly clusters are untouched.

The existing DECIMAL BVT is extended in place, reusing its dataset and normal result comparison. On the unmodified base the original 239 statements pass; the final extended 274-statement case has exactly four new scan/index assertion failures and 270 passes. No existing expectation is weakened.

Local candidate results:

  • 312/312 independent SQL result assertions pass on both versions, including safe → wide → safe → NULL → TEXT/DOUBLE → integer rebinding in both protocols.
  • 40 scoped pruning/index capability failures on the base become zero on the candidate. Non-index integer IN/BETWEEN read one block / 8,192 rows instead of four / 32,768. Indexed integer IN/BETWEEN and identity SIGNED peers retain the native secondary-index path.
  • The original untyped DECIMAL18 BETWEEN literal was itself non-selective. It was replaced only in the diagnostic harness with an explicit same-domain DECIMAL literal, independently verified selective on both binaries. The original invalid-control logs are retained; they are not used as regression evidence.
  • Extended BVT: 274/274 twice, normal run mode, 2.830s / 2.839s. Explicit before/after database checks are zero. No generated-result acceptance.
  • Complete pkg/sql/plan tests pass; focused frontend real-cache tests pass, including safe cache identity, wide/NULL fallback and recovery, plus existing signed-narrowing/assignment/float controls.
  • Complete pkg/vm/process, pkg/sql/models, pkg/sql/compile tests pass. The real remote-terminal regression test fails on the base (rows preserved, expected four blocks become zero) and passes after the optional-field change.
  • Focused planner race checks pass (1.926s), and frontend cache/rebinding plus existing narrowing/assignment/float race checks pass (1.312s).
  • Scoped go vet passes for the five affected packages; formatting and whitespace checks pass. Pinned golangci-lint v2.14.0, repository config, all five packages, --new-from-rev=f42af4df...: exit 0, zero reported issues (1m 2.787s). The initially selected host Go launcher could not recognize SIMD inside lint's package loader; fixing only PATH/GOROOT to the verified Go 1.27.1 toolchain resolved it. SIMD/v3 and native provenance checks were retained.

Bounded actual-query timing (median of five 200-operation batches per protocol/scenario; 8,000 correctness-checked operations per binary): persisted IN takes 43.3% / 45.2% of base time (binary / SQL EXECUTE); indexed SIGNED takes 53.1% / 55.5%. On two-row tables, the added guarded paths cost 15–37 microseconds per execution (5.3–14.0%) in this shared-host sample. This cost is disclosed, not called zero regression or a production guarantee. The existing cache is retained, rather than replacing the access-path issue with repeated planning or a new cache mechanism.

Both isolated test services have been stopped; test databases were removed. All evidence is retained under /tmp/mo-29661-completion-20261011.O28F1p on server 50.

Explicit remaining limits

  • Direct TEXT on physical DECIMAL128(18,2), and explicit DOUBLE comparison with an INT binding, remain outside this patch. A conversion-only guard does not establish float injectivity; forcing per-execution replanning is not an acceptable substitute for a sound cache proof.
  • The remote block-count defect is reproduced through the actual terminal serialization/receiver/aggregation code, not a claim that a full TKE topology was rerun locally.
  • Local timing comparisons are informational measurements on a shared host, not a production performance guarantee. Full GitHub CI is reported separately from local evidence.

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

@aunjgr aunjgr 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 head 55957c5 against f42af4d. No blocking finding.

The admission proof is appropriately narrow: native DECIMAL columns, exact integer peers, and injective integer cast chains. All peers must fit before guards are published, executable parameters/casts remain intact, and a failed proof retains the fallback/value dependency. The declared-precision probes protect reuse without replacing the admitted cache entry on a wide binding. The tests cover these boundaries and safe/wide/NULL recovery.

The optional InputBlocks JSON field preserves actual remote scan work without inventing legacy counts. Producer/receiver, duplicate terminal delivery, and local/remote aggregation tests cover the changed diagnostic contract.

Validation: reused the reported owning-package/cache/race and real SQL/BVT evidence, plus passing current-head CI. I did not rerun a local service or benchmark. Remaining TEXT/DOUBLE cases and the disclosed small-query guard overhead are explicitly outside the claim.

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

Deep review of 55957c53053f03c3bb00ff5d813aeadb2d6e72a5 against f42af4dfcba210fd91b6f1fc5d7b5a72704502ee: no blocking finding.

The design extends the existing prepared consumer admission and diagnostic/cache ownership. It replaces the old direct-comparison branch with one admission for comparison/list/range peers. The native DECIMAL column is retained only when every integer peer fits; explicit cast chains must be injective over their source domain and remain executable. Guard publication is atomic, prior value dependencies survive, and wide/NULL/type-changing bindings cannot overwrite the admitted safe plan. TEXT/DOUBLE residual cases stay outside this proof; this PR correctly does not close #29661.

The InputBlocks change repairs the existing terminal-analysis serialization boundary with an optional field, reusing producer, receiver and node aggregation. Missing legacy data remains zero; duplicate terminal delivery remains idempotent. No new statistics estimator, cache, storage field or protocol state machine is introduced.

All eight files reviewed: production 2 files +136/-37, Go tests 4 +381/-1, SQL/results 2 +109/-0, no documentation files. The test increment checks real cache identity and failure/recovery, executable parameter retention, narrowing/float controls, remote serialization/aggregation and actual SQL rows/access paths. The BVT reuses the persisted fixture and makes selective scan/index assertions rather than relying only on plan shape.

Fresh local Darwin arm64 / Go 1.27.1 race checks passed: planner prepared-DECIMAL tests (2.995s), frontend prepared-DECIMAL and existing signed-narrowing cache checks (3.029s), real remote-terminal scan-work test (4.152s) and physical-plan JSON round trip (1.615s). Inspected current-head successful CI 38154370996 and its actual pessimistic BVT artifact: the extended DECIMAL script passed 274/274, with zero ignored/abnormal results. There are no unresolved review threads.

Performance is a real tradeoff: existing per-EXECUTE diagnostic probes protect the newly admitted cases, so small queries incur work. The author's disclosed shared-host measurements report +15–37 microseconds (5.3–14%) for two-row cases, while selective persisted IN/index cases improve substantially. I did not rerun those benchmarks and do not interpret them as a production guarantee or zero TP regression. The code preserves cache reuse and does not add unconditional replanning; the bounded guard cost buys the claimed access-path correctness.

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

mergify Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-11 23:35 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-11 23:37 UTC · at 7373fe5fd49bf7898fabcff35b828384d95133ba

This pull request spent 1 minute 55 seconds in the queue, with no time running CI.

Reason

Pull request #29920 has been merged manually at 6812abb

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 had an error being deployed

1 failed deployment
ci — 7373fe5f Deployed Oct 12, 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 kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Prepared integer bindings on DECIMAL columns disable native block pruning

4 participants