You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Prepared SUM and AVG reject parameter markers as TEXT #26019
I searched open and closed issues for prepared aggregate parameter markers, SUM(?), AVG(?), and the observed TEXT type error. No exact duplicate was found.
Branch Name
main
Commit ID
50319026a69e45c3c190cb7a09e9c5fbdb7f6857
Other Environment Information
MatrixOne: 8.0.30-MatrixOne-v1.3.0
MySQL comparison: 8.0.45
SQL-level and MySQL binary-protocol prepared statements were checked.
Actual Behavior
MatrixOne rejects numeric aggregate parameter markers while preparing the statement:
PREPARE s FROM'SELECT SUM(?)';
Result:
ERROR 20203 (HY000): invalid argument aggregate function sum, bad value [TEXT]
AVG(?) fails in the same way. The failure occurs during PREPARE, before any value can be supplied by EXECUTE.
The result reproduced 3/3 times. A binary-protocol prepared recursive CTE with SUM(n), where n originates from a parameter marker, reaches the same error.
Expected Behavior
The statement should be prepared successfully and the parameter type should be resolved from the value supplied at execution time, matching MySQL.
MySQL 8.0.45 returns 2 for each of three runs:
PREPARE s FROM'SELECT SUM(?)';
SET @n =2;
EXECUTE s USING @n;
Steps to Reproduce
PREPARE s1 FROM'SELECT SUM(?)';
SET @n =2;
EXECUTE s1 USING @n;
PREPARE s2 FROM'SELECT AVG(?)';
EXECUTE s2 USING @n;
Control statements with a direct numeric expression do work:
The parameter binder creates an untyped marker as T_text by default. Numeric aggregate overload resolution happens while constructing the prepared plan, before the execution value is available, so SUM and AVG reject the marker as TEXT.
Confirmed on current-main baseline e15943929885c2c5c83daed90f0f8caeb9a1f0d0. A bare prepared marker is initially bound as TEXT, while SUM/AVG use a fixed numeric-only aggregate type check with no implicit conversion, so the direct form fails during planning.
This needs static prepare-time numeric inference rather than execution-value-dependent typing. However, a direct aggregate special case would not close the recursive-CTE reproduction: at the aggregate boundary the marker has already become a CTE column, so the inferred type must survive recursive seed/term common-column resolution as well. The window-aggregate binder must also obey the same contract.
I therefore do not propose a direct-only PR as a close. A complete fix should cover direct SUM/AVG, recursive CTEs, repeated executions with numeric/numeric-string/NULL/invalid-string inputs, parameter metadata, window aggregates, and cached re-execution.
Re-reviewed while implementing the related prepared-statement batch, now against current main (0d7eeb38b4). No equivalent fix has landed, and the prior no-PR decision still holds.
A local SUM(?)/AVG(?) binder exception would only fix the direct expression. The recursive-CTE reproduction reaches the aggregate after the marker has become a common CTE column, so numeric intent must survive seed/recursive-term common-type resolution; window aggregates must use the same inference contract. Without that, a small PR would advertise support while the production recursive/window paths still reject or mis-type the value.
A complete PR therefore needs one static prepare-time numeric inference contract with direct aggregate, recursive CTE, window aggregate, parameter metadata, cached/repeated execution, and numeric/numeric-string/NULL/invalid-string coverage. I am not opening a partial aggregate-only PR.
现有 package UT 覆盖 metadata;稳定 text SQL 可扩展进 prepare BVT。binary 类型重绑更适合 motr/suites/14_issue_regression scenario。当前没有新提交。
测试证据
go test ./pkg/tests/issues -run '^TestCodexLive26019PreparedAggregatesTextAndBinary$' -count=3 -v
go test ./pkg/frontend -run '^TestPreparedNumericAggregateBinaryProtocolMetadata$' -count=1 -v
Activity
LeftHandCold commentedon Jul 22, 2026
Confirmed on current-main baseline
e15943929885c2c5c83daed90f0f8caeb9a1f0d0. A bare prepared marker is initially bound asTEXT, whileSUM/AVGuse a fixed numeric-only aggregate type check with no implicit conversion, so the direct form fails during planning.This needs static prepare-time numeric inference rather than execution-value-dependent typing. However, a direct aggregate special case would not close the recursive-CTE reproduction: at the aggregate boundary the marker has already become a CTE column, so the inferred type must survive recursive seed/term common-column resolution as well. The window-aggregate binder must also obey the same contract.
I therefore do not propose a direct-only PR as a close. A complete fix should cover direct
SUM/AVG, recursive CTEs, repeated executions with numeric/numeric-string/NULL/invalid-string inputs, parameter metadata, window aggregates, and cached re-execution.LeftHandCold commentedon Jul 23, 2026
Re-reviewed while implementing the related prepared-statement batch, now against current
main(0d7eeb38b4). No equivalent fix has landed, and the prior no-PR decision still holds.A local
SUM(?)/AVG(?)binder exception would only fix the direct expression. The recursive-CTE reproduction reaches the aggregate after the marker has become a common CTE column, so numeric intent must survive seed/recursive-term common-type resolution; window aggregates must use the same inference contract. Without that, a small PR would advertise support while the production recursive/window paths still reject or mis-type the value.A complete PR therefore needs one static prepare-time numeric inference contract with direct aggregate, recursive CTE, window aggregate, parameter metadata, cached/repeated execution, and numeric/numeric-string/NULL/invalid-string coverage. I am not opening a partial aggregate-only PR.
fix(plan): preserve prepared aggregate parameters (#26042)
fix(plan): infer prepared SUM and AVG parameters (#26534)
LeftHandCold commentedon Aug 1, 2026
fixed
Ariznawlll commentedon Aug 4, 2026
测试版本
mainc726a6199094184a2e6ebc7504c3e011982b8976原问题验证
原问题的
SUM(?)与AVG(?)marker 推断路径已恢复。每轮同时执行 textSELECT SUM(?)、SELECT AVG(?)、SELECT SUM(?) OVER (),并以2作为绑定参数;结果均为2。完整用例重复 3 次。Happy Path 覆盖
SUM(?)、AVG(?)、windowSUM(?) OVER ()均成功。WITH RECURSIVE ... SELECT SUM(n),AVG(n)用两个 marker 绑定1,4,结果为10,2.5。SUM(?)依次绑定整数2、浮点3.5、NULL;前两者有行结果,NULL 返回 NULL。SUM、AVG和 window SUM 的 parameter/result metadata。Unhappy Path 覆盖
SELECT 1成功,未污染 prepared handle 或连接。此处不把方言允许的 coercion 误报为 bug。白盒验证
已运行
TestPreparedNumericAggregateBinaryProtocolMetadata,其验证 prepare response 中的 marker 与 DOUBLE result metadata。此 issue 的主要风险是 planner 参数推断,公共 SQL 结果、recursive/window 分支和 binary 重绑均已实际执行。回归测试
现有 package UT 覆盖 metadata;稳定 text SQL 可扩展进 prepare BVT。binary 类型重绑更适合
motr/suites/14_issue_regressionscenario。当前没有新提交。测试证据
live 用例三轮均通过。
测试结论
测试通过。
Ariznawlll commentedon Aug 4, 2026
motr 回归补充
本评论补充已通过路径的可执行回归;此前原问题的完整验证结论见 #26019 的已有测试评论。
main@c726a6199094184a2e6ebc7504c3e011982b8976127.0.0.1:6001;2026-08-04。3d79e01b6348e23bb747de5ab9a9d16995304a29。已加入:
suites/14_issue_regression/t/issue_26019_prepared_sum_avg.testPREPARE/EXECUTE下SUM(?)以同一 handle 依次绑定INT(2)、FLOAT(3.5)、NULL;结果为2.0、3.5、NULL。AVG(?)覆盖整数/浮点重绑;SUM(?) OVER ()覆盖窗口聚合绑定。SUM/AVG,断言10.0/2.5。suites/scenarios/14_issue_regression/issue_26019_protocol_prepared_aggregates.go(由同名.sh调用)go-sql-driver/mysql的真实COM_STMT_PREPARE/EXECUTE,不是 SQL 文本EXECUTE。SUM(?)handle,验证int64、float64、nil;再验证AVG(?)和窗口SUM(?) OVER ()。NULL后继续SELECT 1,防止只检查结果而漏掉 statement/session 损坏。执行证据:
该场景的稳定 stdout 已记录在
suites/scenarios/14_issue_regression/out/issue_26019_protocol_prepared_aggregates.out;14_issue_regression整套运行时同样成功。白盒注入不适用:该问题可由公开协议接口稳定触发,回归应保留在 motr 协议场景。fix(plan): preserve prepared aggregate parameters (matrixorigin#26042)
fix(plan): infer prepared SUM and AVG parameters (matrixorigin#26534)
fix(plan): preserve prepared aggregate parameters (matrixorigin#26042)
fix(plan): infer prepared SUM and AVG parameters (matrixorigin#26534)
fix(plan): preserve prepared aggregate parameters (matrixorigin#26042)
fix(plan): infer prepared SUM and AVG parameters (matrixorigin#26534)