Re: 7.4 Wishlist

Поиск
Список
Период
Сортировка
От Christopher Kings-Lynne
Тема Re: 7.4 Wishlist
Дата
Msg-id 016a01c29a44$308a7870$6500a8c0@internal
обсуждение исходный текст
Ответ на 7.4 Wishlist  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
Ответы Re: 7.4 Wishlist  (Karel Zak <zakkr@zf.jcu.cz>)
Список pgsql-hackers
> Yeah, but there is a point about running count(*) one time too many.
> Say if i would like to get a prettyprinting query like this:
>
> SELECT id, @a:=COUNT(*), sum_col::text||'/'@a::text FROM table_name;
>
> That would be DAMN expensive doing with a subselect:
>
> SELECT id, sum_col||'/'||(select COUNT(*) from tabe_name) FROM
> table_name;
>
> I know this example suck eggs, but you get the point where it hurts,
> right?

Are you sure that postgres evaluates that subselect more than once?  It
looks to me like it returns a constant result for every row and hence it
will be evaluated once per statement, not once per row.  I'm no expert tho.
Can someone answer this?

And if the subselect changes for each row (ie. it's a correlated subquery)
then you cannot use the variable anyway.

It seems to me that if postgres doesn't consider count(*) as a constant then
perhaps it should be taught to?  Should be safe shouldn't it?  I guess if a
function in your select statemnt is inserting a row then there's trouble.
But if there is, then the sum/count(*) is nonsensical anyway.

Chris



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

Предыдущее
От: Robert Treat
Дата:
Сообщение: Re: protecting prosrc (was Re: [GENERAL] USAGE on schema allowed by
Следующее
От: "Christopher Kings-Lynne"
Дата:
Сообщение: Re: ALTER .. ADD PRIMARY KEY