Repository navigation
Description
Branch Name
main
Commit ID
Other Environment Information
- MatrixOne was built from the commit above and started locally with
etc/launch/launch.toml. - The minimal
BOTHcase was reproduced in three fresh databases. - MySQL comparison version: 8.0.45.
Actual Behavior
TRIM with a row-dependent removal expression and POSITION(... IN ...) work in normal SELECTs and views, but CTAS cannot materialize the same expressions.
CREATE TABLE s(a VARCHAR(8), b VARCHAR(32));
INSERT INTO s VALUES ('ab', 'ababXabab');
SELECT TRIM(BOTH a FROM b) FROM s;
-- X
CREATE VIEW v AS SELECT TRIM(BOTH a FROM b) AS t FROM s;
SELECT t FROM v;
-- X
CREATE TABLE c AS SELECT TRIM(BOTH a FROM b) AS t FROM s;The CTAS statement returns a parser error from the generated internal query:
ERROR 1105 (HY000): You have an error in your SQL syntax ...
syntax error ... near " `s`.`a` from `s`.`b`) as `t` from `s`) as __mo_ctas_source"
The same failure occurs for all three explicit directions:
CREATE TABLE c1 AS SELECT TRIM(BOTH a FROM b) AS t FROM s;
CREATE TABLE c2 AS SELECT TRIM(LEADING a FROM b) AS t FROM s;
CREATE TABLE c3 AS SELECT TRIM(TRAILING a FROM b) AS t FROM s;Plain TRIM(b) CTAS succeeds, and the connection remains usable after each error.
The same CTAS reconstruction problem affects POSITION with either a column or a literal search value:
CREATE TABLE p1 AS SELECT POSITION(a IN b) AS p FROM s;
CREATE TABLE p2 AS SELECT POSITION('ab' IN b) AS p FROM s;Both fail because the internal SELECT is regenerated as the unparseable POSITION(a, b) form. Equivalent LOCATE(a,b) and INSTR(b,a) CTAS statements succeed and materialize 3.
Expected Behavior
CTAS should preserve the valid TRIM([BOTH|LEADING|TRAILING] remstr FROM str) syntax and materialize the query results:
BOTH -> X
LEADING -> Xabab
TRAILING -> ababX
MySQL 8.0.45 successfully creates all three CTAS tables with those values.
It also materializes POSITION(a IN b) as 3.
Steps to Reproduce
DROP DATABASE IF EXISTS trim_ctas_repro;
CREATE DATABASE trim_ctas_repro;
USE trim_ctas_repro;
CREATE TABLE s(a VARCHAR(8), b VARCHAR(32));
INSERT INTO s VALUES ('ab', 'ababXabab');
CREATE TABLE c1 AS SELECT TRIM(BOTH a FROM b) AS t FROM s;
CREATE TABLE c2 AS SELECT TRIM(LEADING a FROM b) AS t FROM s;
CREATE TABLE c3 AS SELECT TRIM(TRAILING a FROM b) AS t FROM s;
CREATE TABLE p1 AS SELECT POSITION(a IN b) AS p FROM s;Additional Information
The function value implementations are not the failing component. The error text shows that CTAS's generated SELECT does not reconstruct special function syntax into a parseable form. The original parser/AST formatter has special handling for TRIM ... FROM ... and POSITION ... IN ... in pkg/sql/parsers/tree/expr.go, while the CTAS path regenerates SQL from the bound plan expression. As controls, SUBSTRING(b FROM 3 FOR 4), EXTRACT(YEAR_MONTH FROM d), and CONVERT(b USING utf8mb4) all survive the same CTAS path.
Activity
[-][Bug]: CTAS cannot materialize TRIM with an explicit removal expression[/-][+][Bug]: CTAS cannot reconstruct TRIM and POSITION special syntax[/+]fix: preserve TRIM and POSITION syntax in CTAS (#29359)
Ariznawlll commentedon Sep 27, 2026
测试版本
main5be6cd90b501da225be591ffffe6000bf01f515e原问题验证
在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交
36c3fbce2c99410d83bd084d1eb9f09044284012。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
确认修复提交
36c3fbce2c99410d83bd084d1eb9f09044284012是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。回归测试
已加入 MOTR PR #204 的
issue_29323_29325_29327_29328_29329_29330_29331_sql_contracts.test,MOTR 提交2b4462f2;本地基线比对连续 3 次通过。测试证据
5be6cd90b501da225be591ffffe6000bf01f515e测试结论
测试通过。