Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZExqZ-0003DC-QJ for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Jul 2015 10:53:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZExqZ-0004Bn-8F for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Jul 2015 10:53:59 +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) (envelope-from ) id 1ZExpw-0002o2-8R; Tue, 14 Jul 2015 10:53:20 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZExpt-0007kF-FB; Tue, 14 Jul 2015 10:53:19 +0000 Received: from localhost ([127.0.0.1]:47029 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.84 (FreeBSD)) (envelope-from ) id 1ZExpo-00028x-MZ; Tue, 14 Jul 2015 10:53:12 +0000 From: Andrew Gierth To: Jeevan Chalke , Atri Sharma Cc: PostgreSQL Hackers , Postgres-Bugs Subject: Re: [HACKERS] GSets: Fix bug involving GROUPING and HAVING together In-Reply-To: (Jeevan Chalke's message of "Tue, 14 Jul 2015 14:51:09 +0530") Message-ID: <87si8rqba3.fsf@news-spur.riddles.org.uk> References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix) Date: Tue, 14 Jul 2015 11:53:12 +0100 MIME-Version: 1.0 Content-Type: text/plain X-Pg-Spam-Score: -3.3 (---) 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 >>>>> "Jeevan" == Jeevan Chalke 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