Skip to content

[Compatibility]: SUM and AVG reject ENUM and SET numeric aggregation supported by MySQL #28692

Closed

Description

@Ariznawlll

问题描述

MatrixOne 的 SUM/AVG 类型检查拒绝 ENUM 和 SET 列,错误把操作数报告为 VARCHAR。MySQL 在数值聚合上下文中使用 ENUM 的 1-based ordinal 和 SET 的 bitmap 数值,因此直接聚合、DISTINCT 聚合和分组聚合都可执行。

MatrixOne 对同一列显式增加 +0 后能够得到与 MySQL 相同的数值结果,说明存储的 ordinal/bitmap 信息可用,缺口位于直接聚合的类型归一化,而不是数据内容无法表示。

环境

  • MatrixOne 最新 main:7013fbbd6e152ba31da2d3dbba7012ac7f8b8462
  • MatrixOne:本地 launch 2 CN / 1 TN / 1 Log,全新数据目录
  • 对照:MySQL 8.3.0
  • 双方 SQL mode 均含 STRICT_TRANS_TABLES 与 ONLY_FULL_GROUP_BY

最小复现

create table t(
  id int primary key,
  g int,
  e enum('red','green','blue'),
  s set('a','b','c')
);

insert into t values
  (1,1,'red','a'),
  (2,1,'red','a'),
  (3,1,'green','a,b'),
  (4,2,'blue','c'),
  (5,2,null,null);

select sum(e), avg(e), sum(s), avg(s) from t;
select sum(distinct e), avg(distinct e),
       sum(distinct s), avg(distinct s) from t;
select g, sum(e), avg(e), sum(s), avg(s)
from t group by g order by g;

MatrixOne 行为

上述查询在绑定阶段被拒绝:

ERROR 20203 (HY000): invalid argument aggregate function sum, bad value [VARCHAR]
ERROR 20203 (HY000): invalid argument aggregate function avg, bad value [VARCHAR]

直接、DISTINCT 和分组形式均如此,连续执行三轮结果一致。

MySQL 行为

sum(e)  avg(e)  sum(s)  avg(s)
7       1.75    9       2.25

sum(distinct e)  avg(distinct e)  sum(distinct s)  avg(distinct s)
6                2                8                2.6666666666666665

g  sum(e)  avg(e)              sum(s)  avg(s)
1  4       1.3333333333333333  5       1.6666666666666667
2  3       3                   4       4

MatrixOne 数值对照

select sum(e+0), avg(e+0),
       sum(distinct e+0), avg(distinct e+0) from t;
-- 7, 1.7500, 6, 2.0000

select sum(s+0), avg(s+0),
       sum(distinct s+0), avg(distinct s+0) from t;
-- 9, 2.2500, 8, 2.6667

显式数值化后的值与 MySQL 一致。

期望行为

为了兼容 MySQL,SUM/AVG 应在数值聚合上下文中将 ENUM 转为 ordinal、将 SET 转为 bitmap 数值,并对普通、DISTINCT、分组、VIEW/CTAS 使用一致规则;不应要求应用额外写 +0。

初步代码定位

Activity

  1. added this to the MO-202609 milestone on Sep 11, 2026
  2. added
    kind/bug
    on Sep 11, 2026
  3. added theissue type on Sep 11, 2026
  4. self-assigned this
    on Sep 12, 2026
  5. added a commit that references this issue on Sep 21, 2026
    f9d89ab
  6. Ariznawlll commented on Sep 21, 2026

    @Ariznawlll
    CollaboratorAuthor

    Verified on current main 57c280e.\n\nENUM and SET numeric aggregation now follows the expected numeric values. For ENUM 1,2,4 and SET 1,2,1,4, the regression returns ENUM SUM/AVG 6/2.0000 and SET SUM/AVG 8/2.6667. The result passed three MOTR runs.\n\nCoverage: matrixorigin/motr#193,\nsuites/14_issue_regression/t/issue_28765_28694_28692_28222_compatibility.test.\n\nClosing as fixed.

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