Repository navigation
fix(sql): preserve prepared numeric and temporal contracts - #29556
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? |
3a6aad4 to
6624b1b
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Decision: REQUEST_CHANGES recommendation
Reviewed all 38 files at e3a5296f9e9419c23355f65978a71d26115f32ba against declared base/merge-base c2cad8af38f140e5a554b349553e94ea608d296b. Independent review, no subagents. This is submitted as COMMENT because the authenticated reviewer is also the PR author; it is not an approval.
Three P2 items remain:
- Ordinary DECIMAL64 row conversion regresses materially. All validated inputs now take the allocating coefficient-to-string canonicalization path and then reparse the emitted string. A matched non-race benchmark of the actual
NewCast/NewExplicitCastentry points on an 8192-row, non-constant VARCHAR vector containing12345.67, destination DECIMAL(18,2), gives the following medians (three samples per side):
| CAST entry point | Base | PR | Allocations per batch, base → PR |
|---|---|---|---|
NewCast |
294,259 ns | 921,641 ns | 1 → 16,385 |
NewExplicitCast |
323,255 ns | 929,769 ns | 1 → 16,385 |
That is approximately 3.1× / 2.9× the CAST-stage time, plus ~192 KiB and 16,384 allocations per 8192 rows. This is not a whole-query throughput claim. These are ordinary successful inputs, so the affected path is much broader than scientific notation or prepared lookup fixes. Scalar owner measurements corroborate the cause: explicit64 12345.67 is 36.33 → 111.8 ns and 0 → 2 allocations per call. For balance, explicit DECIMAL128 12345678901234567890.12 improves in the batch benchmark (~3.21 → 2.07 ms); the issue is the ordinary DECIMAL64 hot path, not a claim that all conversions are slower. Preserve complete lexical validation, width-bounded arithmetic and proven-overflow-only clamping, but avoid materializing and reparsing an intermediate coefficient string for these ordinary inputs within the existing conversion owner.
-
The new pruning regression test does not assert scanned work.
issue_29512_round_filter_pushdown.sql:51applies@ignore:0to the single-column EXPLAIN ANALYZE result. The matching golden printsinputBlocks=1 inputRows=1, but those values are not compared. The mo-tester implementation marks ignored cells unchecked and skips their comparison; a counter-only regression with unchanged result shape therefore passes. Ordinary EXPLAIN and planner UTs verify plan construction, not that the runtime filter actually prevents excess reads. The documented manual measurements are useful evidence for today's behavior, but do not provide the claimed durable 1-block/1-row assertion. Add an operator-scoped counter regex or a structured scan-counter assertion using the existing fixture; do not pin timings or introduce another test harness. Existing vector BVTs already combine@ignore:0with targeted@regexassertions. -
A remaining malformed-DECIMAL golden is inconsistent with the new error owner and fails current CI. Proxy BVT job 110533064472 reports exactly one failed statement out of 44,666:
test/distributed/cases/dtype/decimal.test:659,SELECT 10.0 + CAST('aaa' AS decimal(38,0));.
dtype/decimal.result:1371still expectsinvalid input: aaa beyond the range, can't be converted to Decimal128(38,0).; actual isinvalid input: "aaa" is invalid decimal string. This PR already updates other malformed-DECIMAL goldens, but misses this consumer. Keep the distinction between invalid syntax and numeric overflow, align the remaining golden with the intended lexical contract, and rerun that BVT. Do not restore blanket error-to-clamp behavior just to match the old wording.
Design, adjacent contracts and engineering quality
The overall direction is reasonable. The changes reuse the existing numeric conversion owner, typed constant evaluator, prepared value-dependent/cache-admission state, projection normalization, join/runtime-filter policy and statistics owner. The ROUND-only proof, duplicated normalization and obsolete decimal overflow/underflow branches are removed; no new evaluator, cache, storage owner, lock protocol or execution state machine is introduced. The singleton proof has shape/type/semantic-barrier guards, actual typed-value/domain checks, preserved executable conversions and refreshed column-reference/statistics bookkeeping.
Implementation is +795/-786 (net +9); tests/goldens +1076/-59; documentation +181/-0. The small production net delta does not excuse the measured row cost, and test line count does not excuse an ignored oracle. The public integration test appropriately reuses the canonical fixture and owns SQL rows/statements through error and close. Documentation is mostly a chronology of superseded reviews/heads and model-session approvals: non-blocking recommendation is to retain final contracts, rationale and reproducible evidence in the repo, and keep historical review outcomes on the PR. In particular, correct its statement that the new goldens assert 1-block/1-row once item 2 is addressed.
No additional confirmed correctness/data-compatibility blocker was found in this pass. New LAST_DAY bindings expose nullable DATE; old overload IDs and serialized VARCHAR expressions retain their evaluator path. Views are rebound/described through existing SQL/metadata owners. The EXPLAIN wrapper change classifies the underlying SELECT without admitting explained DML to SELECT-only proofs. Diagnostic/error/NULL/volatile/fractional/FLOAT guards and parameter rebinding were traced rather than assuming that the target happy path covers adjacent cases. Mixed-version upgrade compatibility was not treated as a requirement.
Executed validation and limits
On this exact head, Go 1.26.4, Darwin/arm64, Apple M4, with verified matching CPU native-artifact provenance:
- Full normal tests:
pkg/container/types,pkg/sql/plan/function,pkg/sql/plan,pkg/sql/colexec,-count=1; terminal exit 0. - Real frontend
TestPreparedNumericTemporalContractsinpkg/tests/sqlintegration, normal mode,-count=1; all four named scenarios and final fixture teardown passed, terminal exit 0. - Independent seeded exact-
big.Ratoracle: 1800 inputs across precisions 1/6/18/19/30/38/39/60/76, varying scale, sign, rounding and scientific exponent; 3600 strict/explicit conversions passed. - Focused race tests, 100 successful iterations each, terminal exit 0:
TestPreparedIntegerComparisonProofDiagnostics,TestPreparedSingletonJoinIntegerComparison,TestSingletonProjectedPeerAdmission,TestRestorePreparedExactIntegerTextExecutesNormalization,TestLastDayPersistedVarcharABI,TestDecimalScientificCastContracts,TestDecimalScientificWideValues. - Matched base/head conversion and actual batch-CAST benchmarks, non-race,
-benchtime=200ms -count=3, run sequentially on the same machine, terminal exit 0 on both revisions. Benchmark/oracle files are external Go overlays; no production or committed test files were changed. - Current exact-head CI: SCA, Ubuntu UT, UT Coverage and pessimistic multi-CN BVT passed; Proxy BVT failed as above. Coverage aggregation reports that a required producer did not publish a complete profile and explicitly says no coverage verdict was calculated. It is not an independent coverage-percentage failure. No rerun was requested or waited for.
At review intake there were no actionable human inline review threads (only a paused-bot issue comment). The same-head approval from another reviewer does not close the three newly demonstrated gaps. The previous documented F1/F2 repairs have substantive implementation/behavior evidence, but this head is not ready for my approval recommendation until the remaining items above are closed.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Overall recommendation: APPROVE at e66cdafe56817fa62881dc7d5131c75cacadb695, which preserves the reviewed complete-diff SHA-256 6fcaa7282e0aca51117eaab635bddc13b958bc95500e6116c1ca49006afc4cc0. GitHub review event is COMMENT because the authenticated reviewer is also the PR author; this is not a self-approval event.
Reconciled the complete 39-file PR, not just the amendment, with the accepted design and independent QA. All three findings in review 5384880775 are fixed:
- Ordinary DECIMAL conversion no longer allocates a canonical coefficient string or reparses it. One scanner grammar supplies transient facts; bounded caller scratch is consumed by shared typed digit arithmetic. Matched 8192-row strict/explicit Decimal64 batches are 295/298µs vs declared-base 294/323µs, with 1 allocation per batch rather than 16385. Decimal128 is 1221µs vs base3214µs. These are CAST-stage measurements only. Neighboring float conversion remains zero-allocation, with measured approximately2%/2%/6% overhead, not the misleading loaded-machine scanner ratio.
- The nested runtime-filter ANALYZE now checks the lookup scan's own inputBlocks=1 and inputRows=1 via an existing operator-scoped regex; it no longer ignores the complete result. The oracle accepts the golden and rejects scan-only inputRows=20004 while aggregate row counts remain unchanged. Result and plain EXPLAIN assertions remain independent.
- The remaining malformed-DECIMAL golden now reflects lexical failure. The existing full decimal BVT passes without restoring incorrect blanket overflow clamping.
Current-code validation: full types/function/planner/colexec suites, changed-owner vet-all, complete affected-package incremental SCA (0 issues), independent exact arithmetic oracle (3600 conversions), four real public prepared/temporal SQL scenarios, and three complete mo-tester cases twice on the same instance (1592 statements, zero failed/ignored/abnormal). Scan table teardown is verified before replay. Prior valid focused race/serialized LAST_DAY ABI evidence is retained for unchanged paths; this amendment adds no concurrent state or lifecycle.
Design and final independent overall review: actual gpt-6.1-sol / xhigh, final session 01a0f93e-b6aa-78d2-819d-f324ae4310c6, no unresolved material blocker. Existing conversion/planning owners remain authoritative; no alternate parser/interpreter/cache or execution path. Complete syntax precedes overflow decisions; quantization rounds once and keeps scratch bounded; persisted representations/legacy LAST_DAY VARCHAR overload ABI are retained. Prepared proof/source/cache ownership and EXPLAIN-underlying-SELECT classification remain intact. Final documentation describes contracts rather than process history.
No unresolved material blocker. Persisted-data compatibility is considered; mixed-version operation is outside the agreed scope. New remote CI is not awaited or claimed green.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review recommendation: APPROVE / no unresolved material blocker at e66cdafe56817fa62881dc7d5131c75cacadb695. GitHub event is COMMENT because the reviewer account is also the author; this is not a self-approval event.
The complete 39-file change map and full-diff fingerprint are unchanged from the recorded independent gpt-6.1-sol/xhigh review (6fcaa7282e0aca51117eaab635bddc13b958bc95500e6116c1ca49006afc4cc0). I reused semantically valid evidence, retraced neighboring consumers and ran additional real-SQL counterexamples. No subagents, delegated CLI review or product edits in this pass.
Design and engineering: the fix remains at existing decimal conversion, prepared binding, typed evaluator, projection/statistics and overload ABI owners. No parallel lexer, cache, state machine, storage or execution path. Quantization rounds once into bounded borrowed scratch and shares physical digit arithmetic; complete syntax precedes overflow/clamping. Original executable expressions, diagnostics, parameter provenance and value-dependent cache admission remain. Serialized LAST_DAY VARCHAR overloads stay executable while new bindings expose nullable DATE; explained DML is not classified as SELECT. Implementation (+919/-840), tests/goldens (+1147/-68) and final-contract documentation (+68) were considered separately. Added primitives have actual consumers and measured benefit; UT, public result/metadata, persisted ABI and scan-counter oracles serve distinct claims. No new unjustified abstraction, dead state or superseded process-history document found.
Fresh adversarial QA, exact head, Go1.26.4/Darwin arm64, controlled native dependencies, one canonical test-owned CN fixture: TestPR29556ReviewAdversarialSQL, five named subtests, -count=1, terminal exit0, package13.044s (SQL body169ms). Verified:
- Half-away rounding/carry/underflow controls, a 1000-digit exponent-cancelling spelling, malformed zero/overflow-looking syntax, and normal execution after each same-handle error.
- Mixed valid/malformed INSERT SELECT rolls back completely; subsequent valid batch persists exactly the expected values.
- JOIN LIMIT0/OFFSET1/WHEREfalse barriers retain empty results; UNION ALL preserves duplicate matches; unmatched LEFT JOIN preserves all rows.
- UINT64_MAX/MAX-1, negative/out-of-domain and >2^53 prepared DECIMAL-transport rebinding preserve exact row identity.
- Prepared EXPLAIN UPDATE has no side effect; the corresponding UPDATE modifies only the intended signed BIGINT, not its neighboring colliding key. Native LAST_DAY century/NULL boundaries remain correct.
Unhappy-path closure:
| Check | Result |
|---|---|
| Q1 ownership | Evaluator frees on error, proof frees returned witnesses once on all success/rejection paths; constructors retain no borrowed input. SQL resources and fixture teardown remain owned. |
| Q2 termination | Planning cancellation cause propagates; conversion diagnostics keep runtime ownership. No new locks/channels/RPC waits or asynchronous generation. Test service/admission/port release completed. |
| Q3 bounds | Coefficient scratch76bytes, normalized integer output20digits, full exponent consumption with safe saturation; no exponent-sized materialization or retained new store. |
Previous comments: all three actionable threads are genuinely fixed, with source and execution evidence—not merely resolved flags: DECIMAL allocation/reparsing (4159947342), ignored scan counters (4159947351), stale malformed-DECIMAL golden (4159947360). No additional actionable human comment was found. The scan regex rejects changed scan inputRows while keeping aggregate cardinality unchanged.
Valid reused evidence: full owning suites, changed-owner vet and affected-package SCA0issues; independent exact arithmetic3600conversions; four public frontend scenarios;1592normal BVT statements over six runs with teardown; focused race and persisted expression ABI checks for unchanged ownership paths. Matched actual8192row Decimal64 strict/explicit CAST is295/298µs versus declared-base294/323µs,1allocation/batch; Decimal1281221µs versus3214µs. Neighboring float conversion is zero-allocation with measured~2%/~2%/~6% overhead. No whole-query throughput claim.
Current CI: run36926270715 completed successfully at the reviewed head: Required, Linux/arm64 SCA, Ubuntu/x86 UT, shared build, Proxy multi-CN BVT and pessimistic multi-CN BVT passed. Optional/disabled/upgrade skips are not claimed passed. Persisted-data compatibility remains in scope; mixed-version rollout and coverage percentage are not approval gates here.
No new correctness/data-compatibility, leak/hang/OOM, material performance or engineering-design blocker was demonstrated. No code changes requested.
What type of PR is this?
Which issue(s) this PR fixes:
Closes #29550
Closes #29551
Closes #29552
Closes #29553
What this PR does / why we need it:
Restore four SQL contracts at their existing conversion and binding owners:
Superseded ROUND-specific and duplicate overflow branches are removed. Documentation describes final contracts rather than the review chronology. Runtime-filter BVT asserts the lookup scan's actual
inputBlocks=1 inputRows=1using an operator-scoped regex, without pinning timings or ignoring the complete ANALYZE result. Existing malformed-DECIMAL goldens are aligned with lexical failure, not restored to blanket overflow clamping.Validation
Current candidate: Darwin/arm64, Go 1.26.4, matching stamped repository CGo dependencies:
veton changed conversion owners and incremental golangci-lint on the complete affected package closure passed, zero issues.big.Ratoracle: 1800 inputs / 3600 strict and explicit conversions, widths 1–76, varying scales, signs, long mantissas and positive/negative exponents. Constructor boundaries, lexical failures, rounding/carry, prefix and scientific contracts passed. Ordinary short-text DECIMAL64 conversion has a zero-allocation regression assertion.inputRows=20004mutation while aggregate row counts remain unchanged.Matched non-race CAST-stage benchmarks, 8192 nonconstant VARCHAR rows, three 200ms samples, same machine/toolchain/native dependencies:
The prior PR head imposed approximately 3× DECIMAL64 CAST-stage work and 16385 allocations/batch; that regression is removed. These are conversion-stage measurements, not whole-query throughput claims.
Neighboring MySQL string-to-FLOAT conversion remains zero-allocation. Matched samples are approximately +2% for ordinary/scientific text and +6% for a long leading-zero prefix (about 0.6–2.7ns), rather than extrapolating the isolated scanner's percentage to the whole consumer.
Design and final overall review used actual gpt-6.1-sol / xhigh. Final overall review: APPROVE, no unresolved material blocker, session
01a0f93e-b6aa-78d2-819d-f324ae4310c6. Submitted commite66cdafe56817fa62881dc7d5131c75cacadb695preserves the exact reviewed complete-diff fingerprint6fcaa7282e0aca51117eaab635bddc13b958bc95500e6116c1ca49006afc4cc0.Scope includes persisted data/serialized LAST_DAY compatibility; mixed-version rollout is excluded. Remote CI is not awaited and is not claimed to have passed.