Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Searched open and closed LAST_DAY reports. #25306 tracks zero/invalid-date behavior, not valid-result types. #28493 is the separate MAKEDATE type issue. #24436 is a broad CTAS tracker whose listed cases do not include LAST_DAY. No dedicated report for this function's return-type failure was found.
Branch Name
main
Commit ID
79fa30e10c0b298567eb073cdfd88bdc91ab09b9
Other Environment Information
- Debian Linux x86_64; Go 1.26.4; CPU build from the exact commit.
- Test-owned two-CN standalone launch after graceful restart.
- Real SQL frontend with PyMySQL; independent MySQL 8.0.44 reference.
- Discovered during latest-main black-box QA; no claim that a recent commit introduced this longstanding signature.
Actual Behavior
LAST_DAY computes the correct calendar value but exposes VARCHAR rather than DATE, including when its input is already DATE:
SELECT LAST_DAY('2024-02-29'),
LAST_DAY(CAST('2024-02-29' AS DATE));MatrixOne advertises both result columns as MySQL protocol type 253 (VARCHAR), display length 262140, and Python receives strings. MySQL 8.0.44 advertises type 10 (DATE), display length 10, and returns date values.
This is observable in SQL independently of client decoding: CTAS stores the output as VARCHAR(65535) on MatrixOne, versus DATE on MySQL. Client metadata and materialized schema therefore lose the temporal contract. The same result-type discrepancy was reproduced for leap-day, ordinary February, year-end, and new-year inputs.
Expected Behavior
LAST_DAY returns DATE for a valid character, DATE, or DATETIME input. CTAS, View metadata, and text/binary prepared output should preserve that DATE contract rather than materializing a large character column. Invalid-date/NULL handling should retain its separately defined behavior.
Steps to Reproduce
DROP DATABASE IF EXISTS qa_lastday_type;
CREATE DATABASE qa_lastday_type;
USE qa_lastday_type;
SELECT LAST_DAY('2024-02-29'),
LAST_DAY(CAST('2024-02-29' AS DATE));
-- Values agree, but MatrixOne sends VARCHAR metadata instead of DATE.
CREATE TABLE materialized AS
SELECT LAST_DAY('2024-02-29') AS d;
SELECT column_name,data_type,column_type
FROM information_schema.columns
WHERE table_schema='qa_lastday_type' AND table_name='materialized';
-- MatrixOne: d, varchar, VARCHAR(65535)
-- MySQL: d, date, date
SELECT d FROM materialized;
-- Both represent 2024-02-29, so the mismatch is the actual SQL type.
DROP DATABASE qa_lastday_type;Additional information
White-box root cause: the LAST_DAY registration in pkg/sql/plan/function/list_builtIn.go has only VARCHAR/CHAR argument overloads and both retType callbacks return types.T_varchar. The existing LastDay execution function produces a string vector. fixedTypeMatch routes native DATE input through the character implementation as well. CTAS faithfully persists this declared type, so its schema builder/client parser is not the owner of the defect.
Suggested priority: P2 compatibility and persistent-schema issue. Restore the temporal result at the function signature/execution owner; do not fix individual clients or add CTAS-only casts. Acceptance should assert exact values and DATE metadata/schema for valid character/DATE/DATETIME inputs, leap/year boundaries, NULL, direct SQL, SQL/binary PREPARE, CTAS, and View consumers.
Activity
[-][Compatibility]: LAST_DAY returns VARCHAR and CTAS persists VARCHAR(65535) instead of DATE[/-][+][Bug]: LAST_DAY returns VARCHAR and CTAS persists VARCHAR(65535) instead of DATE[/+]fix(sql): preserve prepared numeric and temporal contracts (#29556)
Ariznawlll commentedon Oct 2, 2026
测试版本
maind50a2d475a406829f67127fef7b2ad4abc1c1d3dmo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE原问题验证
按 issue 原始语义在上述 commit 重新执行并重复 3 次。CTAS 从目标表达式推导出的列类型为 DATE,结果值与源查询一致。
Happy Path 覆盖
覆盖 DATE literal、列、prepared 参数和后续 DESCRIBE。
Unhappy Path 覆盖
覆盖 NULL、invalid date 与空输入 CTAS;不退化为 VARCHAR/DATETIME。
白盒验证
关联修复 #29556 已进入当前
main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。回归测试
suites/14_issue_regression/t/issue_recent_sql_semantics.test714/714条语句通过。测试证据
d50a2d475a406829f67127fef7b2ad4abc1c1d3d14_issue_regression中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。测试结论
测试通过。
Ariznawlll commentedon Oct 8, 2026
在当前 main
bab4b3286a0dd5683a9b291763817722233e586c上补充了 LAST_DAY 的值、元数据及持久化消费者覆盖。结果:
DATE(0),不再是VARCHAR(65535);data_type=date, column_type=DATE(0);ld DATE AS (LAST_DAY(dt))能正确写入和随 UPDATE 重算,NULL 输入保持 NULL;WHERE ld='2024-02-29'使用Index Table Scan和prefix_eq;真实 MySQL binary prepared statement 另外连续执行 3 轮:
ColumnTypes都报告DatabaseTypeName=DATE、ScanType=sql.NullTime;2024-02-10扫描为2024-02-29;Gotime.Time(2024-12-31 23:59:59)扫描为2024-12-31;sql.NullTime;2025-01-01每轮都恢复为2025-01-31。直接结果、binary protocol metadata、CTAS、View、generated column 及索引消费路径均保持 DATE 合同。