Skip to content

fix: preserve prepared variadic comparison domains - #29345

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-prepared-variadic-comparison
Sep 25, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-prepared-variadic-comparison

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 24, 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 #29317
Fixes #29318

What this PR does / why we need it:

Prepared SQL EXECUTE transported user variables as text and allowed provisional marker casts/numeric-prefix conversion to choose the wrong comparison domain for all-parameter GREATEST/LEAST and FIELD. Binary FIELD operands could also fall through to DOUBLE comparison.

  • Restore each SQL variable's source type at these variadic comparison operands before rebinding the complete tuple. Keep actual string operands as string boundaries; restore numeric literal peers only when the tuple has no actual string operand.
  • Route binary/text-only FIELD tuples through the existing byte-preserving, case-insensitive string implementation. Leave COM_STMT protocol typing and explicit SQL casts unchanged.
  • Pin the planner-generated vector-index overfetch LEAST() arithmetic to explicit UINT64, so execute-time variadic rebinding cannot reinterpret a prepared LIMIT as signed or decimal. Cover saturation boundaries and decimal inputs.
  • Add planner/function unit coverage and a public SQL BVT for mixed numeric/text values, binary NUL/case behavior, NULL, statement reuse, explicit casts, and numeric literal peers.

Validation on base 2f25834093 (isolated local MatrixOne service): original three issue reproductions fail before the change and match direct SQL after it. pkg/sql/plan and pkg/sql/plan/function full CGo test suites pass. New BVT: 37/37 statements pass. Earlier GPT-6 Astra medium independent final review: no blockers. The subsequent two unsigned-overfetch commits have focused planner regression coverage and are included in the current final review.

Latest-main rebase and current validation

Rebased onto matrixorigin/main@e914d987641c266162eb607ec072fdb5a2b06da9 (including #29369); new head 4876d85a92c2ef099bfd559771bd18abc7de3354. Main moved ParamValue from plan to executor; the conflict resolution keeps the existing plan.ParamValue alias and relocates this PR's SourceType comment to the defining type in pkg/util/executor/options.go. git range-diff confirms all behavioral patches are retained; the other eight file diffs are byte-for-byte identical. git diff --check passes.

Focused post-rebase CGo tests passed for prepared variadic source domains, unsigned/decimal vector overfetch boundaries, FIELD type handling, and the newly merged prepared generate_series consumers. The pkg/sql/compile CGo test binary also compiled and linked successfully. Full CI on this head is pending.

@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

Copy link
Copy Markdown
Contributor Author

Follow-up fix pushed in 0bf4aca0e0. The pessimistic multi-CN BVT failure was in vector_prepared_limit.sql (2 executions): prepared runtime-source restoration for LEAST/GREATEST also rewrote the already-typed uint64 LIMIT marker inside the generated overfetch budget to the SQL variable's DECIMAL128 source type. The table-function LIMIT evaluator then rejected the budget. Source-type restoration is now restricted to provisional string/ANY markers and binder-inserted implicit casts; consumer-typed markers keep their domain. A focused overfetch regression failed before the change and passes afterward. Full pkg/sql/plan and pkg/sql/plan/function tests, build, vet, and incremental lint pass locally. The PR's new prepared_variadic_comparison.sql case was 37/37 in the earlier CI. The unrelated Ubuntu UT job stopped during checkout with a GitHub TLS handshake error, before tests ran. Fresh CI after this push is still pending.

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

Deep review of 2c56474 against base/merge-base 7db5bee: no new blocking finding in this PR's diff. COMMENT only because this account is the PR author; this is not a GitHub approval.

Reviewed all 10 changed files and traced three behavioral closures: SQL EXECUTE source-domain restoration and peer rebinding; FIELD string-family dispatch; and generated UINT64 vector-overfetch arithmetic through the expression/TVF consumer. Explicit CAST, real string boundaries, nested consumers, numeric-prefix conversion, binary-protocol separation, NULL and cached-plan immutability were checked. No new async/resource/wire-format contract requiring race or Q1-Q3 testing was identified.

Validation: reused successful current-head CI run 36085561188, including Ubuntu UT and multi-CN BVT (the pessimistic job selects prepared_variadic_comparison.sql and vector_prepared_limit.sql). Locally reran the focused variadic, FIELD and overfetch tests with CGo and -count=1. Independent reviewer probes verified fresh-plan equivalence/template immutability across numeric/text/binary/NULL/protocol transitions, and all 18 prepared DECIMAL-source overfetch boundary cases passed, including zero and UINT64_MAX in both overfetch modes. Direct-vs-prepared probes also covered explicit CHAR, nested/string boundaries, invalid numeric strings and Boolean sources.

Adjacent existing issue, not attributed to this PR: a DECIMAL(38,0) source 9007199254740993 passed to FIELD(?, 9007199254740992) yields 1, while direct SQL and the all-parameter control yield 0; an explicit DECIMAL fixed peer also reproduces it. The same probes fail identically on base 7db5bee and this head, so this was excluded from new blocking findings. This was reproduced through parsed PREPARE, production parameter specialization and expression evaluation, not a new live-service BVT run.

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

2 participants