Re: bad execution plan for subselects containing windowing-function

Поиск
Список
Период
Сортировка
От Andreas Kretschmer
Тема Re: bad execution plan for subselects containing windowing-function
Дата
Msg-id 20100114183139.GA11334@tux
обсуждение исходный текст
Ответ на Re: bad execution plan for subselects containing windowing-function  (Andreas Kretschmer <akretschmer@spamfence.net>)
Список pgsql-performance
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°

В списке pgsql-performance по дате отправления:

Предыдущее
От: Greg Smith
Дата:
Сообщение: Re: a heavy duty operation on an "unused" table kills my server
Следующее
От: "Kevin Grittner"
Дата:
Сообщение: Re: Slow "Select count(*) ..." query on table with 60 Mio. rows