Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3iG6-0005TR-VL for pgsql-bugs@arkaria.postgresql.org; Sun, 15 Oct 2017 12:43:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e3iG6-0005D5-28 for pgsql-bugs@arkaria.postgresql.org; Sun, 15 Oct 2017 12:43:10 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e3iG4-0005Ce-Cv for pgsql-bugs@postgresql.org; Sun, 15 Oct 2017 12:43:08 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e3iFw-0006e5-PQ for pgsql-bugs@postgresql.org; Sun, 15 Oct 2017 12:43:07 +0000 Received: from [192.168.127.1] (port=30222 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 1e3iFr-000FZh-Hm; Sun, 15 Oct 2017 12:42:55 +0000 Received: from [127.0.0.1] (port=22905 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1e3iFq-000BRv-Qd; Sun, 15 Oct 2017 12:42:54 +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: <1197.1507820787@sss.pgh.pa.us> (Tom Lane's message of "Thu, 12 Oct 2017 11:06:27 -0400") Message-ID: <87lgkclh7t.fsf@news-spur.riddles.org.uk> References: <7dbdcf5c-b5a6-ef89-4958-da212fe10176@iki.fi> <1197.1507820787@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Sun, 15 Oct 2017 13:42:52 +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: Tom> One thing I'm wondering is why only the HAVING clause would be Tom> subject to the problem. I'm a bit surprised that the "x" in the Tom> targetlist didn't become a constant as well. This may be pointing Tom> to some klugery in the GROUPING SETS patch that we could clean up Tom> if we use placeholders for this. This shows that the problem can extend to the targetlist too: select four, x || 'x' from (select four, ten, 'foo'::text as x from tenk1 ) as t group by grouping sets(four, x); four | ?column? ------+---------- 3 | foox 0 | foox 1 | foox 2 | foox | foox (5 rows) What seems to happen in the original case is that the 'foo' constant ends up in the projection of the input to the aggregate node, with a Var in the output. -- 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