From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andreas Kretschmer <akretschmer@spamfence.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: bad execution plan for subselects containing windowing-function
Date: Thu, 14 Jan 2010 12:42:05 -0500
Message-ID: <25915.1263490925@sss.pgh.pa.us> (raw)
In-Reply-To: <20100114173025.GA8675@tux>
References: <20100114170318.GA7634@tux>
<25448.1263489336@sss.pgh.pa.us>
<20100114173025.GA8675@tux>
Andreas Kretschmer <akretschmer@spamfence.net> writes:
> Tom Lane <tgl@sss.pgh.pa.us> 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.
regards, tom lane
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: tgl@sss.pgh.pa.us, akretschmer@spamfence.net
Subject: Re: bad execution plan for subselects containing windowing-function
In-Reply-To: <25915.1263490925@sss.pgh.pa.us>
* 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