Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VyrSw-0004H5-1O for pgsql-performance@arkaria.postgresql.org; Thu, 02 Jan 2014 23:14:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VyrSu-0004ud-M3 for pgsql-performance@arkaria.postgresql.org; Thu, 02 Jan 2014 23:14:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VyrRk-0003Lp-9w for pgsql-performance@postgresql.org; Thu, 02 Jan 2014 23:13:00 +0000 Received: from mailout.scc.kit.edu ([129.13.185.202]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VyrRh-0007b9-Pu for pgsql-performance@postgresql.org; Thu, 02 Jan 2014 23:12:59 +0000 Received: from KIT-MSX-03.kit.edu (kit-msx-03.kit.edu [172.21.117.13]) by scc-mailout-02.scc.kit.edu with esmtps (Exim 4.72 #1) id 1VyrRg-0008OJ-GC; Fri, 03 Jan 2014 00:12:56 +0100 Received: from [141.3.200.96] (172.21.117.6) by smtp.kit.edu (172.21.117.13) with Microsoft SMTP Server (TLS) id 8.3.327.1; Fri, 3 Jan 2014 00:12:56 +0100 Message-ID: <52C5F277.8070001@student.kit.edu> Date: Fri, 3 Jan 2014 00:12:55 +0100 From: Thomas Mayer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Tom Lane , Jeff Janes CC: pgsql-performance Subject: Re: window function induces full table scan References: <52C5DAD1.20109@student.kit.edu> <17191.1388699570@sss.pgh.pa.us> <18380.1388702592@sss.pgh.pa.us> In-Reply-To: <18380.1388702592@sss.pgh.pa.us> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -4.7 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Am 02.01.2014 23:43, schrieb Tom Lane: > Jeff Janes writes: >> On Thu, Jan 2, 2014 at 1:52 PM, Tom Lane wrote: >>> It's possible that in the specific case you exhibit here, pushing down >>> the clause wouldn't result in changes in the window function's output for >>> the selected rows, but the optimizer doesn't have enough knowledge about >>> window functions to determine that. > >> A restriction in the WHERE clause which corresponds to the PARTITION BY >> should be pushable, no? I think it doesn't need to understand the internal >> semantics of the window function itself, just of the PARTITION BY, which >> should be doable, at least in principle. > > If the restriction clause must give the same answer for any two rows of > the same partition, then yeah, we could in principle push it down without > knowing anything about the specific window function. It'd be a less than > trivial test to make, I think. In any case, it's not a "bug" that the > optimizer doesn't do this currently. I agree, this is not a "bug" in v9.3.2 in terms of correctness. But it's a limitation, because the query plan is by far not optimal. You may consider this report as a feature request then. The optimization I suggested is normally performed, when no window function occurs in the statement. It seems like the optimizer is already capable of doing a check if the WHERE can be done first. However, this check seems to be done too conservative: I guess, the check is ignoring the PARTITION-BY-sets of attributes completely. > > regards, tom lane > . > Best regards Thomas -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance