From: | Andreas Kretschmer <akretschmer(at)spamfence(dot)net> |
---|---|
To: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: bad execution plan for subselects containing windowing-function |
Date: | 2010-01-14 18:03:49 |
Message-ID: | 20100114180349.GA9962@tux |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Andreas Kretschmer <akretschmer(at)spamfence(dot)net> writes:
> > Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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.
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°
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Smith | 2010-01-14 18:07:44 | Re: a heavy duty operation on an "unused" table kills my server |
Previous Message | Greg Smith | 2010-01-14 18:01:50 | Re: Slow "Select count(*) ..." query on table with 60 Mio. rows |