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.
Description
Every group produced by
GROUP BYcontains at least one input row, soCOUNT(*) > 0is always true for every emitted group. TheHAVINGpredicatecannot filter the result.
Expected: eliminate the redundant
HAVINGpredicate and generate the sameplan as the query without it.
Actual: the generated plan retains and evaluates the
COUNT(*) > 0filter.How to repeat
Version
Virtuoso Open Source Server 07.20.3240; Virtuoso ODBC Driver 07.20.3243;
Windows x64 client; WSL2 Docker server.