Repository navigation
fix: install prepared Boolean precision rewrites - #28651
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed e633b74 against main a6a493a. No concrete merge-blocking issue found. COMMENT only for this self-authored PR.
This closes the specific baseline limitation recorded in #28628: the existing rebinder already constructs the Boolean-source-to-int64 precision argument, but unchanged outer overload/result metadata previously left specialized=false and the frontend discarded that copied plan. Setting specialized at the actual source-rewrite boundary makes the frontend adopt the changed expression and avoid its incompatible prepare-time compile.
The flag is scoped to an existing occurrence-qualified SQL-source rewrite, not every literal replacement or parameter. It does not add HasRuntimeType to Boolean user variables or change bare-result materialization, so #28628's direct TEXT result/metadata separation remains intact. NULL does not manufacture a non-NULL numeric source. Explicit casts, nonnumeric control occurrences and ordinary string conversion remain subject to the existing eligibility/domain rules. This flag can also install pre-existing value-only rewrites for other eligible numeric sources; it is an installation invariant, not a Boolean-only conversion rule.
I traced plan adoption and cached compile selection, including the bounded category cache: cacheable rewrites retain/restore ParamRefs for current execution values, while noncacheable value-specialized copies are installed for that execution. Existing error propagation prevents installation after a failed rebind. No new rounding policy, precision bound, vector kernel, row-mask handling, wire field or persistent state is introduced.
The new planner test checks both the specialization signal and the Boolean-to-int64 precision expression for ROUND/TRUNCATE. The embedded regression compares each function and both marker positions against direct SQL across TRUE/FALSE/NULL/1/0 reuse. Existing mixed direct-result/numeric-sibling controls still assert TEXT metadata and TRUE/FALSE/NULL/TRUE values.
Non-blocking follow-up: add negative precision and a mixed bare marker plus ROUND(1.25, ?) control, and consider invalid-string-after-success execution. Those would strengthen this exact installation regression but are not demonstrated blockers. The fix can cause compilation for value-only cases that previously discarded the copy; that extra work is required for correctness and should not be described as a free performance change.
Evidence/limits: complete three-file diff and PR discussion, #28484 and #28628 review history, exact-head source-domain construction, occurrence eligibility, frontend installation/cache and retained metadata controls inspected. Head/base rechecked before submission. Reported normal/race/package tests were not independently rerun here; no live SQL, distributed or mixed-version experiment and no CI wait.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28484 ## What this PR does / why we need it: SQL `PREPARE`/`EXECUTE` already materializes a Boolean user-variable source for generic numeric functions, but the runtime specialization signal only tracked overload or result-type changes. For `ROUND(1.25, ?)` and `TRUNCATE(1.25, ?)`, the precision argument changes while the selected overload and result type stay stable, so the copied plan was discarded and the cached text-to-integer cast rejected `TRUE`/`FALSE`. This change marks every SQL-EXECUTE numeric-source rewrite as requiring installation of the copied runtime plan at the shared rebinding boundary. It fixes both argument positions without changing ordinary literal SQL, explicit casts, string-backed parameters, or COM_STMT behavior. ## Test plan - Added planner coverage proving the value-only rewrite is marked specialized and contains the Boolean-to-int64 precision cast for both `ROUND` and `TRUNCATE`. - Added embedded-cluster SQL coverage for both marker positions and `TRUE`, `FALSE`, `NULL`, `1`, and `0`; each `EXECUTE ... USING` result is compared with the equivalent direct SQL expression. - Focused planner test: normal and `-race`. - Focused issue regression test: normal and `-race`. - Full `pkg/sql/plan` and `pkg/tests/issues` suites. - Incremental `go vet` and `golangci-lint` for the owning packages with the repository CGo build environment.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28484 ## What this PR does / why we need it: SQL `PREPARE`/`EXECUTE` already materializes a Boolean user-variable source for generic numeric functions, but the runtime specialization signal only tracked overload or result-type changes. For `ROUND(1.25, ?)` and `TRUNCATE(1.25, ?)`, the precision argument changes while the selected overload and result type stay stable, so the copied plan was discarded and the cached text-to-integer cast rejected `TRUE`/`FALSE`. This change marks every SQL-EXECUTE numeric-source rewrite as requiring installation of the copied runtime plan at the shared rebinding boundary. It fixes both argument positions without changing ordinary literal SQL, explicit casts, string-backed parameters, or COM_STMT behavior. ## Test plan - Added planner coverage proving the value-only rewrite is marked specialized and contains the Boolean-to-int64 precision cast for both `ROUND` and `TRUNCATE`. - Added embedded-cluster SQL coverage for both marker positions and `TRUE`, `FALSE`, `NULL`, `1`, and `0`; each `EXECUTE ... USING` result is compared with the equivalent direct SQL expression. - Focused planner test: normal and `-race`. - Focused issue regression test: normal and `-race`. - Full `pkg/sql/plan` and `pkg/tests/issues` suites. - Incremental `go vet` and `golangci-lint` for the owning packages with the repository CGo build environment.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28484 ## What this PR does / why we need it: SQL `PREPARE`/`EXECUTE` already materializes a Boolean user-variable source for generic numeric functions, but the runtime specialization signal only tracked overload or result-type changes. For `ROUND(1.25, ?)` and `TRUNCATE(1.25, ?)`, the precision argument changes while the selected overload and result type stay stable, so the copied plan was discarded and the cached text-to-integer cast rejected `TRUE`/`FALSE`. This change marks every SQL-EXECUTE numeric-source rewrite as requiring installation of the copied runtime plan at the shared rebinding boundary. It fixes both argument positions without changing ordinary literal SQL, explicit casts, string-backed parameters, or COM_STMT behavior. ## Test plan - Added planner coverage proving the value-only rewrite is marked specialized and contains the Boolean-to-int64 precision cast for both `ROUND` and `TRUNCATE`. - Added embedded-cluster SQL coverage for both marker positions and `TRUE`, `FALSE`, `NULL`, `1`, and `0`; each `EXECUTE ... USING` result is compared with the equivalent direct SQL expression. - Focused planner test: normal and `-race`. - Focused issue regression test: normal and `-race`. - Full `pkg/sql/plan` and `pkg/tests/issues` suites. - Incremental `go vet` and `golangci-lint` for the owning packages with the repository CGo build environment.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #28484
What this PR does / why we need it:
SQL
PREPARE/EXECUTEalready materializes a Boolean user-variable source for generic numeric functions, but the runtime specialization signal only tracked overload or result-type changes. ForROUND(1.25, ?)andTRUNCATE(1.25, ?), the precision argument changes while the selected overload and result type stay stable, so the copied plan was discarded and the cached text-to-integer cast rejectedTRUE/FALSE.This change marks every SQL-EXECUTE numeric-source rewrite as requiring installation of the copied runtime plan at the shared rebinding boundary. It fixes both argument positions without changing ordinary literal SQL, explicit casts, string-backed parameters, or COM_STMT behavior.
Test plan
ROUNDandTRUNCATE.TRUE,FALSE,NULL,1, and0; eachEXECUTE ... USINGresult is compared with the equivalent direct SQL expression.-race.-race.pkg/sql/planandpkg/tests/issuessuites.go vetandgolangci-lintfor the owning packages with the repository CGo build environment.