From: | Ottó Havasvölgyi <havasvolgyi(dot)otto(at)gmail(dot)com> |
---|---|
To: | pgsql-performance(at)postgresql(dot)org |
Subject: | Throwing unnecessary joins away |
Date: | 2006-01-12 12:18:58 |
Message-ID: | 34608c0c0601120418n1af567b9n@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Hi all,
Is PostgreSQL able to throw unnecessary joins?
For example I have two tables, and I join then with their primary keys, say
type of bigint . In this case if I don't reference to one of the
tables anywhere except the join condition, then the join can be eliminated.
Or if I do a "table1 left join table2 (table1.referer=table2.id)" (N : 1
relationship), and I don't reference table2 anywhere else, then it is
unnecessary.
Primary key - primary key joins are often generated by O/R mappers. These
generated queries could be optimized even more by not joining if not
necessary.
You may say that I should not write such queries. The truth is that the O/R
mapper is generating queries on views, and it does not use every field every
time, but even so the query of the view is executed with the same plan by
PostgreSQL, although some joins are unnecessary.
So basically this all is relevant only with views.
Best Regards,
Otto
From | Date | Subject | |
---|---|---|---|
Next Message | Alessandro Baretta | 2006-01-12 12:35:07 | Re: Throwing unnecessary joins away |
Previous Message | Simon Riggs | 2006-01-12 09:48:41 | Re: Extremely irregular query performance |