Repository navigation
fix: accept fractional prepared numeric overloads - #27556
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? |
aunjgr
left a comment
There was a problem hiding this comment.
Forcing prepared ABS to FLOAT64 is not semantically safe. A binary-protocol INT64 value of -9007199254740993 must produce the exact integer 9007199254740993; the new cast rounds it to 9007199254740992. It also changes the integer-domain behavior at MinInt64.
The recursive containsPreparedParamExpr makes the issue broader: abs(case when ? then bigint_col else bigint_col end) converts ordinary BIGINT column values to FLOAT64 even though the parameter only controls the branch.
SLEEP can reasonably have a stable DOUBLE input, but polymorphic ABS must preserve integer, decimal, and floating domains, likely through runtime type-category specialization rather than one approximate universal type. Please add binary-protocol regressions beyond 2^53 and for a parameter nested in a CASE around BIGINT data.
|
Updated exact head: 1d9b1ae, with latest main d511de3 merged. Closed the two latest P1 blockers:
New real COM_STMT controls cover multi-marker arithmetic, mixed INT64 and DECIMAL metadata/value, IF, CASE, single and dual scalar subqueries, v29 direct and nested stale-value reproduction, and v30 Decimal256 same-key value changes. Fresh validation after merging main:
Independent local review: code-review APPROVE; architecture CLEAR. @aptend @XuPeng-SH please re-review the updated exact head. |
…pared-overloads # Conflicts: # pkg/frontend/computation_wrapper.go # pkg/frontend/computation_wrapper_test.go # pkg/sql/plan/utils.go # pkg/sql/plan/visit_plan_rule.go
|
已推送合并提交 |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head 0f6645c52754824a4e4d0fdc1f1cb1df48cf80e6. The two correctness blockers from the previous review are closed: all value-source parameters are rebound, and every materialized parameter is restored before a same-category cache hit. The real COM_STMT regression passes, including multi-marker exactness, DECIMAL256, scalar subqueries, v29/v30 cache isolation, MinInt64, and UINT64 boundaries.
Two blocking performance-contract problems remain.
-
[P1 performance] Prepared-ABS provenance inflates every
plan.Expr, including unrelated ordinary queries.Five scalar fields were added directly to the globally hot
plan.Exprprotobuf. On this exact head,unsafe.Sizeof(plan.Expr{})is 184 bytes versus 160 bytes on base8b0a5ff873. That crosses the Go allocator size class from 160 to 192 bytes: approximately 20% more heap per independently allocated expression. Planner construction, optimizer rewrites,DeepCopyExpr, RPC plan materialization, and every non-prepared SQL statement pay this cost, even though only preparedABSneeds the metadata.The PR provides no allocation/plan-build evidence for this global footprint change. Please keep the rare provenance sparse, for example as one optional nested metadata pointer or plan-level sidecar, and show representative planner/deep-copy allocation evidence. The wire fields may still be explicit; they do not need five always-resident scalars on every expression.
-
[P2 performance/selection] The explicit DOUBLE-cast fast path is still classified as deferred specialization.
The issue documents
ABS(CAST(? AS DOUBLE))as an already-working control, and the implementation says explicit user DOUBLE casts should remain ordinary DOUBLE expressions. However, through the real parser:prepare s from 'select abs(cast(? as double))' PreparedPlanNumericFallbackParamPositions(...) == [0]A temporary planner assertion expecting no fallback fails exactly with
[0]. The helper UT constructstree.CastExprdirectly, but the parsed SQL shape is not recognized bycontainsExplicitFloatCast. Consequently this fixed-domain query allocates a runtime plan/compile unnecessarily; alternating integer/float protocol descriptors changepreparedRuntimeSemanticKeyand repeatedly deep-copy/recompile although the explicit cast fixes the output and overload to DOUBLE.Please derive the explicit-cast boundary from the actual parsed/bound shape and add a public parser-path plus compile-count/cache regression proving that explicit-cast executions stay on the original cached compile across parameter categories.
Evidence:
- exact-head GitHub CI: green;
- focused real COM_STMT issue regression: PASS;
- temporary parser-path metadata counterexample: FAIL as described, then removed;
- base/head
plan.Exprsize checks: 160/184 bytes, then removed; - no new goroutine, wait-chain, resource leak, or log-storm path found.
…pared-overloads # Conflicts: # pkg/frontend/computation_wrapper.go # pkg/frontend/computation_wrapper_test.go # pkg/frontend/mysql_cmd_executor.go # pkg/frontend/types.go # pkg/pb/plan/plan.pb.go
|
Addressed the latest review at exact head b958ced and merged upstream/main e5f26b6.\n\n1. Sparse prepared-ABS provenance\n- Replaced the five always-resident plan.Expr scalar fields with one optional PreparedNumericMetadata pointer.\n- Ordinary expressions leave the pointer nil; unsafe.Sizeof(plan.Expr{}) is now 168 bytes instead of 184 bytes on the reviewed head.\n- DeepCopyExpr copies the metadata only when present.\n- Added a committed benchmark. On the merged head (amd64, count=3), ordinary deep copy is 246-251 ns/op, 696 B/op, 8 allocs/op; the rare metadata-bearing path is 274-275 ns/op, 760 B/op, 9 allocs/op.\n- Proto round-trip, deep-copy, flattening, parameter-order reset, and scalar-subquery source provenance tests cover the sparse representation.\n\n2. Explicit DOUBLE-cast fast path\n- FLOAT/DOUBLE user casts now use the dedicated explicit-cast overload, preserving the parsed semantic boundary in the bound plan.\n- Deferred-ABS discovery and runtime-specialization admission now require the explicit fallback marker and exclude the explicit cast boundary.\n- Added parser-to-plan coverage proving ABS(CAST(? AS DOUBLE)) has no fallback positions and requires no runtime specialization.\n- Added frontend cache coverage that executes the same prepared statement first with INT64 and then DOUBLE descriptors and proves both executions reuse the original plan and cached compile without creating a runtime specialization entry.\n\nConflict integration\n- Integrated prepared-ABS specialization with main's new direct-result specialization path: numeric-prefix/ABS categories use the full semantic key, direct-result-only executions use the direct-result key, and parameter provenance is retained when the paths overlap.\n- GitHub now reports the PR mergeable; CI has restarted on the new head.\n\nLocal validation:\n- full go test ./pkg/sql/plan ./pkg/frontend\n- real TestIssue27294PreparedNumericOverloads\n- go vet ./pkg/sql/plan ./pkg/frontend ./pkg/tests/issues\n- git diff --check\n- benchmark above, count=3\n\nPlease re-review exact head b958ced. |
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed exact head b958ced6ffde0d694f276aa42187ea4cffc0b756 against its current merge base.
The prior global Expr-footprint and direct ABS(CAST(? AS DOUBLE)) findings are materially addressed: prepared metadata is now one optional pointer (ordinary Expr size 168 bytes), and the real parser path preserves a top-level explicit DOUBLE cast without deferred specialization.
One blocking correctness gap remains in the new detector. containsExplicitFloatCast recursively treats a DOUBLE cast anywhere in CASE/IF—including control-only conditions—as fixing the ABS argument's value domain. For example:
ABS(CASE WHEN CAST(? AS DOUBLE) > 0 THEN ? ELSE ? END)
The condition cast does not determine the type/exactness of the selected value parameters, but it makes hasExplicitFloatCast true, so markPreparedNumericFallback is skipped. A selected INT64 value such as -9007199254740993 therefore stays on the provisional DOUBLE path and can be rounded. The same problem applies to IF/control-only subtrees and unrelated nested functions.
Make the explicit-float test value-domain aware—only a cast that fixes the produced ABS argument should suppress fallback—and add real parser/COM_STMT controls with a control-only DOUBLE cast plus wide integer/DECIMAL value branches. Exact-head CI is green but does not cover this separation.
aptend
left a comment
There was a problem hiding this comment.
Reviewed exact head b958ced6ffde0d694f276aa42187ea4cffc0b756 against merge base e5f26b66195373f9bff512ac9f428788d1c07e8c.
The prior wide-integer/DECIMAL, scalar-subquery, multi-marker, stale-cache, global Expr-footprint, and top-level explicit-DOUBLE findings are materially closed. I also exercised the control-only cast concern independently: the parser-produced CASE WHEN CAST(? AS DOUBLE) > 0 THEN ? ELSE ? END plan retains fallback positions [1,2]; the direct IF(CAST(? AS DOUBLE), ?, ?) shape has no bounded ABS fallback metadata, but remains on the generic runtime-specialization path and a real COM_STMT execution returned BIGINT 9007199254740993 exactly. I therefore could not reproduce a correctness failure from that shape.
Exact-head verification passed: full pkg/sql/plan and pkg/frontend, focused race coverage for prepared/runtime-specialization paths, and the embedded COM_STMT regression TestIssue27294PreparedNumericOverloads.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed exact head b958ced. Rechecked prepared numeric overload selection for fractional values across parameter binding, decimal/float coercion, result metadata, NULL/error boundaries, and direct-vs-prepared compatibility. The revised dispatch accepts the intended fractional prepared inputs without broadening unrelated overloads or adding per-row work; exact-head CI is green. No blocking correctness, compatibility, unhappy-path, or performance issue remains.
|
Updated exact head: The newest exact-head review on I have now:
Fresh validation on the new head:
All passed. @aunjgr please re-review the updated exact head so the superseded CHANGES_REQUESTED state can be cleared. |
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed exact head 7b34b2633e6af14bca4f238012039c3031a8854e against merge base 02af906c367b3ef7e530336651ba033f8c14861c and newest main@958a4ceb9e73c5e70928304996873e089279b667.
The previously demonstrated blockers are closed: all numeric value-source parameters are represented and rebound, every materialized parameter is restored before cache publication/reuse, same-category executions cannot retain prior values, and protocol-generation/category changes replace the bounded runtime specialization entry. Prepared metadata is sparse on one optional pointer, avoiding the prior global Expr size-class inflation, while real parser top-level DOUBLE casts remain fixed-domain and skip unnecessary specialization.
I also rechecked the control-only float-cast concern. Although the AST detector is intentionally broad, CASE/IF value parameters that need runtime typing remain covered by the generic prepared-runtime specialization when the ABS-specific fallback marker is absent; they are not stranded as first-execution DOUBLE literals. The real COM_STMT matrix covers multi-marker INT64/UINT64/DECIMAL256 exactness, selected CASE/IF branches, scalar subqueries, same-category value changes, NULL/error boundaries, and v29/v30 cache isolation. The increment from the last semantic head is only a current-main merge, and exact-head CI is fully green.
No blocking correctness, result-metadata, cache-generation, compatibility, ownership, unhappy-path, or performance issue remains.
|
Queued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 16 minutes 12 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #27556 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.
HintYou 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. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #27294
What this PR does / why we need it:
Server-side prepared
ABS(?)andSLEEP(?)were bound to the first integer overload while the parameter marker was still represented as text. Fractional and decimal-looking values then failed during the cached implicit integer cast.This change gives only parameter-bearing
ABS/SLEEPexpressions a stable DOUBLE binding domain during PREPARE. It leaves ordinary column calls and other prepared plans on their existing paths, so execution can reuse the cached compile without the broad per-execution plan specialization that caused the TPCC regression.Regression coverage: