Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3wQp-0004ri-68 for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Oct 2017 03:51: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 1e3wQo-000503-5U for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Oct 2017 03:51: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 1e3wQ5-0003kf-LQ for pgsql-bugs@postgresql.org; Mon, 16 Oct 2017 03:50:25 +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 1e3wQ2-0000if-ER for pgsql-bugs@postgresql.org; Mon, 16 Oct 2017 03:50:24 +0000 Received: from [192.168.127.1] (port=45665 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 1e3wPx-000GbI-2j; Mon, 16 Oct 2017 03:50:17 +0000 Received: from [127.0.0.1] (port=16180 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1e3wPw-000Glr-AW; Mon, 16 Oct 2017 03:50:16 +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: <87efq3lq93.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: Mon, 16 Oct 2017 04:50:15 +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: >> I propose the attached patch to fix that. It forces the use of >> PlaceHolderVars in subquery pullup, if the parent query has grouping >> sets and HAVING. I'm not 100% sure that's the right approach or a >> misuse of the placeholder system, so comments welcome. I've been testing Heikki's patch with the havingQual condition removed, and I haven't found any issues yet. 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. As far as I can tell, the "x" _does_ become a constant, but then in setrefs, because it's still labelled with a sortgroupref, it gets replaced by a Var again. I don't recall touching any of that in the GS work, because it was already like that for plain GROUP BY. -- 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