Re: Improper const-evaluation of HAVING with grouping sets and subquery pullup

Heikki Linnakangas <hlinnaka@iki.fi>

From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>, Tom Lane <tgl@sss.pgh.pa.us>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Date: 2017-10-17T07:44:23Z
Lists: pgsql-bugs
Here's another interesting case, without any subqueries:

postgres=# SELECT g as newalias1, g as newalias3
FROM generate_series(1,3) g
GROUP BY newalias1, ROLLUP(newalias3);
  newalias1 | newalias3
-----------+-----------
          1 |         1
          3 |         3
          2 |         2
          2 |         2
          3 |         3
          1 |         1
(6 rows)

Why are there no "summary" rows with NULLs, despite the ROLLUP? If you 
replace one of the g's with (g+0), you get the expected result:

postgres=# SELECT g as newalias1, (g+0) as newalias3
FROM generate_series(1,3) g
GROUP BY newalias1, ROLLUP(newalias3);
  newalias1 | newalias3
-----------+-----------
          1 |         1
          3 |         3
          2 |         2
          2 |
          3 |
          1 |
(6 rows)

- Heikki


Commits

  1. Fix incorrect handling of subquery pullup in the presence of grouping sets.

  2. Make setrefs.c match by ressortgroupref even for plain Vars.

  3. Make the upper part of the planner work by generating and comparing Paths.