Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz96Z-00036s-3h for pgsql-performance@arkaria.postgresql.org; Fri, 03 Jan 2014 18:04:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vz96Y-0004DR-JF for pgsql-performance@arkaria.postgresql.org; Fri, 03 Jan 2014 18:04:18 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz96X-0004DK-Dr for pgsql-performance@postgresql.org; Fri, 03 Jan 2014 18:04:17 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz96U-00049C-JN for pgsql-performance@postgresql.org; Fri, 03 Jan 2014 18:04:16 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s03I4DXx004828; Fri, 3 Jan 2014 13:04:14 -0500 From: Tom Lane To: Thomas Mayer cc: pgsql-performance Subject: Re: window function induces full table scan In-reply-to: <52C6F712.6040804@student.kit.edu> References: <52C5DAD1.20109@student.kit.edu> <17191.1388699570@sss.pgh.pa.us> <18380.1388702592@sss.pgh.pa.us> <20167.1388706955@sss.pgh.pa.us> <52C63E8B.2040806@student.kit.edu> <9269.1388760865@sss.pgh.pa.us> <52C6F712.6040804@student.kit.edu> Comments: In-reply-to Thomas Mayer message dated "Fri, 03 Jan 2014 18:44:50 +0100" Date: Fri, 03 Jan 2014 13:04:13 -0500 Message-ID: <4827.1388772253@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) 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 Thomas Mayer writes: > ... "mark" ...: Do I understand you correctly, that you prefer doing the > decision elsewhere and store the result (safe/unsafe) boolean value > besides to the subquery output fields? For the push-down, a subquery > output field must be available anyways. See check_output_columns(). The infrastructure for deciding whether a potentially-pushable qual refers to any unsafe subquery outputs already exists; we just need to extend it to consider outputs unsafe if they don't appear in all PARTITION BY lists. >> Offhand I think the details of testing whether a given output column >> appears in a given partition clause are identical to testing whether >> it appears in the distinctClause. So you'd just be mechanizing running >> through the windowClause list to verify whether this holds for all >> the WINDOW clauses. > When a field is element of all PARTITION BY clauses of all window > functions, it does not mean that this field is distinct. No, I didn't say that. What I meant was that (a) the is_pushdown_safe logic can treat non-partitioning subquery outputs much like non-DISTINCT outputs, and (b) the parsetree representation of PARTITION BY is enough like DISTINCT ON that the same kind of test (viz, a targetIsInSortList call) will serve. I think you need to read the code around subquery_is_pushdown_safe and qual_is_pushdown_safe some more. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance