Skip to content

[Bug]: tracker for remaining CTAS schema inconsistencies with MySQL #24436

Open

Description

@Ariznawlll

Consolidated tracking scope: CTAS inferred target type and persisted value consistency

Original reproductions and discussions remain available in the source issues below. Administrative consolidation is not a claim that a defect is fixed. Each input family and execution path retains independent acceptance.

Included reports

  • #28127 — [Bug]: CTAS persists fractional TIME values in an unscaled TIME column
  • #30942 — [Bug]: decimal literal 0.1 infers DECIMAL(1,1) (no integer digit) — CTAS column rejects values >= 1

Acceptance checklist

  • For the fractional TIME reproduction, the persisted CTAS value and its declared fractional-second precision must agree; compare direct INSERT SELECT into TIME/TIME(0) and explicitly scaled TIME targets.
  • Retain the pure-fraction decimal-literal case: infer the MySQL-compatible precision/scale for 0.1 (DECIMAL(2,1) in the report), verify SHOW CREATE/column metadata, and test a subsequent representable 1.5 insert.
  • Preserve valid 1.5/1.50 and explicit DECIMAL controls, NULL behavior, and every existing CTAS tracker row as separate acceptance cases. These reports do not establish one immediate implementation root cause.

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

20346ca

Other Environment Information

- MO version: 8.0.30-MatrixOne-v
- MySQL version: 8.0.45
- Verify date: 2026-05-18

Actual Behavior

After re-verifying #14792, several CREATE TABLE ... AS SELECT schema behaviors are still inconsistent with MySQL.

Already verified fixed:

  • scene 5
  • scene 7

Known MO-specific behavior not split into this tracker:

  • TEXT/BLOB DEFAULT NULL printing difference in show create table

Still inconsistent with MySQL:

  • aggregate functions in CTAS: avg/sum/count/max/min
  • bitwise aggregate functions in CTAS: bit_and/bit_or/bit_xor
  • plain DECIMAL column definition after CTAS
  • concat_ws result column definition after CTAS
  • date_format result column definition after CTAS
  • AUTO_INCREMENT attribute is retained after CTAS

Expected Behavior

The CTAS target schema should be consistent with MySQL for the remaining scenarios above.

Steps to Reproduce

1. aggregate functions in CTAS
drop table if exists agg01;
drop table if exists math01;
create table math01 (col1 int default 0, col2 decimal, col3 float, col4 double not null);
insert into math01 values (1, 7382.4324, 432453.3243, -2930.321323);
insert into math01 values (-100, 3283.32324, 328932.0, -9392032);
insert into math01 values (22813, -241, 932342.4324, -0.1);
insert into math01 values (null, null, null, 10);
create table agg01 as
select avg(col1) as avgCol, sum(col2) as sumcol, count(col3) as countCol, max(col4) as maxCol, min(col4) as minCol
from math01;
show create table agg01;
desc agg01;

2. bitwise aggregate functions in CTAS
drop table if exists bit02;
drop table if exists bit01;
create table bit01 (col1 char(1), col2 int);
insert into bit01 values ('a',111),('a',110),('a',100),('a',000),('b',001),('b',011);
create table bit02 as
select bit_and(col2), bit_or(col2), bit_xor(col2)
from bit01;
show create table bit02;
desc bit02;

3. plain DECIMAL column after CTAS
drop table if exists dst01;
drop table if exists src01;
create table src01 (col7 decimal);
insert into src01 values (3232.000), (0.0001), (null);
create table dst01 as select * from src01;
show create table dst01;
desc dst01;

4. concat_ws result column after CTAS
drop table if exists string02;
drop table if exists string01;
create table string01 (col1 varchar(40), col2 char, col3 text default null);
insert into string01 values ('  database system', 'a', 'x');
insert into string01 values (' string function ', '1', 'y');
insert into string01 values ('test create table as select', '0', null);
create table string02 as
select concat_ws(',', col1, 'abcde') as newCol
from string01;
show create table string02;
desc string02;

5. date_format result column after CTAS
drop table if exists time02;
drop table if exists time01;
create table time01(col1 date, col2 datetime, col3 timestamp, col4 time);
insert into time01 values ('2020-10-11', '2023-11-11 10:00:01', '1997-01-13 12:12:12.000', '12:12:12');
insert into time01 values ('1919-12-01', '1990-10-10 01:01:01', '2001-12-12 01:01:01.000', '10:59:59');
insert into time01 values (null, null, null, null);
create table time02 as
select date_format(col2, '%W %M %Y') from time01;
show create table time02;
desc time02;

6. AUTO_INCREMENT attribute retained after CTAS
drop table if exists table02;
drop table if exists table01;
create table table01 (
    id int auto_increment primary key,
    col1 varchar(255) not null
);
insert into table01 (col1) values ('Value2'), ('Value3');
create table table02 as select * from table01;
show create table table02;
desc table02;

Additional information

This issue is a tracker that summarizes the remaining incompatible CTAS schema behaviors from #14792.

Activity

  1. added this to the MO-202607 milestone on Jul 2, 2026
  2. added theissue type on Jul 2, 2026
  3. Ariznawlll commented on Jul 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional Model 11 metadata coverage on latest main 51656deb6 still reproduces CTAS/view schema inference gaps against MySQL 8.0.45.

    Repro:

    drop database if exists mysql_compat_model11b;
    create database mysql_compat_model11b;
    use mysql_compat_model11b;
    
    create table t_base (
      id int not null auto_increment comment 'pk id',
      c_nn int not null default 5,
      c_v varchar(12) default 'abc',
      c_dec decimal(8,3) default 1.230,
      primary key(id)
    ) auto_increment = 100;
    insert into t_base(c_nn, c_v, c_dec) values (7, 'x', 2.500);
    
    create table t_ctas as
    select
      id,
      c_nn + 1 as plus_i,
      c_dec * 2 as dec_expr,
      concat(c_v, '-s') as concat_expr,
      if(c_nn > 0, 'yes', 0) as if_mixed,
      cast('2024-01-02 03:04:05' as datetime) as dt_expr
    from t_base;
    
    desc t_ctas;
    select column_name, column_type, is_nullable, column_default, extra
    from information_schema.columns
    where table_schema = database() and table_name = 't_ctas'
    order by ordinal_position;

    Observed differences:

    • MySQL: id int NOT NULL DEFAULT '0'; MO: keeps id int NOT NULL AUTO_INCREMENT.
    • MySQL: dec_expr decimal(9,3); MO: DECIMAL(38,3).
    • MySQL: concat_expr varchar(14) and if_mixed varchar(3); MO: VARCHAR(65535) for both.
    • MySQL: dt_expr datetime NULL DEFAULT NULL; MO: DATETIME(0) NOT NULL.
    • MO information_schema.columns also exposes __mo_fake_pk_col for the CTAS table.

    This is the same family as the existing CTAS schema tracker, adding mixed arithmetic/string/datetime expression coverage.

  4. Ariznawlll commented on Jul 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional Model 11 CTAS metadata coverage on latest main 51656deb6:

    create table t_ctas_src (
      g int,
      i int,
      d decimal(8,2),
      v varchar(12),
      ts datetime
    );
    insert into t_ctas_src values
      (1,10,1.25,'aa','2024-01-01 00:00:00'),
      (1,20,2.50,'bbb','2024-01-02 00:00:00'),
      (2,null,null,null,null);
    
    create table t_ctas_agg as
    select g, count(i) as cnt_i, sum(d) as sum_d, avg(i) as avg_i, group_concat(v order by v) as gc
    from t_ctas_src group by g;
    
    desc t_ctas_agg;
    
    create table t_ctas_window as
    select g, i, row_number() over(partition by g order by i) as rn, sum(i) over(partition by g) as win_sum
    from t_ctas_src;
    
    desc t_ctas_window;
    
    create table t_ctas_union as
    select 1 as x, 'a' as y
    union all
    select 2.5 as x, repeat('b', 20) as y;
    
    desc t_ctas_union;

    Observed MySQL vs MO schema differences:

    • count(i): MySQL bigint NOT NULL DEFAULT 0; MO BIGINT NOT NULL DEFAULT NULL.
    • sum(decimal(8,2)): MySQL decimal(30,2); MO DECIMAL(38,2).
    • avg(int): MySQL decimal(14,4); MO DOUBLE.
    • row_number(): MySQL bigint unsigned; MO BIGINT.
    • window sum(int): MySQL decimal(32,0); MO BIGINT.
    • union x: MySQL decimal(2,1); MO DECIMAL(20,1).
    • union y: MySQL varchar(20) NULL; MO VARCHAR(65535) NOT NULL.

    A separate value-materialization bug was filed for CTAS + GROUP_CONCAT with NULL values: #25389.

  5. Ariznawlll commented on Jul 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional CTAS/derived UNION coverage on latest main 49842fb04 shows the schema inference gap can become a materialization failure when later UNION branches contain NULL.

    Repro:

    drop database if exists compat_view_ctas_probe;
    create database compat_view_ctas_probe;
    use compat_view_ctas_probe;
    
    create table ctas_union as
    select * from (
      select cast(1 as signed) as a, 'x' as s
      union all
      select null, repeat('y',5)
    ) u;
    
    desc ctas_union;
    select a,s,length(s) as s_len from ctas_union order by s;

    MySQL 8.0.45 succeeds and creates nullable columns:

    a bigint YES
    s varchar(5) YES
    
    1    x      1
    NULL yyyyy  5
    

    MatrixOne latest main 49842fb04 fails during CTAS materialization:

    ERROR 3819 (HY000): constraint violation: Column 'a' cannot be null
    

    This appears to be the same CTAS UNION schema-inference family already tracked here, but with a value-path failure instead of only metadata mismatch.

  6. Ariznawlll commented on Jul 6, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional View/CTAS deep-path coverage on latest main 781161fab against MySQL 8.0.45 confirms this tracker still covers the remaining CTAS metadata/materialization gaps.

    Newly checked shapes:

    • CTAS over UNION ALL where a later branch contains NULL: MySQL creates nullable columns; MO still fails during materialization with ERROR 3819: constraint violation: Column 's' cannot be null.
    • CTAS over aggregates: values match, but metadata differs for COUNT, SUM, AVG precision/defaults (SUM(int) MySQL decimal(32,0), MO BIGINT; AVG(decimal) MySQL decimal(14,6), MO DECIMAL(38,8)).
    • CTAS over window functions: values match, but metadata differs for ROW_NUMBER() unsignedness/defaults and window aggregate precision.
    • CTAS over IFNULL / COALESCE / CASE / CONCAT / NULLIF: values match, but nullability and varchar length inference still differ from MySQL.

    No new issue opened; these are the same CTAS schema inference/materialization family tracked here.

  7. added
    kind/bug
    on Jul 17, 2026
  8. Ariznawlll commented on Jul 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充 CTAS 默认值场景,使用两列最小表复现:

    create table source_t (
      id int primary key,
      qty int not null default 7
    );
    insert into source_t(id) values (1);
    create table ctas_base as select id, qty from source_t;
    desc ctas_base;
    insert into ctas_base(id) values (2);

    三次执行中,DESC ctas_base 均显示 qty INT(32) NOT NULL DEFAULT 7,
    但最后一条插入均返回:

    ERROR 20301 (HY000): invalid input: invalid default value for column 'qty'
    

    显式给出 qty 时可写入;手工创建的同定义表省略 qty 可正确写入 7。
    MySQL 8.0.45 的 CTAS 目标显示默认值 7,省略 qty 的插入成功并写入 7。

    这属于本单跟踪的 CTAS schema/default 使用路径差异,补充最小可复现用例,不新增同类 CTAS 单。

  9. Ariznawlll commented on Aug 20, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 592ad2190a90e063e3877059f4018427a10a4998 上复核了该追踪项,并确认同一 AVG 返回类型规则也覆盖窗口查询和 JDBC 结果集元数据。

    在 TINYINT/SMALLINT/INT/BIGINT/DECIMAL(20,6)/DOUBLE 输入上,普通聚合和 AVG(...) OVER (ORDER BY id ROWS UNBOUNDED PRECEDING) 连续 3 轮一致:

    • MO TINYINT/SMALLINT/INT 的 AVG:DOUBLE(精度 53);MySQL:DECIMAL(scale 4)。
    • MO BIGINT:DECIMAL(38,4);MySQL:DECIMAL(23,4)。
    • MO DECIMAL(20,6):DECIMAL(38,12);MySQL:DECIMAL(24,10)。
    • DOUBLE 输入两端均为 DOUBLE。

    例如整型值 1,2,4 的窗口 AVG 第三行,MO 返回 2.3333333333333335,MySQL 返回 2.3333。在 16,387 行滑动窗口上,后续再对窗口 AVG 求和时,MO 和 MySQL 因逐行结果尺度不同产生 819245.772383 与 819245.7728 的差异。

    CREATE TABLE ... AS SELECT AVG(i) OVER (...) 仍复现:MO 目标列为 DOUBLE,MySQL 为 DECIMAL(14,4);普通 AVG(i) CTAS 也是同样结果。因此这属于本 tracker 已列的 aggregate/window CTAS 类型推导兼容性范围,不新增同类 Issue。

  10. daviszhen commented on Aug 22, 2026

    @daviszhen
    Contributor

    • 结论:Issue #24436 仍未解决,且当前没有关联 PR。原先拆出的 #24429~#24434 被关闭只是“合并回此 tracker”,不是已修复证据。Issue #24436
    (#24436)

    仍需处理的核心问题:

    1. CTAS 聚合类型推导
      AVG/SUM/COUNT/MAX/MIN 的精度、scale、默认值、NULL 属性与 MySQL 不一致;尤其 AVG 普通聚合和窗口聚合仍返回不同类型。最新复测
      ([Bug]: tracker for remaining CTAS schema inconsistencies with MySQL #24436 (comment))

    2. BIT_AND/OR/XOR 的 CTAS 类型推导
      需要统一结果类型、无符号属性、默认值和 NULL 属性。BIT_XOR(...) OVER (...) 还存在单独的语法/执行问题,应另开 PR 处理。[Bug]: BIT_XOR aggregate is rejected with an OVER clause #27342
      ([Bug]: BIT_XOR aggregate is rejected with an OVER clause #27342)

    3. DECIMAL 类型
      CREATE TABLE ... AS SELECT decimal_col 仍可能扩大 precision/scale,与 MySQL 不一致。

    4. 字符串函数类型
      CONCAT_WS、CONCAT、IFNULL、COALESCE、CASE、NULLIF 的结果长度和 NULL 属性仍偏宽或不一致,常见为 MatrixOne 返回 VARCHAR(65535)。

    5. 时间函数类型
      DATE_FORMAT 的结果列类型、长度和 NULL 属性需要对齐 MySQL;显式 DATETIME 表达式的 NULL/scale 也有差异。

    6. CTAS 属性和默认值

    7. UNION 类型合并
      UNION 分支的 DECIMAL/VARCHAR 宽度、NULL 属性与 MySQL 不一致;后续分支出现 NULL 时,CTAS 仍可能在物化阶段报 Column ... cannot be null。复测
      ([Bug]: tracker for remaining CTAS schema inconsistencies with MySQL #24436 (comment))

    8. CTAS 元数据暴露
      information_schema.columns 中可能出现 MatrixOne 内部的 __mo_fake_pk_col,需要确认是否应对用户隐藏。

    已经单独解决、无需重复处理的相关问题:

    建议将剩余工作拆成一个“CTAS 类型/属性推导统一”主 PR;视图元数据刷新、BIT_XOR OVER、排名函数 JDBC 无符号元数据分别处理为独立 PR(#26227
    (https://github.com/matrixorigin/matrixone/issues/26227)、#27342 (https://github.com/matrixorigin/matrixone/issues/27342)、#27343
    (https://github.com/matrixorigin/matrixone/issues/27343))。

  11. daviszhen commented on Aug 30, 2026

    @daviszhen
    Contributor

    截至 2026-08-30,基于最新 main e8187087b6 和本地新构建的 mo-service 重跑原始/最小 SQL 后,状态更新如下。

    本轮新确认已解决:

    • 聚合 CTAS 默认值:fix(plan): align non-null aggregate CTAS defaults #27865 已合并。COUNT 为 BIGINT NOT NULL DEFAULT 0,BIT_AND/BIT_OR/BIT_XOR 为 BIGINT UNSIGNED NOT NULL DEFAULT 0,MAX/MIN 保持 nullable。
    • 普通来源列默认值:重跑 qty INT NOT NULL DEFAULT 7 最小用例,CTAS 后省略 qty 的 INSERT 已成功并写入 7,旧的 invalid default value 不再复现。
    • UNION 后续分支产生 NULL 的物化失败:原 3819 Column ... cannot be null 用例已可成功创表并写入 NULL。但 UNION common type 元数据仍未对齐,见下文。
    • 构造的 IFNULL/COALESCE/CASE/NULLIF CTAS 用例已不再推导为 VARCHAR(65535);当前分别得到有界的 VARCHAR(12) / VARCHAR(3)。这说明旧 comment 中的公共超宽问题已被后续控制流类型推导修复;新的特定表达式差异应使用具体 SQL 单独确认。

    本轮已提交:

    • DATE_FORMAT CTAS 元数据:fix(plan): align DATE_FORMAT CTAS metadata #27870。字面量 format 按 MySQL format_length 规则推导长度,保持可空,并保留表达式列名中带引号且大小写敏感的 format。原用例现为 varchar(134) DEFAULT NULL,已补单测和 BVT;待 review/CI/合并。

    仍需处理,按建议优先级排序:

    1. AVG/SUM 普通与窗口聚合规则:返回类型、precision/scale 和实际值截断语义仍与 MySQL 不同,并影响 SELECT、window、CTAS 和 JDBC。这是影响最大也最需谨慎设计的一项,不应做 CTAS-only 修补。
    2. DECIMAL 未显式指定 precision:MO 当前使用 DECIMAL(38,0),MySQL 为 DECIMAL(10,0)。这涉及 parser/DDL 全局语义,需要先评估存储和兼容影响。
    3. UNION common type 元数据:NULL 物化已修复,但 VARCHAR/DECIMAL 的宽度、precision 和 nullability 仍可与 MySQL 不同。当前复测中 MO 为 VARCHAR(65535) NOT NULL,MySQL 为 VARCHAR(5) NULL。
    4. CONCAT/CONCAT_WS 结果域:与开放 PR fix(plan): make binary string result domains lossless #27841 重叠。该 PR 当前仍是 draft、REVIEW_REQUIRED 且 branch behind,建议等其更新/合并后再跑本 tracker 用例,避免重复实现。

    不再列为 remaining 的已解决项仍包括:CTAS AUTO_INCREMENT (#27475)、__mo_fake_pk_col 隐藏 (#27015)、显式 DATETIME CTAS (#26349)、BIT_XOR(...) OVER (...) (#27342)、#25389、#26825、#26826、#26828。

  12. 25 remaining items

  13. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充:动态长度 LPAD / RPAD / REPEAT 的 LONGTEXT 结果在 CTAS 中无法物化

    在固定本地 MatrixOne runtime commit 2ce4e58af6f03b943ee288ffad81012766cf830a 与 MySQL 8.0.46 对照。当前 origin/main 为 944b721d1b3705cdb51d1e26f1a04611a08c8401,相关 func_unary.go、list_builtIn.go 和 string_result_domain.go 在两者间无变化。

    CREATE TABLE src(s VARCHAR(1), n INT, p VARCHAR(1));
    INSERT INTO src VALUES ('a',100000,'x');
    
    SELECT LENGTH(LPAD(s,n,p)), LENGTH(RPAD(s,n,p)), LENGTH(REPEAT(s,n))
    FROM src;

    直接查询和 View 都在两端返回三个长度为 100000 的结果。View 的列类型为 MO TEXT、MySQL LONGTEXT。

    但以下三条 CTAS 在 MO 上各自都返回:

    ERROR 1406 (22001): Can't cast column from TEXT type to TEXT type because of one or more values in that column. Src length 100000 is larger than Dest length 65535
    
    CREATE TABLE ctas_lpad AS SELECT LPAD(s,n,p) v FROM src;
    CREATE TABLE ctas_rpad AS SELECT RPAD(s,n,p) v FROM src;
    CREATE TABLE ctas_repeat AS SELECT REPEAT(s,n) v FROM src;

    MySQL 8.0.46 三条均成功,列类型为 LONGTEXT,物化后长度均为 100000。MO 失败的 CTAS 不留下目标表;View 查询仍能读取完整 100000 字符。

    因此这里不只是 TEXT/LONGTEXT 元数据差异:动态长度表达式合法地产生超过 65535 字符的值,但 CTAS 将其按 65535 长度的 TEXT 目标物化而拒绝。该结果域/物化交叉属于本 CTAS schema tracker,不另开重复 issue。

  14. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充同一 CTAS schema/materialization 问题的边界与 Prepared 复现(MatrixOne commit 2ce4e58af6f03b943ee288ffad81012766cf830a、MySQL 8.0.46):

    SET @s='x', @n=65536, @p='a';
    SELECT CHAR_LENGTH(LPAD(@s,@n,@p)), CHAR_LENGTH(RPAD(@s,@n,@p)), CHAR_LENGTH(REPEAT(@s,@n));
    PREPARE q FROM 'CREATE TABLE lp AS SELECT LPAD(?, ?, ?) AS v'; EXECUTE q USING @s,@n,@p;
    PREPARE q FROM 'CREATE TABLE rp AS SELECT RPAD(?, ?, ?) AS v'; EXECUTE q USING @s,@n,@p;
    PREPARE q FROM 'CREATE TABLE rep AS SELECT REPEAT(?, ?) AS v'; EXECUTE q USING @s,@n;

    两端的标量长度均为 65,536;MySQL 三个 prepared CTAS 均成功并生成 LONGTEXT。MatrixOne 三个 CTAS 均在物化时以 Src length 65536 is larger than Dest length 65535 报错。边界控制:65,535 字符的同类 MatrixOne CTAS 成功,65,536 字符失败。与已有动态长度 100,000 字符复现是同一问题,不另开 issue。

    SPACE(65536) 的函数级拒绝已单独记录在 #30186,这里不重复提报。

  15. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充:SPACE() 常量表达式的 CTAS 列宽

    在固定 MatrixOne runtime commit 2ce4e58af6f03b943ee288ffad81012766cf830a 上,下面三条 CTAS 分别重复创建 3 次,information_schema.columns.column_type 均为 varchar(65535),但实际值长度均为 3:

    CREATE TABLE t AS SELECT SPACE(3) AS s;
    CREATE TABLE t AS SELECT SPACE(1 + 2) AS s;
    CREATE TABLE t AS SELECT SPACE(CAST(3 AS SIGNED)) AS s;

    动态列参数 SPACE(n) 推导为 varchar(65535) 是保守宽度;常量参数则不同。MySQL 8.0.46 的 Item_func_space::resolve_type() 会在参数可常量求值时调用 set_data_type_string(count),所以 SPACE(3) 的表达式结果宽度为 3(参见 MySQL 8.0.46 实现)。本次没有可用的 MySQL runtime,故此处 MySQL 预期来自官方实现,待 live MySQL 再核对。

    这是 CTAS 的结果列元数据差异,不是函数值错误;与 #30186 的大结果长度限制相关但不同。请在处理 SPACE 大结果时一并考虑常量宽度推导,避免所有常量结果都退化为宽类型。归入本 tracker,不另开重复 issue。

  16. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充一组 ENUM/SET 与条件函数的 CTAS schema 交叉。MatrixOne 本地 runtime build 2ce4e58af6f03b943ee288ffad81012766cf830a(8.0.30-MatrixOne-v1.3.0)与 MySQL 8.0.45 对照,三次重建 CTAS 的元数据结果一致:\n\nsql\nCREATE TABLE src(id INT, e ENUM('red','blue'), s SET('a','b'));\nINSERT INTO src VALUES (1,'red','a,b'),(2,'blue','b'),(3,NULL,NULL);\nCREATE TABLE out_types AS\nSELECT e AS src_e, COALESCE(e,e) AS co_e, IFNULL(e,e) AS ifnull_e,\n IF(id=1,e,e) AS if_e, CASE WHEN id=1 THEN e ELSE e END AS case_e,\n COALESCE(s,s) AS co_s\nFROM src;\nSELECT column_name,data_type,column_type\nFROM information_schema.columns\nWHERE table_name='out_types' ORDER BY ordinal_position;\n\n\nMySQL 推导 co_e/ifnull_e/if_e/case_e 为 VARCHAR(4),co_s 为 VARCHAR(3);MO 将这些条件函数结果列均固化为 VARCHAR(65535)。源 ENUM 列在两端均保留 ENUM('red','blue')。实际值 red/blue、a,b/b 及 NULL 行一致;差异仅在 CTAS 结果元数据。该用例补充了现有条件函数 CTAS 类型推导记录中的 ENUM/SET 输入分支。

  17. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充:FROM_BASE64() 的 CTAS 结果列类型

    在 MatrixOne 本地单机 runtime 8.0.30-MatrixOne-v1.3.0(source commit 2ce4e58af6f03b943ee288ffad81012766cf830a)与隔离 MySQL 8.0.45 上,使用含 NULL、有效 Base64 文本和空串的 VARCHAR(8) 源列,各自新建 3 张目标表重复验证:

    CREATE TABLE src(v VARCHAR(8) NULL);
    INSERT INTO src VALUES (NULL), ('Zm9v'), ('');
    CREATE TABLE ct_to AS SELECT TO_BASE64(v) AS value FROM src;
    CREATE TABLE ct_from AS SELECT FROM_BASE64(v) AS value FROM src;

    三轮中,源值及两种函数的物化结果都一致,NULL 也被保留。TO_BASE64(v) 的 CTAS 列类型两端相同(VARCHAR(44) NULL);FROM_BASE64(v) 则为 MySQL VARBINARY(24) NULL、MO LONGBLOB NULL。这是 CTAS 结果类型推导差异,不是本次观察到的字节值错误;补充到现有 CTAS schema tracker,不另开重复 issue。

  18. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充:日期/时间提取函数交叉 CTAS 的结果类型

    MatrixOne 本地 runtime 8.0.30-MatrixOne-v1.3.0(source commit 2ce4e58af6f03b943ee288ffad81012766cf830a)与隔离 MySQL 8.0.45 对照。以 DATE 和 DATETIME(6) 源列物化下列函数,各自连续创建 3 张新 CTAS 表;每轮结果类型稳定,所有函数值相同:

    CREATE TABLE out_t AS
    SELECT DAYOFWEEK(d), WEEKDAY(d), YEAR(d), QUARTER(d), MONTH(d),
           DAYOFMONTH(d), DAYOFYEAR(d), WEEK(d,3), WEEKOFYEAR(d), YEARWEEK(d,3),
           HOUR(ts), MINUTE(ts), SECOND(ts), MICROSECOND(ts),
           DATEDIFF(d,'2024-01-01'), TIMESTAMPDIFF(DAY,'2024-01-01',d),
           TO_DAYS(d), TO_SECONDS(ts), TIME_TO_SEC(TIME(ts)), UNIX_TIMESTAMP(ts)
    FROM src;

    以下列型差异在 3 张目标表上都一致(省略的列型两端相同):

    表达式 MySQL CTAS MO CTAS
    DAYOFWEEK, WEEKDAY, YEAR, WEEKOFYEAR, YEARWEEK, DATEDIFF, TO_DAYS INT BIGINT
    QUARTER, MONTH, DAYOFMONTH, HOUR, MINUTE, SECOND, TIME_TO_SEC INT TINYINT UNSIGNED 或 BIGINT(见函数)
    UNIX_TIMESTAMP(DATETIME(6)) DECIMAL(17,6) DECIMAL(38,6)

    两端的物化值均相同,例如 2024-12-31 23:59:58.123456 得到相同的周、年日、时间字段及 1735660798.123456 Unix 时间值。这是函数结果类型经 CTAS 持久化后的 metadata 差异,不是本次观察到的值错误;补充在现有 CTAS schema tracker 中,不另开 issue。

  19. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充:精确整数 SUM() 的 CTAS 返回类型

    在现有“聚合函数 CTAS”范围内,进一步对照了整数类型族及大值求和。环境为 MatrixOne 本地服务 8.0.30-MatrixOne-v1.3.0(服务源码 commit 2ce4e58af6f03b943ee288ffad81012766cf830a)与隔离 MySQL 8.0.45。

    源表分别包含 TINYINT、SMALLINT、MEDIUMINT、INT、BIGINT、BIGINT UNSIGNED,输入为 1, 2, 3, NULL。在两端各建立 3 组 CTAS 输出表后,information_schema.columns.column_type 每轮都稳定为:

    聚合表达式 MySQL 8.0.45 MatrixOne
    SUM(TINYINT) DECIMAL(25,0) BIGINT
    SUM(SMALLINT) DECIMAL(27,0) BIGINT
    SUM(MEDIUMINT) DECIMAL(30,0) BIGINT
    SUM(INT) DECIMAL(32,0) BIGINT
    SUM(BIGINT) DECIMAL(41,0) DECIMAL(38,0)
    SUM(BIGINT UNSIGNED) DECIMAL(42,0) DECIMAL(38,0)

    值控制未发现差异:普通数据上六种 SUM 均返回 6;两行 BIGINT 最大值相加,两端均返回 18446744073709551614;两行 BIGINT UNSIGNED 最大值相加,两端均返回 36893488147419103230。SUM(i) + CAST('0.000000000000000001' AS DECIMAL(20,18)) 的值也一致。当前证据指向精确整数聚合的结果类型/CTAS 元数据不一致,不是本组已观察到的求和值错误。

    MySQL 8.0 文档说明 SUM() 对 exact-value 输入(整数或 DECIMAL)返回 DECIMAL:Aggregate Function Descriptions。兼容性契约的聚合元数据章节目前只记录 GROUP_CONCAT 的明确类型例外,没有登记整数 SUM 的上述差异;因此把证据补到本 CTAS 汇总 issue,不另开重复 issue。本轮未新增测试文件。

  20. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充:COUNT(DISTINCT) CTAS 列的可空性

    在 MySQL 8.0.45 与 MatrixOne 本地服务 commit 2ce4e58af6f03b943ee288ffad81012766cf830a 上,将二进制列控制与 _ci 值差异分开检查。对同一组含重复值及 NULL 的输入,分别创建 3 张 CTAS 输出表:

    CREATE TABLE out_n AS
    SELECT COUNT(DISTINCT a,s_bin) AS n FROM src;
    SELECT column_type,is_nullable
    FROM information_schema.columns
    WHERE table_name='out_n' AND column_name='n';

    三轮中,表达式的值在两端都是 4,列类型也都是 BIGINT;但 MySQL is_nullable='NO',MO is_nullable='YES'。该列源自 COUNT(DISTINCT ...),空集仍返回 0,不会返回 NULL。这个可空性差异属于 #24436 已覆盖的聚合函数 CTAS 元数据范围;另一个 _ci 去重值差异已补至 #25096。本轮未新建 issue 或测试文件。

  21. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    新增 CTAS 案例:LEAST/GREATEST 对非空输入的可空性推导

    环境: MatrixOne 8.0.30-MatrixOne-v1.3.0(服务源码 commit 2ce4e58af6f03b943ee288ffad81012766cf830a),对照 MySQL 8.0.45。

    CREATE TABLE src(x DECIMAL(10,2) NOT NULL, y DECIMAL(8,4) NOT NULL);
    INSERT INTO src VALUES (1.00, 2.0000);
    
    CREATE TABLE out_t AS
    SELECT GREATEST(x, y) AS g, LEAST(x, y) AS l
    FROM src;
    SHOW CREATE TABLE out_t;
    INSERT INTO out_t VALUES (NULL, NULL);

    观察到的值: 两端 GREATEST=2.0000、LEAST=1.0000。

    CTAS 结构与后续写入: 三次独立重建均一致:

    列 MySQL 8.0.45 MatrixOne
    g / l DECIMAL(12,4) NOT NULL DEFAULT '0.0000' DECIMAL(12,4) DEFAULT NULL
    向结果列写入 NULL ERROR 1048: Column 'g' cannot be null 写入成功,g IS NULL、l IS NULL 均为 1

    直接查询的列协议元数据同样显示 MySQL 有 NOT_NULL,MO 无此标志。结果值本身一致;差异在函数结果可空性如何传入 CTAS,并进一步改变目标表允许写入的数据。

    这与 #26830 已修复的“函数可能由非 NULL 输入产生 NULL,却错误标记为 NOT NULL”方向相反。本例的输入列显式为 NOT NULL DECIMAL;服务源码 function.DeduceNotNullable 对 GREATEST/LEAST 当前无条件保守返回 nullable(runtime source)。作为现有 CTAS schema 推导差异的具体案例补入本 tracker;未新增独立 issue 或测试文件。

  22. Ariznawlll commented on Oct 21, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充同一 CTAS / set operation 类型推导问题的二进制边界。两支输入都是 VARBINARY(8),没有混合类型;MO 的 UNION ALL / INTERSECT ALL 结果经 CTAS 却变成 LONGBLOB。这不只影响元数据:目标表随后接受 9 字节值,而源表和 MySQL 目标表都拒绝。

    CREATE TABLE a(b VARBINARY(8));
    CREATE TABLE b(b VARBINARY(8));
    INSERT INTO a VALUES (X'00FF'), (X'FF00');
    INSERT INTO b VALUES (X'00FF');
    
    CREATE TABLE c_plain AS SELECT b FROM a;
    CREATE TABLE c_union AS SELECT b FROM a UNION ALL SELECT b FROM b;
    CREATE TABLE c_intersect AS SELECT b FROM a INTERSECT ALL SELECT b FROM b;
    
    SELECT table_name, column_type
    FROM information_schema.columns
    WHERE table_schema = DATABASE()
      AND table_name IN ('a', 'c_plain', 'c_union', 'c_intersect')
    ORDER BY table_name;
    
    INSERT INTO a VALUES (X'001122334455667788');
    INSERT INTO c_union VALUES (X'001122334455667788');
    表 MO 3a1e42b430 隔离 MySQL 8.3.0
    a, c_plain VARBINARY(8) VARBINARY(8)
    c_union, c_intersect LONGBLOB VARBINARY(8)

    a 的 9 字节写入两端都拒绝(MO 报 20101 Can't cast,MySQL 报 1406 Data too long)。c_union 的 9 字节写入 MySQL 同样拒绝,MO 则成功,随后 HEX(b) 能读出完整 001122334455667788。原有 00FF / FF00 值和 INTERSECT ALL 的交集值两端一致。对每端 3 个全新数据库重复,54 项结构、值、边界和错误后可用性检查全部得到上述结果;不是脏数据或缓存滞后。

    白盒线索:pkg/sql/plan/query_builder.go 的 set-operation 共同类型分支仅在部分 grouping 条件下保留同型 BINARY/VARBINARY 的宽度,否则将目标类型提升为 BLOB(约 4830–4853 行)。本例与本 tracker 已记录的 UNION/CTAS 类型推导属于同一类,因此补充在这里,不另开重复 issue。

  23. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    Two more CTAS type-inference rows measured on current main (3ad9adbb4c, macOS arm64) that are not yet listed in this tracker.

    create table ct1 as select 1 a, 1.5 b, 'x' c, now() d, cast(1 as unsigned) e;
    desc ct1;

    Measured (MO) vs MySQL 8:

    CTAS expression MO column type MySQL 8 note
    1 bigint int integer literal widened
    1.5 decimal(2,1) decimal(2,1) ✅
    'x' varchar(1) varchar(1) ✅
    now() timestamp datetime changes storage semantics
    cast(1 as unsigned) bigint unsigned bigint unsigned ✅

    now() → timestamp is the one worth prioritising: TIMESTAMP carries timezone-conversion semantics (and a conversion at read/write time) that DATETIME does not, so a table built with CTAS silently gets a column whose values shift with time_zone, while the same statement on MySQL produces a DATETIME. On the 1 → bigint row the effect is only storage/range width, but it also changes what information_schema.columns reports for downstream tooling that infers types from a CTAS.

    Reproduction is fully deterministic (no data dependency); both rows reproduce in a fresh database.

  24. Ariznawlll commented on Oct 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。本 issue 已跟踪的 COUNT(DISTINCT ...) 可空元数据差异,还会通过 Python SDK 的 Arrow 查询与建表传递成目标列约束差异;本次没有观察到聚合结果值错误。

    关键证据

    • 版本:main@c6683bd2f531dcaa80e153c0924dac619c49dc9d,同提交构建的隔离双 CN;MySQL 8.0.45 对照。3 个新建库、两个 CN 分别验证。

    • 数据:src(id INT PRIMARY KEY,x INT,y INT),行 (1,1,2),(2,NULL,3),(3,1,2),(4,NULL,NULL)。查询:

      SELECT COUNT(*) AS c_star, COUNT(DISTINCT x) AS c_dist,
             COUNT(DISTINCT x,y) AS c_multi, MAX(x) AS mx
      FROM src;

      两端结果均为 (4,1,1,1),但 MO 协议元数据将 c_dist/c_multi 标为可 NULL,MySQL 标为非 NULL;COUNT(*) 和 MAX 对照的非空标记一致。空集和全 NULL 输入的实际 COUNT 仍为 0,结果值对齐。

    • 同一查询经 client.analytics.query(...).to_arrow() 获取默认 Arrow schema,再 upload_arrow(..., create=True) 建表:MO 目标 c_dist/c_multi 均变成可 NULL,插入 c_dist=NULL 6/6 成功。显式指定两个 Arrow 字段非空后,同样建表和写入对照 6/6 正确拒绝,原始 (4,1,1,1) 保留;源表不变,连接可用,暂存文件清理。

    • 同查询的 CTAS 对照:MO 3/3 为可 NULL 并接受后续 NULL,MySQL 3/3 为非 NULL 并拒绝。该现象扩展了本 issue 先前的 COUNT DISTINCT CTAS 范围;新增的是协议元数据经 SDK Arrow 物化后的可观察影响,不是另报一个数据错误。

    • SDK Arrow schema 推导 使用协议非空标记;该标记在混合聚合计划中的具体丢失环节仍待定位。完整记录 sdk_agg8_count_metadata.json、sdk_agg8_count_impact.json。

    待解决点

    • 核对 COUNT DISTINCT 在单独、多列及混合聚合时的结果元数据、CTAS 和 SDK Arrow 建表约束;回归需包含空集/全 NULL、明确非空 schema 对照及后续 NULL 写入,不能只检查原始聚合值。
  25. XuPeng-SH commented on Nov 29, 2026

    @XuPeng-SH
    Contributor

    Consolidated #31158 into this CTAS inferred-type tracking scope.

    Additional acceptance evidence retained:

    • CREATE TABLE ct1 AS SELECT 1 AS a and CREATE TABLE ct3 AS SELECT 1 + 1 AS a infer BIGINT in MatrixOne, while MySQL 8.0.45 infers INT for both.
    • Direct source-column copying remains a control: CREATE TABLE src(id INT); CREATE TABLE ct6 AS SELECT id FROM src preserves INT.
    • Preserve real BIGINT columns and expressions as a negative control; the fix must not narrow every integer result indiscriminately.

    Administrative consolidation only. The existing unresolved CTAS metadata failures remain open; this is not a fix or QA-verification claim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions