X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 784239FA7BA for ; Wed, 16 Aug 2006 11:35:07 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 45002-07 for ; Wed, 16 Aug 2006 11:35:02 -0300 (ADT) X-Greylist: delayed 00:59:58.605956 by SQLgrey- Received: from globalrelay.com (mail1.globalrelay.com [216.18.71.77]) by postgresql.org (Postfix) with ESMTP id 3587A9FA65C for ; Wed, 16 Aug 2006 11:35:01 -0300 (ADT) X-Virus-Scanned: Scanned by GRC-AntiVirus Gateway X-GR-Acctd: YES Received: from [67.90.96.2] (HELO DaveEMachine) by globalrelay.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 100735860; Wed, 16 Aug 2006 06:34:59 -0700 From: "Dave Dutcher" To: "'Luiz K. Matsumura'" , Subject: Re: Big diference in response time (query plan question) Date: Wed, 16 Aug 2006 08:34:59 -0500 Message-ID: <00a501c6c138$c55725b0$8300a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 Importance: Normal In-Reply-To: <44E26939.30903@planit.com.br> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200608/264 X-Sequence-Number: 20449 > From: pgsql-performance-owner@postgresql.org=20 > [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of=20 > Luiz K. Matsumura > Well, in this case the queries with LEFT OUTER join and with=20 > inner join=20 > returns the same result set. I don=B4t have the sufficient knowledge = to > affirm , but I suspect that if the query plan used for=20 > fk_clifor =3D 352=20 > and with left outer join is applied for the first query=20 > (fk_clifor =3D 243=20 > with left outer join) > we will have a better total runtime. > There are some manner to make this test ? It looks like Postgres used a nested loop join for the fast query and a merge join for the slow query. I don't think the left join is causing = any problems. On the slower query the cost estimate of the nested loop must have been higher than the cost estimate of the merge join because of = more rows. You could try disabling merge joins with the command "set enable_mergejoin=3Dfalse". Then run the explain analyze again to see if = it is faster. =20 If it is faster without merge join, then you could try to change your settings to make the planner prefer the nested loop. I'm not sure what = the best way to do that is. Maybe you could try reducing the = random_page_cost, which should make index scans cheaper. Dave