Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id ACAB76342C0 for ; Thu, 14 Jan 2010 14:04:03 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 40785-09 for ; Thu, 14 Jan 2010 18:03:51 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from vs137086.vserver.de (static-ip-62-75-137-86.inaddr.intergenia.de [62.75.137.86]) by mail.postgresql.org (Postfix) with ESMTP id BF2316323AF for ; Thu, 14 Jan 2010 14:03:52 -0400 (AST) Received: (qmail 28389 invoked from network); 14 Jan 2010 19:03:51 +0100 Received: from p54b3a04d.dip0.t-ipconnect.de (HELO a-kretschmer.de) (84.179.160.77) by static-ip-62-75-137-86.inaddr.intergenia.de with (AES256-SHA encrypted) SMTP; 14 Jan 2010 19:03:51 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1NVU2v-0002gc-Lr for pgsql-performance@postgresql.org; Thu, 14 Jan 2010 19:03:49 +0100 Date: Thu, 14 Jan 2010 19:03:49 +0100 From: Andreas Kretschmer To: pgsql-performance@postgresql.org Subject: Re: bad execution plan for subselects containing windowing-function Message-ID: <20100114180349.GA9962@tux> References: <20100114170318.GA7634@tux> <25448.1263489336@sss.pgh.pa.us> <20100114173025.GA8675@tux> <25915.1263490925@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <25915.1263490925@sss.pgh.pa.us> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.042 tagged_above=-10 required=5 tests=AWL=0.557, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201001/292 X-Sequence-Number: 37172 Tom Lane wrote: > Andreas Kretschmer writes: > > Tom Lane wrote: > >> I see no bug here. Your second query asks for a much more complicated > >> computation, it's not surprising it takes longer. > > > But sorry, I disagree. It is the same query with the same result. I can't see > > how the queries should return different results. > > In the first query > > select id, avg(value) over (partition by value) from values where id = 50 order by id; > > the avg() calculations are being done over only rows with id = 50. In > the second query > > select * from (select id, avg(value) over (partition by value) from values order by id) foo where id = 50; > > they are being done over all rows. In this particular example you > happen to get the same result, but that's just because "avg(foo) over > partition by foo" is a dumb example --- it will necessarily just yield > identically foo. In more realistic computations the results would be > different. Okay, i believe you now ;-) I will try to find a case with different results ... Thx for your fast help! Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°