Re: Aggregate weirdness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martin Kjeldsen <martin@xxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux