Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id D9434633E3C for ; Thu, 14 Jan 2010 13:15:56 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 38907-07 for ; Thu, 14 Jan 2010 17:15:46 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 2AD05634215 for ; Thu, 14 Jan 2010 13:15:37 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o0EHFasC025449; Thu, 14 Jan 2010 12:15:36 -0500 (EST) To: Andreas Kretschmer cc: pgsql-performance@postgresql.org Subject: Re: bad execution plan for subselects containing windowing-function In-reply-to: <20100114170318.GA7634@tux> References: <20100114170318.GA7634@tux> Comments: In-reply-to Andreas Kretschmer message dated "Thu, 14 Jan 2010 18:03:18 +0100" Date: Thu, 14 Jan 2010 12:15:36 -0500 Message-ID: <25448.1263489336@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.589 tagged_above=-10 required=5 tests=BAYES_00=-2.599, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/288 X-Sequence-Number: 37168 Andreas Kretschmer writes: > No question, this is a silly query, but the problem is the 2nd query: it > is obviously not possible for the planner to put the where-condition > into the subquery. Well, yeah: it might change the results of the window functions. I see no bug here. Your second query asks for a much more complicated computation, it's not surprising it takes longer. regards, tom lane