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 304F3D7E67 for ; Wed, 9 Nov 2005 15:59:36 -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 57098-02 for ; Wed, 9 Nov 2005 19:59:31 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from brmea-mail-3.sun.com (brmea-mail-3.Sun.COM [192.18.98.34]) by svr1.postgresql.org (Postfix) with ESMTP id BEEB3D77CC for ; Wed, 9 Nov 2005 15:59:29 -0400 (AST) Received: from phys-hanwk-1 ([129.149.2.111]) by brmea-mail-3.sun.com (8.12.10/8.12.9) with ESMTP id jA9JxT3F024796 for ; Wed, 9 Nov 2005 12:59:29 -0700 (MST) Received: from conversion-daemon.hanwk-mail1.sfbay.sun.com by hanwk-mail1.sfbay.sun.com (iPlanet Messaging Server 5.2 HotFix 1.24 (built Dec 19 2003)) id <0IPP00901DT7ZB@hanwk-mail1.sfbay.sun.com> (original mail from Ashok.Agrawal@Sun.COM) for pgsql-performance@postgresql.org; Wed, 09 Nov 2005 11:59:29 -0800 (PST) Received: from Sun.COM (sr1-unwk-09.SFBay.Sun.COM [129.149.2.159]) by hanwk-mail1.sfbay.sun.com (iPlanet Messaging Server 5.2 HotFix 1.24 (built Dec 19 2003)) with ESMTP id <0IPP001URE6PUK@hanwk-mail1.sfbay.sun.com> for pgsql-performance@postgresql.org; Wed, 09 Nov 2005 11:59:13 -0800 (PST) Date: Wed, 09 Nov 2005 11:59:13 -0800 From: Ashok Agrawal Subject: Outer Join performance in PostgreSQL To: pgsql-performance@postgresql.org Reply-To: Ashok.Agrawal@Sun.COM Message-id: <43725511.3040809@Sun.COM> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.4) Gecko/20041214 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.062 required=5 tests=[AWL=0.061, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.062 X-Spam-Level: X-Archive-Number: 200511/160 X-Sequence-Number: 15417 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' This query return only 1 record but take 25 second to execute in postgreSQL as compared to 1.3 second in Oracle. Any suggestion ? Below is explain output. Hash Join (cost=1666049.74..18486619.37 rows=157735046 width=874) Hash Cond: ("outer".certificate_type_id = "inner".certificate_type_id) -> Merge Right Join (cost=1666048.13..11324159.05 rows=643816513 width=826) Merge Cond: ("outer"."?column3?" = "inner"."?column16?") -> Sort (cost=30776.19..31207.80 rows=172645 width=64) Sort Key: (e.emp_no)::text -> Seq Scan on taxpack_user e (cost=0.00..4898.45 rows=172645 width=64) -> Sort (cost=1635271.94..1637136.51 rows=745827 width=811) Sort Key: (a.approved_by)::text -> Merge Left Join (cost=25230.45..36422.18 rows=745827 width=811) Merge Cond: ("outer"."?column17?" = "inner"."?column2?") -> Sort (cost=3117.35..3119.51 rows=864 width=844) Sort Key: (a.updated_by)::text -> Nested Loop Left Join (cost=0.00..3075.21 rows=864 width=844) -> Index Scan using pk_ecms_cert_headers on ecms_cert_headers a (cost=0.00..6.01 rows=1 width=829) Index Cond: ((dln_code)::text = '17319'::text) -> Index Scan using ash_n1 on taxpack_user c (cost=0.00..3058.40 rows=864 width=64) Index Cond: (("outer".created_by)::text = (c.emp_no)::text) -> Sort (cost=22113.10..22544.71 rows=172645 width=16) Sort Key: (d.emp_no)::text -> Seq Scan on taxpack_user d (cost=0.00..4898.45 rows=172645 width=16) -> Hash (cost=1.49..1.49 rows=49 width=50) -> Seq Scan on ecms_certificate_types b (cost=0.00..1.49 rows=49 width=50) (23 rows) Thanks Ashok