Skip to content

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

Closed

Description

@LeftHandCold

Summary

Main rejects an integer-valued text parameter in NTILE(?) after execution-time source-domain rebinding, violating the numeric-string acceptance contract recorded when #26867 was closed. Integer parameters still work; this is not a recurrence of every aspect of the original integer-parameter bug.

No other open issue or in-flight fix specifically tracking this prepared NTILE text-parameter failure was found.

Versions and original acceptance

  • Nightly MO: 21f711a7b852238394417e547282e14dce8660d9.
  • Independently reproduced on host 50 against fresh Main 625404fd7d665f8d82356cdd8440f0876abfb24a using actual MySQL binary prepared statements (interpolateParams=false) and SQL PREPARE/EXECUTE.
  • The original fix fix(plan): infer prepared ntile parameters #26950 (3bd2abea304bab6696f9442f3cfde18404987841) is included in both versions.
  • Original closing acceptance explicitly accepts string "2" as well as integers 1/2/5, rejects invalid inputs, and requires recovery on the same prepared handle. It was validated against e8ecba8662ca4c4d9c0179978425fc08505967dc.

Reproduction

CREATE DATABASE ntile_text_repro;
USE ntile_text_repro;
CREATE TABLE t(id INT);
INSERT INTO t VALUES (1),(2);
PREPARE p FROM 'SELECT id, NTILE(?) OVER (ORDER BY id) AS bucket FROM t ORDER BY id';
SET @n=2;
EXECUTE p USING @n; -- (1,1), (2,2): succeeds
SET @n='2';
EXECUTE p USING @n; -- expected same buckets; actual type error
SET @n=2;
EXECUTE p USING @n; -- integer execution still succeeds
DEALLOCATE PREPARE p;
DROP DATABASE ntile_text_repro;

SQL EXECUTE error:

Error 20203 (HY000): invalid argument function ntile, bad value [VARCHAR]

Using one Go MySQL Conn and one Stmt, bind int64(1), int64(2), int64(5), then "2". The integers return hand-derived buckets; the string fails with:

Error 20203 (HY000): invalid argument function ntile, bad value [TEXT]

Nightly evidence

Main MOTR Job, frozen MOTR 5b9fc960ba80d6f502a9b94996e2fb4d595527f5, case 14_issue_regression.issue_26867_prepared_ntile:

PASS: literal NTILE(2) matches hand-derived multi-partition buckets
PASS: binary prepared NTILE(?) reuses parameters 1,2,5
FAIL: numeric string parameter: Error 20203 (HY000): invalid argument function ntile, bad value [TEXT]

The frozen driver uses a real binary prepared statement on the same connection/handle. This is not a Runner substitution or an acceptable change to the oracle. The case is Main-only, so its absence from 4.2 is not evidence of a 4.2 pass.

Confirmed root cause and fix boundary

The PREPARE template has an INT64 consumer context for NTILE. The current execution-time source-type rebind rebuilds the plan rather than merely filling that template. bindPreparedNumericFuncExpr only installs this context for PREPARE; bindPreparedConsumerArguments restores it for NTILE's NULL/ANY source but misses MySQL string sources. Thus a TEXT/VARCHAR marker reaches the integer-only NTILE type checker unconverted and is rejected before bucket execution.

#29462 is the source-domain rebind mechanism boundary, but a parent/child performance or functional A/B identifying the first bad merge has not been run; this report does not claim an exact first introducing commit.

The minimal fix should restore a strict implicit INT64 conversion at this prepared NTILE consumer only. It must not loosen ordinary NTILE string-column overloads, truncate fractional/prefix text, change the bucket algorithm, specialize plans to the current value, or relax invalid-input checks. Retain same-handle good/bad/good coverage for both protocols and verify that cached execution still reads the current parameter.

Activity

  1. added
    kind/bug
    on Oct 5, 2026
  2. added a commit that references this issue on Oct 5, 2026
    35e750e
  3. added
    severity/s0
    and removed on Oct 7, 2026
  4. Ariznawlll commented on Oct 8, 2026

    @Ariznawlll
    Collaborator

    在当前 main bab4b3286a0dd5683a9b291763817722233e586c 上补充真实 MySQL 二进制 prepared statement 覆盖。测试表包含两个分区(分别 5 行和 4 行),同一个 NTILE(?) OVER (PARTITION BY grp ORDER BY id) handle 交替绑定并重复 3 轮。

    结果如下:

    • int64(2)、uint64(3)、文本 "2"、二进制字符串 []byte("2") 均生成准确 bucket;
    • 每个 partition 独立重新编号,bucket 数大于/接近分区行数时结果符合手工计算;
    • DOUBLE 2.0 保持严格类型检查,不被隐式放宽;
    • 小数文本 "2.5" 和前缀文本 "2x" 均返回明确的整数转换错误,没有截断接受;
    • 0 返回 bucket count 必须为正的错误,NULL 返回 bucket count 不能为 NULL 的错误;
    • 每组异常输入后重新绑定文本 "4",两个分区均恢复为准确的 4 bucket 结果。

    三轮输出一致;文本/二进制字符串整数上下文已保留,异常参数没有污染同一 prepared handle 的后续执行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions