pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Jeevan Chalke <jeevan.chalke@enterprisedb.com>
To: Atri Sharma <atri.jiit@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: Postgres-Bugs <pgsql-bugs@postgresql.org>
Subject: Re: [HACKERS] GSets: Fix bug involving GROUPING and HAVING together
Date: Tue, 14 Jul 2015 11:53:12 +0100
Message-ID: <87si8rqba3.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <CAM2+6=WG9omG5rFOMAYBweJxmpTaapvVp5pCeMrE6BfpCwr4Og@mail.gmail.com>
References: <CAM2+6=WG9omG5rFOMAYBweJxmpTaapvVp5pCeMrE6BfpCwr4Og@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

>>>>> "Jeevan" == Jeevan Chalke <jeevan.chalke@enterprisedb.com> writes:

 Jeevan> Basically, when we have only one element in GROUING SETS, we
 Jeevan> are assuming it as a simple GROUP BY with one column. Due to
 Jeevan> which we are ending up with this error.

 Jeevan> If we have ROLLUP/CUBE or GROUPING SETS with multiple elements,
 Jeevan> then we are not getting this error.

There's two issues here. One you correctly identified, which is that
contain_agg_clause() should be true for GroupingFuncs too.

The other is that in subquery_planner, the optimization of converting
HAVING clauses to WHERE clauses is suppressed if parse->groupingSets
isn't empty. (It is empty if there's either no group by clause at all,
or if there's exactly one grouping set, which must not be empty, however
derived.) This is costing us some optimizations, especially in the case
of an explicit GROUP BY () clause; I'll look into this.

In the meantime your patch looks OK (and necessary) to me.

 Jeevan> The side effect is that, if we have plain group by clause, then
 Jeevan> too we can use GROUPING in HAVING clause. But I guess it is
 Jeevan> fine.

GROUPING is, per spec, explicitly allowed anywhere you could have an
aggregate call, whether the group by clause is plain or not.

-- 
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 (8+ messages)  latest in thread

Message-ID: <87si8rqba3.fsf@news-spur.riddles.org.uk>
Permalink:  ../87si8rqba3.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87si8rqba3.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, jeevan.chalke@enterprisedb.com, atri.jiit@gmail.com, pgsql-hackers@postgresql.org
  Subject: Re: [HACKERS] GSets: Fix bug involving GROUPING and HAVING together
  In-Reply-To: <87si8rqba3.fsf@news-spur.riddles.org.uk>
  References: <CAM2+6=WG9omG5rFOMAYBweJxmpTaapvVp5pCeMrE6BfpCwr4Og@mail.gmail.com> <87si8rqba3.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