Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Related to #32265 and PR #32520. No existing issue specifically covers ENUM/SET actual NULL versus subtotal NULL deduplication.
Branch Name
4.1.6-hotfix
Commit ID
34691aecbb58a297d4cf7fdc1e69694126f20f4e
This is an unresolved defect in the global-DISTINCT scope of 34691aecbb (PR #32520), not a newly introduced regression: the same wrong rows reproduce at v4.1.6-hotfix-20261113 (614fb9d8544ad0a52ce2dce26f3bef15cd96bbb3).
Other Environment Information
- Hardware parameters: 10-core arm64 machine.
- OS type: macOS / Darwin arm64.
- Others: Go 1.26.4; reproduced through SELECT and CTAS readback.
Actual Behavior
When an ENUM or SET source contains an actual NULL and a ROLLUP adds a subtotal NULL, SELECT DISTINCT returns both NULL rows. CTAS persists both rows as well.
The defect occurs with and without ORDER BY, and also with GROUPING SETS ((e), ()). Ordinary GROUP BY deduplicates correctly, and the equivalent INT and VARBINARY ROLLUP controls return only one NULL.
Expected Behavior
DISTINCT must operate on the user-visible result values after all grouping branches are combined. Actual NULL and subtotal NULL have the same selected value and must produce one output row when they are the only selected column.
For the fixture below, the ENUM query must return NULL, a, b (three rows), and CTAS must persist those same three rows.
Steps to Reproduce
drop database if exists qa_enum_rollup;
create database qa_enum_rollup;
use qa_enum_rollup;
create table enum_src(e enum('a','b','c'),v int);
insert into enum_src values('a',1),('b',2),('a',3),(null,4);
select distinct e from enum_src group by e with rollup order by e;
-- Actual: NULL, NULL, a, b
-- Expected: NULL, a, b
create table enum_rollup_ctas as
select distinct e from enum_src group by e with rollup order by e;
select count(*) as total_rows,
count(e) as non_null_rows,
count(*)-count(e) as null_rows
from enum_rollup_ctas;
-- Actual: 4, 2, 2
-- Expected: 3, 2, 1A corresponding SET example also returns and persists two NULL rows:
create table set_src(s set('a','b','c'),v int);
insert into set_src values('a',1),('b',2),('a,b',3),(null,4);
select distinct s from set_src group by s with rollup order by s;
-- Actual: NULL, NULL, a, b, a,b
-- Expected: NULL, a, b, a,bAdditional information
EXPLAIN VERBOSE shows the final DISTINCT rewritten as an aggregate whose Group Key is the internal __grouping_0 transport column. Thus, internal grouping provenance still distinguishes the two rows even though their user-visible selected values are both NULL. Relevant implementation areas are pkg/sql/plan/grouping_stage.go:332-355 and pkg/sql/plan/opt_misc.go:807-827.
This is directly related to the PR's stated invariant that only user result columns participate in DISTINCT; hidden grouping lineage must not change row multiplicity. A regression test needs ENUM and SET cases containing both an actual NULL and a synthesized subtotal NULL, including CTAS readback.
Activity
[4.1.6-hotfix] fix(plan): deduplicate grouping NULL values in DISTINCT (
XuPeng-SH commentedon Nov 17, 2026
QA 交接补充(不代表验收通过)
#32802 已于 2026-11-16 合入 4.1.6-hotfix,merge SHA
52da59083ff60beab943d347c187f568fc5c84aa。本 issue 已由 QA @slyunnn 负责,保留负责人,仅补交接证据。修复在最终 DISTINCT 边界物化 nullable selected keys,仅清除结果 grouping bitmap,不改上游 provenance、已存值和显式 GROUPING()。作者记录 ENUM SELECT/CTAS total/non-NULL/NULL 从 4/2/2 修为 3/2/1,SET 从 5/3/2 修为 4/3/1;早期 CAST 导致的 FLOAT/GEOMETRY 重验证反例已消除。作者 macOS/arm64 完整 plan/function 通过;单 CN grouping_ctas.sql 两轮各 391/391、geometry 763/763、on_duplicate_key 139 通过和 8 个既有 skip。审查在 Linux/amd64、head
b51540a8fe6d44d0c698d69f69766576df7fb439独立运行 focused planner/function tests,含 typed keys、constant/NULL/empty vectors、重复执行及既有 VALUES,未留下未决人工问题。以上为作者/审查记录,本巡检未本地测试。边界:未覆盖 multi-CN、全仓 SCA 或生产规模性能;nullable keys 新增向量复制,不宣称零性能回退。review 时 UT/SCA failed 且步骤记录不完整,不认定 CI 全绿或确定失败原因。请在目标 hotfix 二进制复验 ENUM/SET 实际 NULL 与 subtotal NULL 的 DISTINCT、ROLLUP/GROUPING SETS、ORDER BY、CTAS 回读、显式 GROUPING() 及 FLOAT/GEOMETRY 不被重新验证的回归。
slyunnn commentedon Nov 18, 2026
Regression and extended verification for #32789 (2026-11-18)
Verification Environment
4.1.6-hotfixat latest fetched52da59083ff60beab943d347c187f568fc5c84aa,[4.1.6-hotfix] fix(plan): deduplicate grouping NULL values in DISTINCT (#32802). The running binary reports52da59083fon all three endpoints.52da59083ff60beab943d347c187f568fc5c84aa, materializes nullable DISTINCT keys while preserving explicit grouping lineage.2 CN / 1 TN / 1 Log / Proxytopology. Proxy6001, CN116001, and CN216002were reachable. The original SQL and expanded checks ran through each endpoint using the MySQL protocol via PyMySQL. Product BVT ran through Proxy using JDBC. Tests ran serially; this is not a parallel execution or performance claim.What Was Covered
ENUMandSETactual-NULL/subtotal-NULLDISTINCTreproductions,ROLLUPandGROUPING SETS, and CTAS readback on each endpoint: one visible NULL remains.GROUPING()distinguishes real and synthesized NULLs; storedFLOATandGEOMETRYvalues remain usable without revalidation. The existing grouping CTAS BVT also exercises unordered results, CTAS and additional types:391/391, no failures or skips.TestGroupingDistinctValueKeyspasses, as do health checks on all endpoints.Findings
The original duplicate visible NULLs were not observed. The explicit grouping marker continues to preserve the distinction when selected.
MOTR / BVT Coverage
The product
function/grouping_ctas.sqldirectly covers the original cases and expanded boundaries, so a duplicate MOTR case is unnecessary. This hotfix is outside the currently maintained MOTRmainand4.2-devtargets.Final Conclusion
Fixed on
4.1.6-hotfixat52da59083f.