Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aKQew-0007Vm-KL for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Jan 2016 13:12:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aKQew-0006ep-0e for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Jan 2016 13:12:50 +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 1aKQeJ-0005y2-6u for pgsql-bugs@postgresql.org; Sat, 16 Jan 2016 13:12:11 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aKQeG-00032k-AS for pgsql-bugs@postgresql.org; Sat, 16 Jan 2016 13:12:10 +0000 Received: by mail.anarazel.de (Postfix, from userid 108) id BC1AD860004; Sat, 16 Jan 2016 14:12:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mail X-Spam-Level: X-Spam-Status: No, score=-5.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from anarazel.de (p54BEB56E.dip0.t-ipconnect.de [84.190.181.110]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 9F8F6860002; Sat, 16 Jan 2016 14:12:03 +0100 (CET) Received: by anarazel.de (Postfix, from userid 1000) id 104091019EF; Sat, 16 Jan 2016 14:12:03 +0100 (CET) Date: Sat, 16 Jan 2016 14:12:02 +0100 From: Andres Freund To: Dean Rasheed Cc: wrb , Haribabu Kommi , "pgsql-bugs@postgresql.org" Subject: Re: BUG #13863: Select from views gives wrong results Message-ID: <20160116131202.GP10941@awork2.anarazel.de> References: <20160113183558.12989.56904@wrigleys.postgresql.org> <82C006C0-07A7-401B-9BDA-0BABD9025099@autistici.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -4.2 (----) 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 Hi, Thanks for digging! On 2016-01-16 11:23:31 +0000, Dean Rasheed wrote: > When the clause is pushed down into the view it is turned from a WHERE > clause into a HAVING clause, because the view query has grouping. That > part is OK. However, the query planner then decides that since the new > HAVING clause doesn't contain any aggregates or volatile expressions, > it is safe to turn it back into a WHERE clause in the inner query. > That would be OK for normal grouping, because in that case the clause > would evaluate the same for all the rows in a group. However, that > doesn't work for grouping sets, since the output of the grouping sets > aggregation may contains nulls not present before grouping. > Probably that change should be undone and the comment expanded to > explain why it isn't safe when the query has grouping sets. Hm, I'm a bit hesitant to potentially noticeably regress plans here, although it seems unikely that already "relies" on this. Can't we essentially treat references to columns which can be set to null by due to a grouping set, as containing an agg clause and only prevent moving in that case? Greetings, Andres Freund -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs