Fix overeager pushdown of HAVING clauses when grouping sets are used.
authorAndres Freund
Mon, 8 Feb 2016 10:03:31 +0000 (11:03 +0100)
committerAndres Freund
Mon, 8 Feb 2016 10:03:37 +0000 (11:03 +0100)
commit87dbc72a79bbd84aaba3a8c543a093106392da8d
tree6c07594929e161a5b644e2645f72c99c11a79077
parent65f1510a82a2e792b8b0c4ffacdb4e996410d943
Fix overeager pushdown of HAVING clauses when grouping sets are used.

In 61444bfb we started to allow HAVING clauses to be fully pushed down
into WHERE, even when grouping sets are in use. That turns out not to
work correctly, because grouping sets can "produce" NULLs, meaning that
filtering in WHERE and HAVING can have different results, even when no
aggregates or volatile functions are involved.

Instead only allow pushdown of empty grouping sets.

It'd be nice to do better, but the exact mechanics of deciding which
cases are safe are still being debated. It's important to give correct
results till we find a good solution, and such a solution might not be
appropriate for backpatching anyway.

Bug: #13863
Reported-By: 'wrb'
Diagnosed-By: Dean Rasheed
Author: Andrew Gierth
Reviewed-By: Dean Rasheed and Andres Freund
Discussion: 20160113183558[email protected]
Backpatch: 9.5, where grouping sets were introduced
src/backend/optimizer/plan/planner.c
src/test/regress/expected/groupingsets.out
src/test/regress/sql/groupingsets.sql