Skip to content

[Bug]: ENUM/SET ROLLUP DISTINCT keeps actual and subtotal NULLs as separate rows on 4.1.6-hotfix #32789

Closed

Description

@ck89119

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, 1

A 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,b

Additional 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

  1. added
    kind/bug
    on Nov 16, 2026
  2. added
    severity/s0
    and removed on Nov 16, 2026
  3. added a commit that references this issue on Nov 16, 2026
    52da590
  4. assigned and unassigned on Nov 17, 2026
  5. XuPeng-SH commented on Nov 17, 2026

    @XuPeng-SH
    Contributor

    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 不被重新验证的回归。

  6. slyunnn commented on Nov 18, 2026

    @slyunnn

    Regression and extended verification for #32789 (2026-11-18)

    Verification Environment

    • MatrixOne 4.1.6-hotfix at latest fetched 52da59083ff60beab943d347c187f568fc5c84aa, [4.1.6-hotfix] fix(plan): deduplicate grouping NULL values in DISTINCT (#32802). The running binary reports 52da59083f on all three endpoints.
    • Fix: PR [4.1.6-hotfix] fix(plan): deduplicate grouping NULL values in DISTINCT #32802, merge 52da59083ff60beab943d347c187f568fc5c84aa, materializes nullable DISTINCT keys while preserving explicit grouping lineage.
    • Isolated 2 CN / 1 TN / 1 Log / Proxy topology. Proxy 6001, CN1 16001, and CN2 16002 were 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

    • OK: Original ENUM and SET actual-NULL/subtotal-NULL DISTINCT reproductions, ROLLUP and GROUPING SETS, and CTAS readback on each endpoint: one visible NULL remains.
    • OK: Explicit GROUPING() distinguishes real and synthesized NULLs; stored FLOAT and GEOMETRY values remain usable without revalidation. The existing grouping CTAS BVT also exercises unordered results, CTAS and additional types: 391/391, no failures or skips.
    • OK: Existing TestGroupingDistinctValueKeys passes, as do health checks on all endpoints.
    • Not covered: Production-scale performance or engine-parallel execution; the issue is about result-key semantics and does not require a large-data regression to establish correctness.

    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.sql directly covers the original cases and expanded boundaries, so a duplicate MOTR case is unnecessary. This hotfix is outside the currently maintained MOTR main and 4.2-dev targets.

    Final Conclusion

    Fixed on 4.1.6-hotfix at 52da59083f.

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions