Repository navigation
Description
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
- [Compatibility]: SUM and AVG reject ENUM and SET numeric aggregation supported by MySQL #28692 established and fix(plan): preserve ENUM and SET identity for ordering and aggregates #29177 implemented the direct-query numeric contract for ENUM/SET
SUMandAVG. - Ordinary, CTE, derived-table
LIMIT, andDISTINCTcontrols on this commit retain the correct numeric values. - SQL PREPARE alone changes the aggregate input to
[VARCHAR], including a statement containing no parameter marker. MIN/MAXprepared controls still work, narrowing the defect to numeric aggregate type/provenance preservation during prepared-plan construction.
Duplicate / compatibility-contract check
- [Compatibility]: SUM and AVG reject ENUM and SET numeric aggregation supported by MySQL #28692 is the closed direct-query compatibility issue fixed by fix(plan): preserve ENUM and SET identity for ordering and aggregates #29177; this report covers the still-broken prepared path on the latest main.
- [Bug]: Prepared SUM and AVG reject parameter markers as TEXT #26019 concerns parameter markers passed as
SUM(?)/AVG(?); here the operands are typed table columns and the failure occurs even without?. - No open or closed issue or fix PR was found for prepared ENUM/SET column aggregation after fix(plan): preserve ENUM and SET identity for ordering and aggregates #29177.
mysql-compatibility-contract/README.mdcontains no ENUM/SET aggregate or prepared-plan exemption.
Activity
fix: preserve prepared table-function domains through consumers and C…
Ariznawlll commentedon Sep 27, 2026
测试版本
main5be6cd90b501da225be591ffffe6000bf01f515e原问题验证
在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交
5d80e0bc0348c31325c9a54488561c567076abb0。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
确认修复提交
5d80e0bc0348c31325c9a54488561c567076abb0是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。回归测试
已加入 MOTR PR #204 的
issue_29311_29313_29314_29320_prepared_domains.test,MOTR 提交2b4462f2;本地基线比对连续 3 次通过。测试证据
5be6cd90b501da225be591ffffe6000bf01f515e测试结论
测试通过。