Repository navigation
Description
Summary
DATE_ADD and DATE_SUB cannot be executed through a prepared statement when either the date operand or the INTERVAL value is a parameter marker. The same SQL succeeds with literals, and the related TIMESTAMPADD function accepts a parameter marker normally.
This prevents applications from binding ordinary runtime values to DATE_ADD/DATE_SUB even though the interval unit remains a SQL keyword.
Environment
- MatrixOne official
main:99ed717b769e261b842c2f17345bd65865fc1470 - Clean local single-CN build and isolated data directory
- Repeated three times through both MySQL text prepared statements and the MySQL binary prepared-statement protocol
Reproduction
SELECT DATE_ADD('2024-02-28 23:59:59.123456', INTERVAL 1 DAY);
-- 2024-02-29 23:59:59.123456
PREPARE p_date FROM 'SELECT DATE_ADD(?, INTERVAL 1 DAY)';
SET @d = '2024-02-28 23:59:59.123456';
EXECUTE p_date USING @d;
-- ERROR 20203 (HY000): invalid argument date_add/date_sub function need two args, bad value 3
PREPARE p_interval FROM 'SELECT DATE_ADD(''2024-02-28 23:59:59.123456'', INTERVAL ? DAY)';
SET @n = 1;
EXECUTE p_interval USING @n;
-- ERROR 20203 (HY000): invalid argument date_add/date_sub function need two args, bad value 3The same failure occurs for DATE_SUB. Parameterizing both operands fails as well.
Control
PREPARE p_timestampadd FROM
'SELECT TIMESTAMPADD(DAY, ?, ''2024-02-28 23:59:59.123456'')';
SET @n = 1;
EXECUTE p_timestampadd USING @n;
-- 2024-02-29 23:59:59The binary protocol has the same split: DATE_ADD(?, INTERVAL 1 DAY) and DATE_ADD(literal, INTERVAL ? DAY) both fail, while the binary prepared TIMESTAMPADD control succeeds. All outcomes were identical in 3/3 runs.
Expected behavior
Prepared execution should accept parameter markers in value positions, including the first DATE_ADD/DATE_SUB operand and the numeric expression after INTERVAL; the DAY unit remains static SQL syntax. MySQL documents INTERVAL expr unit as expression syntax and permits prepared-statement parameter markers where data values occur.
Preliminary code observation
The SQL is first rewritten from its two surface arguments into the internal three-argument form (date, interval-value, interval-unit). At prepared execution, the binder appears to re-enter the public date_add/date_sub validation and rejects that internal form with the observed “need two args, bad value 3” error. This is a diagnosis hypothesis, not a proposed fix.
Suggested regression coverage
Cover text and binary prepared statements for:
DATE_ADD(?, INTERVAL 1 DAY).DATE_ADD(literal, INTERVAL ? DAY).DATE_SUBequivalents and repeated executions with different values.- A
TIMESTAMPADDprepared-statement control to preserve the distinct supported path.
Activity
XuPeng-SH commentedon Oct 23, 2026
Consolidation: #28135 reports the same prepared-expression arity failure through the
ADDDATE/SUBDATEaliases. Both reports observeinvalid argument date_add/date_sub function need two args, bad value 3after the surface syntax is normalized to the internal three-argument form and revalidated as the public two-argument function. The suspected validation boundary is the same; this does not claim the code-level diagnosis is proven.Keep these alias cases in this issue's regression matrix:
ADDDATE(?, INTERVAL ? DAY)andSUBDATE(?, INTERVAL 1 DAY)through SQL PREPARE and the MySQL binary prepared protocol.DATE_ADD/DATE_SUBcases.The original reproductions and environment details remain in #28135. This issue is the single open tracker for the shared prepared
DATE_ADD/DATE_SUBfamily; no fix is claimed by this consolidation.XuPeng-SH commentedon Oct 23, 2026
Additional historical path from #28240: a prepared
UPDATEthat changes a base column used by a STORED or VIRTUALDATE_ADD/DATE_SUBgenerated column reported the same internalneed two args, bad value 3error after rebinding the normalized expression. Keep this as a regression case alongside the direct prepared SELECT andADDDATE/SUBDATEaliases.Status boundary: merged PR #28932 explicitly says the #28240 behavior was already present on its upstream base. I have not re-run that generated-column scenario on today's main, so this is historical regression coverage, not evidence that the path currently fails. #30194 remains separate: its prepared expression executes and the defect is result-schema/type metadata.
Fix SQL compatibility regressions across aggregates, casts, and prepa…
XuPeng-SH commentedon Nov 22, 2026
QA 交接:DATE_ADD/DATE_SUB 值位置的服务器预编译绑定
#32002 已合入
main,合并 SHAd9a43b3156dd6ee54f14bdd4197071e522efd285,最终 PR heada2b88df5。较早基线与候选对照,日期参数、INTERVAL 数值参数、重复绑定与 NULL 通过;PR 将其作为已有路径的回归控制,未证明是本 PR 首次修复。 上述独立 QA 证据对应较早候选
005ea33b,不是当前合并版的实测。正式评审针对较早 headb1bc02f6,最终 head 的 Iceberg E2E 通过;合并队列记录未显示 Required 已满足。未在当前合并提交复跑,不推定 4.2 或整体 CI 通过。请验 SQL PREPARE 与二进制协议,覆盖 ADDDATE/SUBDATE 别名、重复绑定、预编译 UPDATE 触发的 STORED/VIRTUAL 生成列与 NULL;这些扩展不宣称已测。 转测不等于验收通过,工单保持开放。
Ariznawlll commentedon Nov 23, 2026
结论
通过。在官方
main测试开始时的最新提交c8805c3e2613bcb53f279035fdf2e2337c86a68e上,原始DATE_ADD/DATE_SUB预编译值参数场景及本 Issue 合并跟踪的别名、生成列更新场景均已通过。本次验证 main,不推定 4.2-dev 同样支持。关键证据
git_version()和二进制源码版本均为上述完整 SHA。研发交接的 #32002 合并提交包含在此版本中;该交接指出该路径此前也可能已可工作,不将修复归因于此 PR。DATE_ADD/DATE_SUB、ADDDATE/SUBDATE以及同一预编译句柄重复绑定;跨闰日、0 天和微秒结果符合预期。原始TIMESTAMPADD文本预编译控制正常。DATE_ADD和 VIRTUALDATE_SUB生成列的表,用文本和二进制预编译 UPDATE 修改日期及置 NULL,读取实际生成值与 NULL 传播均正确。TestCalendarIntervalTypedBinding、TestCalendarIntervalPreparedTimeKeepsLegacyNormalizer,各重复 3 次通过;这些测试验证的是绑定控制,并非替代上述真实 SQL 执行。0631f9b50e0bb5ca39d7ffbe1cdfd16720525875,只针对 main。新提交 CI 正在运行,尚不宣称其已通过。按用户要求,回归 PR 提交后先关闭,稍后合入。待解决点
本次验收目标是参数绑定及计算值。个别字面量参数形式和别名在文本协议下返回 Python 字符串,测试按实际日期时间值比较;未据此宣称所有表达式的结果元数据都已验收,也不将其与本 Issue 的参数绑定问题混为一谈。