Skip to content

fix: preserve prepared arithmetic and exact integer semantics - #27795

Draft
ck89119 wants to merge 6 commits into
matrixorigin:mainfrom
ck89119:issue-25408-runtime-v2-main
Draft

fix: preserve prepared arithmetic and exact integer semantics#27795
ck89119 wants to merge 6 commits into
matrixorigin:mainfrom
ck89119:issue-25408-runtime-v2-main

Conversation

@ck89119

@ck89119 ck89119 commented Aug 28, 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:

issue #25408
issue #27492

What this PR does / why we need it:

Prepared executions transport SQL user-variable values and binary-protocol string values through text-backed parameter vectors. Two related runtime-specialization gaps could therefore reuse or select an approximate domain that did not match the current execution:

  • EXECUTE ... USING arithmetic could retain an earlier integer cast when a later execution supplied DECIMAL;
  • text-backed BIGINT UNSIGNED and BIT(64) comparisons could pass 2^53+1 through DOUBLE, merging adjacent BIGINT values or raising a BIT range error.

This PR keeps the two ownership rules separate while validating them together:

  • SQL arithmetic rebinding uses the current user variable's logical source type and includes it in the specialization-cache identity;
  • comparison rebinding recognizes text operands against exact integer/BIT peers and materializes an in-range integral numeric prefix directly in the peer domain;
  • fractional, out-of-range, nonnumeric, and DECIMAL string comparisons retain the existing MySQL-compatible DOUBLE fallback;
  • BIT comparisons remain in the BIT domain, preserving the column-side comparison/index contract;
  • specialized literals retain parameter provenance so same-category cached plans read each execution's current value.

The implementation is based on current main after #27483. No code was cherry-picked from the older broad implementation in #27466.

Testing

  • complete pkg/sql/plan and pkg/frontend test packages
  • complete TestIssue27088PreparedDecimalCommonType, including SQL PREPARE and COM_STMT BIGINT UNSIGNED/BIT(64) string, integer, NULL, and reuse transitions
  • CGo-wrapper vet=all for pkg/sql/plan, pkg/frontend, and pkg/tests/issues
  • make build
  • prepare_all.sql in normal mo-tester comparison mode twice on the same final binary: 438 total / 437 success / 0 failed / 1 ignored / 0 abnormal in both runs
  • package coverage runs: planner 79.1%, frontend 64.1%, with focused tests for every new specialization branch

@ck89119 ck89119 changed the title fix: rebind SQL EXECUTE arithmetic parameter types fix: preserve prepared arithmetic and exact integer semantics Aug 28, 2026
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Aug 28, 2026
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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants