pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Improper const-evaluation of HAVING with grouping sets and subquery pullup
Date: Mon, 16 Oct 2017 16:41:29 +0100
Message-ID: <871sm3ktl7.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <2431.1508166918@sss.pgh.pa.us>
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>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> 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



view thread (21+ messages)  latest in thread

Message-ID: <871sm3ktl7.fsf@news-spur.riddles.org.uk>
Permalink:  ../871sm3ktl7.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/871sm3ktl7.fsf@news-spur.riddles.org.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andrew@tao11.riddles.org.uk, tgl@sss.pgh.pa.us, hlinnaka@iki.fi
  Subject: Re: Improper const-evaluation of HAVING with grouping sets and subquery pullup
  In-Reply-To: <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> <871sm3ktl7.fsf@news-spur.riddles.org.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox