Skip to content

[Bug]: [4.1.6-hotfix] validate and backport grouping-extension CTAS nullability and round-trip fixes #32265

Closed

Description

@ck89119

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Related to closed #26826 (synthesized NULL keys), #26827 (SQL round trip), and #24436. This is a 4.1.6-hotfix validation/backport follow-up. Grouping-extension fixes are being removed from PR #32085 to keep that PR limited to matrixflow #20285's UNION NULL and outer-join CTAS failures.

Branch Name

4.1.6-hotfix

Commit ID

Target base 77052f8d1f9e6833ff5e5b41ae2343b5bcf0d152. Investigation/fix history is retained in unmerged commit 1dd2bf61082bd4740e8069e82ccf44e228b3245e and its parent.

Other Environment Information

Investigation used Go 1.26.4, a matching isolated single-CN MO service and planner/parser tests. The issues linked above have separate main-branch reproduction evidence; this report does not claim a fresh exact-base reproduction of every grouping variant.

Actual Behavior

The release branch still needs a coherent grouping-extension closure:

  1. Missing grouping-set output keys must be nullable without mutating the evaluated input types.
  2. CTAS formats its source into INSERT SQL; empty/duplicate GROUPING SETS and CUBE syntax must survive that round trip.
  3. Rebinding an expanded ROLLUP/CUBE AST must not expand it again from a partial/empty subset. During PR investigation, repeated planning expanded ROLLUP group count 3→5; CUBE rebind lost original keys and produced must appear in the GROUP BY clause.
  4. Real SQL validation exposed correct-looking metadata with missing subtotal rows, so planner metadata tests alone are insufficient.

Expected Behavior

View/CTAS metadata and actual subtotal rows must agree. Parse/format/reparse and repeated planning must preserve original keys, explicit duplicate/empty grouping sets and grouping multiplicities. Ordinary GROUP BY and keys present in every grouping set retain their existing non-null contract.

Steps to Reproduce

CREATE TABLE src(g INT NOT NULL,h INT NOT NULL,v INT NOT NULL);
INSERT INTO src VALUES(1,10,5),(1,20,7),(2,10,9);
SELECT g,h,SUM(v) FROM src GROUP BY g,h WITH ROLLUP;
CREATE TABLE r AS SELECT g,h,SUM(v) s FROM src GROUP BY g,h WITH ROLLUP;
CREATE TABLE c AS SELECT COALESCE(g,-1) g,COALESCE(h,-1) h,SUM(v) s
FROM src GROUP BY CUBE(g,h);
CREATE TABLE s AS SELECT COALESCE(g,-1) g,COALESCE(h,-1) h,SUM(v) s
FROM src GROUP BY GROUPING SETS ((g,h),(g),());

Compare each source SELECT with CTAS rows/schema and explicit INSERT into a nullable pre-created target. Separately parse one AST and plan it three times; require stable grouping count and generated SQL. Preserve explicit duplicate grouping sets rather than globally deduplicating groups.

Additional information

The unmerged implementation/test history contains TestGroupByFormatRoundTrip, TestCreateTableAsSelectGroupingRebind and real SQL controls. Revalidate them on the chosen branch base rather than blindly cherry-picking the larger CTAS/MARK patch. The old hint_cte fixture expects repeated ROLLUP subtotals; if rebinding is repaired, independently verify its ten correct rows before updating that expectation. That fixture change belongs to this follow-up, not the narrowed #20285 PR.

No production replay or production data-loss claim. Keep this work separate from the general function-proof and MARK resource/performance follow-ups.

Activity

  1. added
    kind/bug
    on Nov 5, 2026
  2. added
    severity/s0
    and removed on Nov 5, 2026
  3. added a commit that references this issue on Nov 14, 2026
    34691ae
  4. assigned and unassigned on Nov 14, 2026
  5. slyunnn commented on Nov 18, 2026

    @slyunnn

    Regression and extended verification for #32265 (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 binary reports 52da59083f on all three endpoints.
    • Fix: PR fix(plan): preserve grouping-extension CTAS semantics on 4.1.6-hotfix #32520, merge 34691aecbb58a297d4cf7fdc1e69694126f20f4e, preserves grouping-extension nullability, SQL round trips and repeated planning. PR [4.1.6-hotfix] fix(plan): deduplicate grouping NULL values in DISTINCT #32802 subsequently fixes the related DISTINCT NULL boundary.
    • Isolated 2 CN / 1 TN / 1 Log / Proxy; Proxy 6001, CN1 16001 and CN2 16002 were all reachable and the original and expanded SQL ran on each through the MySQL protocol via PyMySQL. Product BVT ran via JDBC on Proxy. Tests ran serially and do not establish engine-parallel or production performance behavior.

    What Was Covered

    • OK: Original ROLLUP SELECT and CTAS produce the independently expected six rows and nullable grouping keys on all three endpoints; CUBE and duplicate GROUPING SETS return the expected values and multiplicities.
    • OK: Product function/grouping_ctas.sql passes 391/391, including explicit INSERT, CTAS schema and nullable constraints, CUBE, duplicate and empty grouping sets, views, repeated prepared execution, actual versus synthesized NULL and result-boundary checks.
    • OK: TestGroupByFormatRoundTrip and TestGroupingRepeatedPlanning pass, covering parser formatting/reparsing and repeated planning. Each endpoint remains healthy after the SQL checks.
    • Not covered: Production replay, engine-parallel behavior or performance. A large-data regression is not required for the reported parser/planner semantics and row multiplicity defect.

    Findings

    The tested source SELECT, CTAS rows and nullable-key metadata agree; duplicate grouping sets retain their multiplicity.

    MOTR / BVT Coverage

    The existing product BVT and focused parser/planner tests directly cover the reported scenarios, 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 for the tested scope.

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