X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8410AD9AE8 for ; Wed, 9 Nov 2005 18:47:21 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20349-09 for ; Wed, 9 Nov 2005 22:47:18 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 55524D98B8 for ; Wed, 9 Nov 2005 18:47:20 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id AA18235512; Wed, 9 Nov 2005 14:47:22 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id A87853550F; Wed, 9 Nov 2005 14:47:22 -0800 (PST) Date: Wed, 9 Nov 2005 14:47:22 -0800 (PST) From: Stephan Szabo To: Ashok Agrawal Cc: pgsql-performance@postgresql.org Subject: Re: Outer Join performance in PostgreSQL In-Reply-To: <43725511.3040809@Sun.COM> Message-ID: <20051109144311.B34905@megazone.bigpanda.com> References: <43725511.3040809@Sun.COM> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006] X-Spam-Score: 0.006 X-Spam-Level: X-Archive-Number: 200511/166 X-Sequence-Number: 15423 On Wed, 9 Nov 2005, Ashok Agrawal wrote: > I noticed outer join is very very slow in postgresql as compared > to Oracle. > > SELECT a.dln_code, a.company_name, > to_char(a.certificate_date,'DD-MON-YYYY'), > to_char(a.certificate_type_id, '99'), > COALESCE(b.certificate_type_description,'None') , > a.description, a.blanket_single, a.certificate_status, > COALESCE(a.sun_legal_entity, 'None'), > COALESCE(a.other_entity_name, 'None'), > COALESCE(a.notes, 'None'),COALESCE(c.name, NULL), > COALESCE(to_char(a.created_date,'DD-MON-YYYY'), 'N/A'), > COALESCE(c.name, NULL), > COALESCE(to_char(a.updated_date,'DD-MON-YYYY'), 'N/A'), > COALESCE(e.name, NULL), > COALESCE(to_char(a.approved_date,'DD-MON-YYYY'), 'N/A') > FROM ((((ecms_cert_headers a > LEFT OUTER JOIN taxpack_user c ON (a.created_by = c.emp_no)) > LEFT OUTER JOIN taxpack_user d ON (a.updated_by = d.emp_no)) > LEFT OUTER JOIN taxpack_user e ON (a.approved_by = e.emp_no)) > INNER JOIN ecms_certificate_types b ON > (a.certificate_type_id= b.certificate_type_id )) > WHERE a.dln_code = '17319' I think in the above it's safe to do the inner join first, although PostgreSQL won't determine that currently and that could have something to do with the difference in performance if Oracle did reorder the joins. If you were to run the query doing the INNER JOIN first, does that give the correct results and run more quickly in PostgreSQL? In either case, explain analyze output would be handy to find the actual times taken by the steps.