Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id DE828633C15 for ; Thu, 14 Jan 2010 14:31:55 -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 45671-01 for ; Thu, 14 Jan 2010 18:31:43 +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 DE7AD63290E for ; Thu, 14 Jan 2010 14:31:44 -0400 (AST) Received: (qmail 24014 invoked from network); 14 Jan 2010 19:31:40 +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:31:40 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1NVUTr-00030W-44 for pgsql-performance@postgresql.org; Thu, 14 Jan 2010 19:31:39 +0100 Date: Thu, 14 Jan 2010 19:31:39 +0100 From: Andreas Kretschmer To: pgsql-performance@postgresql.org Subject: Re: bad execution plan for subselects containing windowing-function Message-ID: <20100114183139.GA11334@tux> References: <20100114170318.GA7634@tux> <25448.1263489336@sss.pgh.pa.us> <20100114173025.GA8675@tux> <25915.1263490925@sss.pgh.pa.us> <20100114180349.GA9962@tux> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20100114180349.GA9962@tux> 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.074 tagged_above=-10 required=5 tests=AWL=0.525, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201001/298 X-Sequence-Number: 37178 Andreas Kretschmer wrote: > > 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 ... I have got it! test=# select * from values; id | value ----+------- 1 | 10 2 | 20 3 | 30 4 | 40 5 | 50 6 | 60 7 | 70 8 | 80 9 | 90 (9 rows) Time: 0.240 ms test=*# select id, sum(value) over (order by id) from values where id = 5; id | sum ----+----- 5 | 50 (1 row) Time: 0.352 ms test=*# select * from (select id, sum(value) over (order by id) from values) foo where id = 5; id | sum ----+----- 5 | 150 (1 row) Time: 0.383 ms 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°