Repository navigation
Description
Is there an existing issue for the same bug?
- I searched open and closed issues and pull requests for prepared
NTILE, parameter markers, and the observed internal error. No exact duplicate was found.
Branch Name
main
Commit ID
1d00cca77012a2fac20c94bbbd170579e715d217
Other Environment Information
- MatrixOne:
8.0.30-MatrixOne-v1.3.0 - Deployment: local
mo-service, 2 CN / 1 TN / 1 Log service / Proxy - Both SQL
PREPAREand MySQL binary-protocol prepared statements were tested
Actual Behavior
NTILE(?) prepares successfully, but executing it with a valid positive integer fails with an internal error:
ERROR 20101 (HY000): internal error: ntile bucket count must be integer type
Values 1, 2, and 5 all produced the same error. The failure reproduced 3/3 times with binary-protocol prepared statements and 3/3 times with SQL PREPARE/EXECUTE. The full matrix was rerun after main advanced from ec06a68b8 to the commit above and still reproduced 3/3.
The literal and explicitly typed parameter controls both work:
NTILE(2): 1:1 | 2:1 | 3:2 | 4:1
NTILE(CAST(? AS SIGNED)): 1:1 | 2:1 | 3:2 | 4:1
Expected Behavior
Binding a valid positive integer through a positional parameter marker should produce the same buckets as the equivalent literal. MySQL documents a positional parameter marker as a valid form for the N argument of NTILE.
Steps to Reproduce
DROP DATABASE IF EXISTS ps_ntile;
CREATE DATABASE ps_ntile;
USE ps_ntile;
CREATE TABLE t(id INT PRIMARY KEY, g INT);
INSERT INTO t VALUES (1,1),(2,1),(3,1),(4,2);
-- Correct literal control.
SELECT id,NTILE(2) OVER(PARTITION BY g ORDER BY id)
FROM t ORDER BY id;
-- PREPARE succeeds, but EXECUTE returns internal error 20101.
PREPARE ntile_param FROM
'SELECT id,NTILE(?) OVER(PARTITION BY g ORDER BY id) FROM t ORDER BY id';
SET @buckets=2;
EXECUTE ntile_param USING @buckets;
-- Correct typed-parameter control.
PREPARE ntile_cast FROM
'SELECT id,NTILE(CAST(? AS SIGNED)) OVER(PARTITION BY g ORDER BY id) FROM t ORDER BY id';
EXECUTE ntile_cast USING @buckets;The same error occurs with protocol prepared statements such as Go db.Prepare followed by stmt.Query(2).
Additional information
This appears to be another missing numeric-context propagation for a prepared window argument:
- The
NTILEfunction definition inpkg/sql/plan/function/list_window.goaccepts one argument without constraining it to an integer type. - During execution,
pkg/sql/colexec/window/window.goevaluates that argument and passes its vector to theNTILEaggregate executor. pkg/sql/colexec/aggexec/window.go::ntileWindowExec.Fillaccepts only integer vectors and emits the internal error for every other type.CAST(? AS SIGNED)succeeds, isolating the failure to prepared-parameter type inference rather than theNTILEalgorithm.
Related but not duplicate: #23017 / #23760 implemented NTILE; #25993 concerned parameter markers in window frame bounds; #26019 concerned prepared SUM/AVG inference.
MySQL reference: https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html
Activity
Ariznawlll commentedon Aug 12, 2026
测试版本
maine8ecba8662ca4c4d9c0179978425fc08505967dc原问题验证
使用 SQL PREPARE 和
go-sql-driver/mysql的真实 binary prepare(interpolateParams=false,复用同一连接和同一 statement)执行NTILE(?)。合法参数1 / 2 / 5连续 3 轮均成功,分区内 bucket 结果与 literal NTILE 对照完全一致,未再出现ntile bucket count must be integer type。Happy Path 覆盖
NTILE(1/2/5)结果均正确。"2"按支持的数字转换规则成功执行;随后同一 statement 再绑定整数,结果仍正确。Unhappy Path 覆盖
0、-1被拒绝为 bucket 数必须为正;NULL被拒绝为不能为 NULL。2.5和bad被拒绝为无效整数值;同时核对稳定的错误 cause,避免把无关 internal error 当作通过。白盒验证
本轮验证的是公开 SQL 与 binary protocol 行为,不需要故障注入;修复侧的类型推断/执行器测试由关联修复覆盖。
回归测试
已在 motr PR #107 增加
14_issue_regression.issue_26867_prepared_ntile,使用真实 binary prepare,并包含合法参数、转换边界、全部无效输入和错误后同 handle 恢复。定向--repeat 3为 3/3,通过;与 #26797、#26892 并行复跑总计 9/9,通过。测试证据
测试结论
测试通过。
fix(plan): retain prepared NTILE integer context for text parameters (#…