Skip to content

[Bug]: CTAS with aggregate functions infers schema differently from MySQL #24430

Closed

Description

@Ariznawlll

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

CREATE TABLE ... AS SELECT with aggregate functions infers result schema differently from MySQL.

MO:

CREATE TABLE `agg01` (
  `avgcol` double DEFAULT NULL,
  `sumcol` decimal(38,0) DEFAULT NULL,
  `countcol` bigint NOT NULL,
  `maxcol` double NOT NULL,
  `mincol` double NOT NULL
)

MySQL:

CREATE TABLE `agg01` (
  `avgCol` decimal(14,4) DEFAULT NULL,
  `sumcol` decimal(32,0) DEFAULT NULL,
  `countCol` bigint NOT NULL DEFAULT '0',
  `maxCol` double,
  `minCol` double
)

Expected Behavior

The CTAS result schema should be consistent with MySQL, including column type, nullability, default value, and expression alias casing.

Steps to Reproduce

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;
select * from agg01;

Additional information

Split from #14792 after re-verification.

Activity

  1. Ariznawlll commented on May 18, 2026

    @Ariznawlll
    CollaboratorAuthor

    Closing in favor of summary tracker #24436. This issue was split from #14792 during re-verification and is now tracked centrally in #24436.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions