Skip to content

fix: install prepared Boolean precision rewrites - #28651

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-28484-precision
Sep 11, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-28484-precision

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

Fixes #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.

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

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@XuPeng-SH
XuPeng-SH merged commit cd8e8d9 into matrixorigin:main Sep 11, 2026
17 of 21 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/fix-28484-precision branch September 11, 2026 02:45
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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.

This branch was previously deployed

1 inactive deployment
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/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compatibility]: most math functions reject or misread Boolean expressions

2 participants