Search Postgresql Archives

Re: Optimising Union Query.

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

 



In article <4268F322.1040106@xxxxxxxxxxxxx>,
Rob Kirkbride <rob.kirkbride@xxxxxxxxxxxxx> wrote:

% I've done a explain analyze and as I expected the database has to check 
% every row in each of the three tables below but I'm wondering if I can 

This is because you're returning a row for every row in the three
tables.

% select l.name,l.id from pa i,locations l where i.location=l.id union 
% select l.name,l.id from andu i,locations l where i.location=l.id union 
% select l.name,l.id from idu i,locations l where i.location=l.id;

You might get some improvement from

 select name,id from locations
  where id in (select distinct location from pa union
               select distinct location from andu union
               select distinct location from idu);

this query might be helped by an index on location in each of those
three tables, but probably not.
-- 

Patrick TJ McPhee
North York  Canada
ptjm@xxxxxxxxxxxx

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux