Skip to content

Redundant HAVING COUNT(*) > 0 predicate is retained #1450

Description

@chen8908917

Description

Every group produced by GROUP BY contains at least one input row, so
COUNT(*) > 0 is always true for every emitted group. The HAVING predicate
cannot filter the result.

Expected: eliminate the redundant HAVING predicate and generate the same
plan as the query without it.

Actual: the generated plan retains and evaluates the COUNT(*) > 0 filter.

How to repeat

CREATE TABLE rift_redundant_having (id INTEGER PRIMARY KEY, grp INTEGER);
INSERT INTO rift_redundant_having VALUES (1, 10);
INSERT INTO rift_redundant_having VALUES (2, 10);
INSERT INTO rift_redundant_having VALUES (3, 20);

EXPLAIN ('SELECT grp, COUNT(*) FROM rift_redundant_having GROUP BY grp');
EXPLAIN ('SELECT grp, COUNT(*) FROM rift_redundant_having GROUP BY grp HAVING COUNT(*) > 0');

Version

Virtuoso Open Source Server 07.20.3240; Virtuoso ODBC Driver 07.20.3243;
Windows x64 client; WSL2 Docker server.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions