Skip to content

fix: preserve prepared Boolean math semantics - #28628

Merged
XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-28484-prepared-bool
Sep 11, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-28484-prepared-bool

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 10, 2026 •

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

Follow-up to #28513: fixes the SQL PREPARE/EXECUTE Boolean acceptance failure
reported after that change merged.

What this PR does / why we need it:

SQL EXECUTE transports user-variable values through a text-shaped vector but
retains their logical prepare-time category. The planner must use that
provenance for numeric consumers without changing the historical result domain
of a bare SQL ? projection.

Before this fix, TRUE in CAST(? AS DOUBLE), SIN(?), or ACOS(?) could be
parsed as an ordinary nonnumeric string and become zero in MySQL mode. Integer
consumers such as ABS(?), ROUND(?), and SIGN(?) could reject the same
Boolean with an invalid cast. A Boolean value can also be reused across
executions, NULLs, ordinary strings, and direct-result/numeric sibling
expressions.

Design and implementation

  • SQL EXECUTE carries Boolean SourceType metadata for overload rebinding;
    HasRuntimeType remains unset for a bare SQL result marker, preserving its
    TEXT result metadata. Explicit COM_STMT runtime types remain authoritative.
  • Numeric consumers use the source type to select the existing integer/float
    overloads. The shared string-to-float conversion consults row-local
    Boolean provenance and maps canonical Boolean transport values to 0/1.
  • NULLs and inactive selection rows are handled before conversion. Ordinary
    SQL strings such as 'true' stay on the existing string-coercion and warning
    path; malformed values marked as Boolean fail explicitly.
  • The integration regression closes each query's Rows in a per-iteration
    scope, so assertion failures cannot retain server-side result resources.
  • The repository's .agents/skills/mo-dev now documents changed-package
    static checks and evidence-based CI/environment triage instead of requiring a
    whole-repository SCA in every edit loop.
  • No wire-format, persistence, planner-cache, synchronization, I/O, or
    background-work change is introduced. Runtime plan copies remain isolated
    from the cached prepared plan.

Test plan

Validated from a clean worktree rebased onto origin/main commit
44b7f90ee1695831663c55288a537c03c15c00e0:

  • pkg/sql/plan/function: Boolean FLOAT/DOUBLE casts, inactive rows, and
    numeric math consumers; focused -race passed.
  • pkg/sql/plan: numeric overload/source-type rebinding, direct-result domain
    isolation, cache-plan immutability, and existing prepared parameter tests;
    focused -race passed.
  • pkg/frontend: prepared execution/metadata and related reuse tests;
    focused -race passed.
  • TestIssue27088PreparedDecimalCommonType: real embedded SQL PREPARE/EXECUTE
    coverage for TRUE/FALSE/NULL/string/reuse, integer targets, JSON controls,
    and the direct-parameter-before/after-numeric-sibling case passed in 9.5s
    after the SCA cleanup fix.
  • prepare/numeric_context changes add the reported CAST/SIN/ACOS and
    ABS/ROUND/SIGN reuse cases.
  • Incremental golangci-lint sqlclosecheck on pkg/tests/issues, with the
    repository CGo include paths, passed with 0 issues.
  • quick_validate.py .agents/skills/mo-dev and git diff --check passed.

CI was not awaited. The current PR's historical compose information-schema
failure and resource-heavy UT cancellation are outside the changed paths;
no unrelated test or catalog behavior was modified here.

Review status

The complete final diff was reviewed with GPT-6 medium after implementation.
No remaining P0/P1/P2 semantic, metadata, NULL/mask, reuse, lifecycle, or
performance blocker was identified.

Final head: cec5ce0bc645f3d4a52450312a540541cb703e18.

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

@mergify mergify Bot added the kind/bug Something isn't working label Sep 10, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 10, 2026

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

Re-reviewed exact head cec5ce0 against main 44b7f90. COMMENT only for this self-authored PR.

Conclusion: no remaining concrete P0/P1/P2 blocker found in the current change. The prior direct-result regression is resolved in the implementation: SQL Boolean parameters carry SourceType without HasRuntimeType, so numeric overload rebinding can use Boolean provenance without converting an unrelated bare SQL result marker into a BOOL literal. Explicit protocol RuntimeType remains authoritative. The new frontend and embedded tests exercise direct markers before/after/between numeric siblings, TRUE/FALSE/NULL reuse, TEXT client metadata, and cached-plan immutability.

The FLOAT/DOUBLE conversion checks inactive and NULL rows before reading provenance, uses row-local/constant-aware kind lookup, maps Boolean transport values to 0/1, and leaves ordinary string parsing/warnings on the existing path. Malformed Boolean-tagged input fails explicitly. SIGN's numeric-context addition is scoped to a numeric value consumer. I found no new numeric-width/overflow policy, persistent format, wire field, shared mutable owner, or unbounded retained allocation introduced by this fix.

The historical Boolean precision-argument limitation in ROUND/TRUNCATE remains a separate baseline issue from the earlier review, not a newly demonstrated regression here. I do not treat optional expansion of that coverage as a blocker.

Evidence: current eleven-file diff, previous reviews and issue context, parameter production, specialization/source-domain selection, float conversion, provenance accessor, integration/BVT oracles and cleanup reviewed. Author-reported focused function/planner/frontend race tests and embedded SQL acceptance were considered as reported; I did not independently rerun native tests or BVT. At inspection, current-head Ubuntu UT/coverage, shared build and arm64 SCA were still in progress, so this is not a claim that CI is green or that historical failures are independently proven unrelated. No CI wait and no repository edits. Head/base were rechecked immediately before posting.

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants