Skip to content

Incorrect NULL row in streaming MV after GROUP BY #27451

Closed

Description

@iany0

Describe the bug

A materialized view with GROUP BY over an empty input incorrectly returns one NULL row, while its identical defining query returns zero rows.

AggGroupBySimplifyRule appears to remove the final grouping key, changing grouped aggregation into scalar aggregation and violating empty-input semantics.

Error message/log

No SQL error is reported. `SELECT * FROM m16` returns one `NULL` row, while the identical defining query returns zero rows.

To Reproduce

Run the following SQL:

CREATE MATERIALIZED VIEW m6 AS
SELECT min(x) AS col_0
FROM (VALUES (1)) AS v(x);
FLUSH;

CREATE MATERIALIZED VIEW m16 AS
SELECT col_0 FROM m6
WHERE false
GROUP BY col_0;
FLUSH;

SELECT * FROM m16;

SELECT col_0 FROM m6
WHERE false
GROUP BY col_0;

Expected behavior

Both queries should return zero rows, because WHERE false produces an empty input and grouped aggregation should produce no groups.

Instead, the materialized view incorrectly contains one NULL row.

How did you deploy RisingWave?

Official Linux binary

The version of RisingWave

Reproduced on RisingWave 3.1.0, commit 45baf64.

Additional context

EXPLAIN (TRACE) shows that AggGroupBySimplifyRule removes the final grouping key, converting the query into a StreamSimpleAgg with internal_last_seen_value.

This appears to change the empty-input semantics from zero rows for grouped aggregation to one row for scalar aggregation, causing the unexpected NULL row.

The issue disappears when using GROUP BY GROUPING SETS ((col_0)), which avoids this simplification.

Activity

  1. added this to the release-3.1 milestone on Oct 10, 2026
  2. yashaggarwal85d commented on Oct 21, 2026

    @yashaggarwal85d
    Contributor

    Hi! I'd like to work on this.

    Planned fix: in AggGroupBySimplifyRule, keep at least one group key column when
    the minimized key would be empty (and skip the rule for an empty group key). Other
    redundant columns are still turned into internal_last_seen_value as before.

    I'll add planner tests and an e2e streaming test based on the reproducer. I'll open
    a PR shortly; feedback on the approach is welcome.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugType: Bug. Only for issues.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions