Skip to content

fix(plan): retain prepared NTILE integer context for text parameters - #29632

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/prepared-ntile-text-contract-20261005
Oct 5, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/prepared-ntile-text-contract-20261005

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

Summary

Fixes #29631.

Restore the integer consumer context for prepared NTILE(?) when execution-time source rebinding supplies a MySQL string type. Use the existing strict implicit INT64 cast, retaining the original string ParamRef; do not change the NTILE overload checker, bucket algorithm, ordinary string-column behavior, or cache policy.

This closes the numeric-string portion of the accepted #26867 contract. Current Main still accepts integer 1/2/5 but rejects text "2" during planning, so this is not a blanket claim that the original integer bug returned.

Root cause and scope

BuildPreparedExecutionPlan rebuilds the query using the current parameter source domain. The PREPARE-only numeric binder does not install NTILE's INT64 context in this path; its consumer handling restores ANY/NULL but missed text. An unconverted TEXT/VARCHAR marker therefore reaches the integer-only window type checker and fails before NTILE bucket execution.

The only production change extends that existing NTILE consumer case to MySQL string source types. The cast is implicit, not explicit/numeric-prefix coercion: "2" works, while "2.5", "bad", "2tail", overflow, non-positive integers, and NULL remain errors. The marker remains value-independent and reads the current EXECUTE parameter on every invocation. This does not add a Window diagnostic probe or cache state.

Regression coverage

  • Extend the existing planner NTILE test to cover execution-time TEXT/VARCHAR rebinding, implicit INT64 consumer, retained source ParamRef, and no value-dependent plan specialization.
  • Extend the existing embedded NTILE scenario, using the same two-row fixture and one handle per protocol: SQL PREPARE and real MySQL binary prepare (interpolateParams=false), integers 1/2/5, text 1/2/5, invalid values, and immediate text/integer recovery after every error. Answers are hand-derived, not another server query.
  • Extend the existing prepared_numeric_aggregate BVT SQL/golden pair: partitioned bucket answers, text rebinding, fractional-text rejection, NULL, and same-handle recovery. Fixed expectations are not regenerated from output.
  • Preserve TestNtileRequiresIntegerArgument controls rejecting a string column, fractional input, and explicit CHAR expression.

No Workflow, new fixture, service, global configuration, or runner changes. Local-only validation bridge/configs/reports are outside the commit.

Host 50 validation

Base: official Main 625404fd7d665f8d82356cdd8440f0876abfb24a; Linux host 50; Go 1.26.4; CPU CGo artifacts built in the owned worktree with native provenance verified by mo-cgo-test.

  • RED before production fix: planner execution rebind fails for TEXT/VARCHAR; real binary "2" fails with bad value [TEXT]; SQL EXECUTE "2" fails with bad value [VARCHAR]. Integer controls succeed.
  • GREEN: targeted planner NTILE tests, including unchanged ordinary-input rejection controls.
  • Full owning planner package: PASS, 8.047s.
  • Full embedded package: PASS, 320.462s. After a test-only Rows ownership/linter cleanup, the complete affected TestPreparedSpecializedDomains parent was rerun three times: 3/3 PASS, 10.930s total.
  • Normal mo-tester BVT comparison on the canonical embedded SQL-integration fixture, two passes against the same CN: 63/63 per pass, zero failed/ignored/abnormal; all seven NTILE executions selected; source/golden hashes unchanged; case database absent after each pass. method=run, no genrs.
  • Final go vet on pkg/sql/plan and pkg/embed: PASS.
  • Incremental configured golangci-lint on both packages: 0 issues.
  • gofmt and git diff --check: PASS.

The source-domain rebind boundary is relevant to the failure mechanism, but no parent/child first-introducing-merge A/B is claimed. CI remains a separate gate after submission.

@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

Choose a reason for hiding this comment

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

Approve — reviewed commit 360c6dad2c52123a87c7eb09587970abc276b0b0. No blocking findings. No subagents used.

The fix belongs at the existing prepared consumer-binding boundary: execution-time source rebinding retains the original string ParamRef and installs NTILE's strict implicit INT64 conversion before overload resolution. It does not introduce another parser, cache state, or bucket execution path. Fractional/invalid/prefix text is still rejected; NULL and non-positive values reach the existing execution checks. Explicit CHAR expressions and ordinary string columns retain their rejection behavior.

Reviewed all five changed files, including caller/consumer flow, source transport, cast mode, runtime specialization admission, error recovery and Rows/statement/table cleanup. The planner test establishes source identity, implicit conversion, value independence and template preservation; the existing two-protocol fixture checks real results/errors/reuse, while BVT checks partitioned results and metadata. Production is +6/-3 (net +3); tests/goldens are +205/-13 (net +192); documentation is unchanged. No new fixture or execution framework.

Independent QA on this exact head: 18/18 additional public cases passed using the existing one-CN fixture and a temporary uncommitted Go overlay. Both SQL EXECUTE and binary prepare were challenged with two independent NTILE markers, opposite window orderings, INT64_MAX, binary-string sources, source-type transitions, text zero/negative/empty/underflow, and immediate same-handle recovery after failure. Ordinary string-column and explicit CHAR rejection controls also passed. The package invocation completed successfully in 11.031s.

Reused the exact-head green CI (build, UT, SCA, coverage and both applicable BVT jobs), and the documented author evidence for the baseline failure, full owning packages and twice-run canonical BVT. Local diff check passed. There are no outstanding actionable review comments. The change adds a bounded binder type predicate and the required existing runtime conversion for newly supported text inputs; it does not add a diagnostic probe or relax cache admission. No throughput benchmark claim is made.

@mergify

mergify Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@mergify

mergify Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

queue

⚠️ Invalid commit message

Details

section not found

This branch was previously deployed

1 inactive deployment
ci — ca36bae3 Deployed Oct 5, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prepared NTILE rejects numeric text after execution-time source rebinding (closed #26867 acceptance regressed)

3 participants