Skip to content

[Bug]: prepared SUM and AVG lose ENUM and SET numeric domains #29313

Closed

Description

@Ariznawlll

Summary

SUM and AVG correctly consume the ordinal/bitmap numeric domains of base-table ENUM and SET columns in an ordinary query, but the same SQL is rejected when compiled through SQL PREPARE. The prepared plan exposes both operands as VARCHAR and loses the numeric aggregate normalization added by #29177.

No parameter marker is required to trigger the problem. MIN/MAX remain executable through the same prepared path, and explicit e + 0 / s + 0 numeric controls work.

Version

MatrixOne main: 95b1d2bfd9d756d08320569858080cb16f230fff
Build date: 2026-09-24
Deployment: fresh local launch cluster

Reproduction

CREATE DATABASE repro_enum_set_prepare;
USE repro_enum_set_prepare;
CREATE TABLE t(
  g INT,
  e ENUM('z','a','m'),
  s SET('z','a','m')
);
INSERT INTO t VALUES
  (1,'z','z'),
  (1,'a','a'),
  (1,'m','z,a'),
  (1,NULL,NULL),
  (2,'a','m');

-- ordinary query: 8, 2.0000, 10, 2.5000
SELECT SUM(e),AVG(e),SUM(s),AVG(s) FROM t;

-- rejected during PREPARE even though the SQL has no marker
PREPARE p0 FROM 'SELECT SUM(e),AVG(e),SUM(s),AVG(s) FROM t';

-- also rejected with an unrelated filter marker
PREPARE pe FROM 'SELECT SUM(e),AVG(e) FROM t WHERE g=?';
PREPARE ps FROM 'SELECT SUM(s),AVG(s) FROM t WHERE g=?';

-- prepared controls succeed
PREPARE pm FROM 'SELECT MIN(e),MAX(e),MIN(s),MAX(s) FROM t WHERE g=?';
PREPARE pe_ok FROM 'SELECT SUM(e+0),AVG(e+0) FROM t WHERE g=?';
PREPARE ps_ok FROM 'SELECT SUM(s+0),AVG(s+0) FROM t WHERE g=?';

The ENUM and SET PREPARE statements each reproduce identically in three consecutive attempts.

Actual behavior

invalid argument aggregate function sum, bad value [VARCHAR]

Expected behavior

Preparing a query must preserve the same ENUM ordinal and SET bitmap aggregate domains as ordinary compilation. SUM(e), AVG(e), SUM(s), and AVG(s) should prepare and return the same values as their direct-query controls.

Scope / code analysis

Duplicate / compatibility-contract check

Activity

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

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地单机(1 CN / 1 TN / 1 LogService)
    • 测试日期:2026-09-27

    原问题验证

    在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交 5d80e0bc0348c31325c9a54488561c567076abb0。

    Happy Path 覆盖

    1. prepared SUM/AVG 正确保留 ENUM 与 SET 的数值域,并与直接聚合一致。

    Unhappy Path 覆盖

    1. 覆盖 NULL、跨组值和连续两次 prepared 执行,未出现 TEXT 绑定或结果漂移。

    白盒验证

    确认修复提交 5d80e0bc0348c31325c9a54488561c567076abb0 是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。

    回归测试

    已加入 MOTR PR #204 的 issue_29311_29313_29314_29320_prepared_domains.test,MOTR 提交 2b4462f2;本地基线比对连续 3 次通过。

    测试证据

    测试结论

    测试通过。

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