Martin Kjeldsen <[EMAIL PROTECTED]> writes:
> CREATE OR REPLACE VIEW v_test_with_number AS
>         SELECT
>                 t.*,
>                 (SELECT SUM(number) FROM test_use WHERE test_id = t.id) as 
> numbers
>         FROM test t;

This is a bad way to do it --- the sub-select isn't readily optimizable.
Try something like

 SELECT t.id, t.name, sum(test_use.number) AS numbers
   FROM test_use
   JOIN test t ON test_use.test_id = t.id
  GROUP BY t.id, t.name;


                        regards, tom lane

-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

Reply via email to