Re: 7.4 Wishlist

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "Magnus Naeslund(f)" <mag(at)fbab(dot)net>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: 7.4 Wishlist
Date: 2002-12-02 20:48:38
Message-ID: 016a01c29a44$308a7870$6500a8c0@internal
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-advocacy pgsql-general 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

In response to

Responses

Browse pgsql-advocacy by date

  From Date Subject
Next Message Medi Montaseri 2002-12-02 21:02:30 Re: Segmentation fault while COPY in 7.3
Previous Message Magnus Naeslund(f) 2002-12-02 20:34:20 Re: 7.4 Wishlist

Browse pgsql-general by date

  From Date Subject
Next Message Medi Montaseri 2002-12-02 20:53:55 Re: vacuum full analyze problem
Previous Message Robert Treat 2002-12-02 20:45:22 Re: protecting prosrc (was Re: [GENERAL] USAGE on schema allowed by

Browse pgsql-hackers by date

  From Date Subject
Next Message Medi Montaseri 2002-12-02 21:02:30 Re: Segmentation fault while COPY in 7.3
Previous Message Robert Treat 2002-12-02 20:45:22 Re: protecting prosrc (was Re: [GENERAL] USAGE on schema allowed by