pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-performance@postgresql.org
Subject: Re: bad execution plan for subselects containing windowing-function
Date: Thu, 14 Jan 2010 19:31:39 +0100
Message-ID: <20100114183139.GA11334@tux> (raw)
In-Reply-To: <20100114180349.GA9962@tux>
References: <20100114170318.GA7634@tux>
	<25448.1263489336@sss.pgh.pa.us>
	<20100114173025.GA8675@tux>
	<25915.1263490925@sss.pgh.pa.us>
	<20100114180349.GA9962@tux>

Andreas Kretschmer <akretschmer@spamfence.net> 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°



view thread (6+ messages)

Message-ID: <20100114183139.GA11334@tux>
Permalink:  ../20100114183139.GA11334@tux/
Also on:    postgresql.org/message-id/20100114183139.GA11334@tux

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: akretschmer@spamfence.net
  Subject: Re: bad execution plan for subselects containing windowing-function
  In-Reply-To: <20100114183139.GA11334@tux>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox