Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e47WK-00077b-Ev for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Oct 2017 15:41:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e47WJ-00020w-OR for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Oct 2017 15:41:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e47WJ-0001zi-Dp for pgsql-bugs@postgresql.org; Mon, 16 Oct 2017 15:41:35 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e47WG-00027Q-JS for pgsql-bugs@postgresql.org; Mon, 16 Oct 2017 15:41:34 +0000 Received: from [192.168.127.1] (port=21547 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1e47WE-000HKq-Al; Mon, 16 Oct 2017 15:41:30 +0000 Received: from [127.0.0.1] (port=61835 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1e47WD-000Jy0-MR; Mon, 16 Oct 2017 15:41:29 +0000 From: Andrew Gierth To: Tom Lane Cc: Heikki Linnakangas , Pg Bugs Subject: Re: Improper const-evaluation of HAVING with grouping sets and subquery pullup In-Reply-To: <2431.1508166918@sss.pgh.pa.us> (Tom Lane's message of "Mon, 16 Oct 2017 11:15:18 -0400") Message-ID: <871sm3ktl7.fsf@news-spur.riddles.org.uk> References: <7dbdcf5c-b5a6-ef89-4958-da212fe10176@iki.fi> <1197.1507820787@sss.pgh.pa.us> <87efq3lq93.fsf@news-spur.riddles.org.uk> <87a80rli2w.fsf@news-spur.riddles.org.uk> <32319.1508163874@sss.pgh.pa.us> <8760bfku2u.fsf@news-spur.riddles.org.uk> <2431.1508166918@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Mon, 16 Oct 2017 16:41:29 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org >>>>> "Tom" == Tom Lane writes: >> x and y aren't constants, but z is. Tom> OK, but that just means we should put PHV wrapping around only the Tom> grouping-set columns. Well, can we also take advantage of the fact that we know that anything that's not in the grouping-set columns must be in an aggregate argument, and just omit the PHV inside aggregate args? (And even if grouping columns appear inside aggregate args, they are _not_ nulled out there.) Tom> BTW, also need to think about GS expressions, eg Tom> select x+y, sum(z) from (select 1 as x, 2 as y, 3 as z) s Tom> group by grouping sets (x+y); Tom> Not real sure what needs to happen here. That one currently works (note you have to add another grouping set to test it, since the case of exactly one grouping set is reduced to plain GROUP BY) because setrefs fixes up the reference after-the-fact, replacing the outer x+y (or whatever it got munged to) with a Var based on matching the sortgroupref. This currently fails: select (x+y)*1, sum(z) from (select 1 as x, 2 as y, 3 as z) s group by grouping sets (x+y, x); because the logic in setrefs that would normally detect that (x+y) exists in the child tlist doesn't fire because the whole expression was replaced by a constant. With the patch to use PHVs it works, but I admit to some confusion over exactly why. -- Andrew (irc:RhodiumToad) -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs