X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2DF719DCD7F for ; Thu, 12 Jan 2006 08:18:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23301-05 for ; Thu, 12 Jan 2006 08:19:01 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.204]) by postgresql.org (Postfix) with ESMTP id 99C009DCD7A for ; Thu, 12 Jan 2006 08:18:56 -0400 (AST) Received: by xproxy.gmail.com with SMTP id s14so290986wxc for ; Thu, 12 Jan 2006 04:19:00 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=gvBR2AuHCdRov/uBnv5hTjdFA/3qQkhap9/0BmXlbvQk+8YMXiRhNFpN6pEQL1LP0bxDETIyJ1l6dmSwBl0wgWKlYSMEtBNxaR1EbBecRhRzG6UlTp5pErduXzP7MfMnb9CFWGT5dxkVWLQG59v3a5R06OFCLkAK6IrfWtojOkg= Received: by 10.70.47.17 with SMTP id u17mr2247768wxu; Thu, 12 Jan 2006 04:18:58 -0800 (PST) Received: by 10.70.44.7 with HTTP; Thu, 12 Jan 2006 04:18:58 -0800 (PST) Message-ID: <34608c0c0601120418n1af567b9n@mail.gmail.com> Date: Thu, 12 Jan 2006 13:18:58 +0100 From: =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= To: pgsql-performance@postgresql.org Subject: Throwing unnecessary joins away MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_11612_32089099.1137068338744" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.473 required=5 tests=[AWL=-0.472, HTML_10_20=0.945, HTML_MESSAGE=0.001] X-Spam-Score: 0.473 X-Spam-Level: X-Archive-Number: 200601/151 X-Sequence-Number: 16629 ------=_Part_11612_32089099.1137068338744 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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=3Dtable2.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 ever= y 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 ------=_Part_11612_32089099.1137068338744 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
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.=20
Or if I do a "table1 left join table2 (table1.referer=3Dtable2.id= )"  (N : 1 relationship), and I don't reference table2 anywhere e= lse, then it is unnecessary.
Primary key - primary key joins are often generated by O/R mappers. Th= ese generated queries could be optimized even more by not joining if not ne= cessary.
 
You may say that I should not write such queries. The truth is that th= e O/R mapper is generating queries on views, and it does not use every fiel= d every time, but even so the query of the view is executed with the s= ame plan by PostgreSQL, although some joins are unnecessary.
 
So basically this all is relevant only with views.
 
Best Regards,
Otto
------=_Part_11612_32089099.1137068338744--