Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
The old QUOTE feature-request issues #22943 and #22999 were closed after the function was implemented. #25054 concerns an internal SQL-quoting helper, not the SQL QUOTE() function.
Branch Name
main
Commit ID
e7bb0572235ec4bac81eb098eb0ad8900f0065ab
Other Environment Information
- Deployment: local standalone MatrixOne, 1 CN / 1 TN / 1 Log service
- Client: MySQL text protocol
- Reference: MySQL 8.3.0
Actual Behavior
QUOTE() does not implement the MySQL result contract for NULL, apostrophes, or newlines:
SELECT QUOTE(NULL);
-- MatrixOne: SQL NULL
-- MySQL: string "NULL"
SELECT HEX(QUOTE(CONCAT('a', CHAR(39), 'b')));
-- MatrixOne: 276127276227 ('a''b')
-- MySQL: 27615C276227 ('a\'b')
SELECT HEX(QUOTE(CONCAT('a', CHAR(10), 'b')));
-- MatrixOne: 27615C6E6227 ('a\nb')
-- MySQL: 27610A6227 (the newline is retained)Backslash, NUL, and Ctrl+Z controls do match MySQL. The discrepancies above occur for both constant expressions and table-column values and were reproduced three times.
Expected Behavior
QUOTE(NULL) must return the non-NULL string NULL. For non-NULL values, output bytes must match MySQL's documented SQL-literal escaping: apostrophes are preceded by a backslash, while ordinary newlines are retained.
MySQL reference: https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_quote
Steps to Reproduce
SELECT QUOTE(NULL), HEX(QUOTE(NULL));
SELECT QUOTE(CONCAT('a', CHAR(39), 'b')),
HEX(QUOTE(CONCAT('a', CHAR(39), 'b')));
SELECT QUOTE(CONCAT('a', CHAR(10), 'b')),
HEX(QUOTE(CONCAT('a', CHAR(10), 'b')));Additional information
The implementation currently marks SQL NULL as a null result before calling the quoting writer. For apostrophes, writeQuotedBytes writes two quote bytes; for newline, it writes backslash plus n. Those choices explain the observed output exactly.
Activity
XuPeng-SH commentedon Sep 8, 2026
修复已提交到 PR #28443: #28443
根因已确认:后续 writer 重构偏离了早期 MySQL 兼容实现,导致 QUOTE(NULL) 被当作 SQL NULL、单引号使用双引号形式、LF/CR/TAB 被错误转义;同时长度计算与 writer 的规则存在漂移风险。
本次统一了字节级长度计算和 writer:NULL 输入返回非 NULL 字符串
NULL;仅转义单引号、反斜杠、NUL、Ctrl-Z;保留其他字节,因此兼容二进制和非法 UTF-8。外层 select-list 的掩码行仍保持 SQL NULL。验证:函数包完整 UT 通过;QUOTE/string-domain race 定向测试通过;独立服务黑盒覆盖 NULL、单引号、反斜杠、LF、CR、TAB、NUL、Ctrl-Z;func_string_quote BVT 24/24 连续两次通过;molint、golangci-lint、license-eye(5205 文件,invalid 0)通过。
XuPeng-SH commentedon Sep 8, 2026
PR #28443 follow-up commit 10d63e1 已补齐 review 发现的返回类型边界问题。
Root cause:QUOTE(NULL) 的运行时结果是四字节字符串 NULL,但原 quoteReturnType 对已知零宽 VARCHAR/VARBINARY 只给出 2 字节上界;CTAS 等消费者会因此得到低估的列元数据。
修复:
证据:目标包 UT、go vet/molint、golangci-lint(0 issues)均通过;固定二进制执行 func_string_quote BVT 30/30 通过。运行时 QUOTE 实现未改,性能路径不变。PR 合入后再由 CI 做完整门禁。
fix(function): align QUOTE with MySQL (#28443)
Ariznawlll commentedon Sep 9, 2026
已在包含 #28443 的最新
main(f0c31cd4b830be32442cf329e0a3fb08aa9c16c3)确认QUOTE()的结果契约已与 MySQL 8.3 对齐:QUOTE(NULL)返回非空字符串NULL,继续参与CONCAT时得到[NULL];\\n、\\r、\\t;VARCHAR/VARBINARY列、SQLPREPARE/EXECUTE、CTAS 中一致;VARCHAR(32)经QUOTE()的 CTAS 宽度为VARCHAR(66),与 MySQL 一致;额外验证了二进制输入:MatrixOne 保留
VARBINARY结果域并能按字节处理无效 UTF-8;这是 #28443 明确实现的扩展行为,不影响本 issue 所列 MySQL 兼容性修复。fix(function): align QUOTE with MySQL (matrixorigin#28443)
fix(function): align QUOTE with MySQL (matrixorigin#28443)
fix(function): align QUOTE with MySQL (matrixorigin#28443)