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 D87FF9DC866 for ; Wed, 1 Feb 2006 15:34:27 -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 17889-03 for ; Wed, 1 Feb 2006 15:34:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 9A9739DC946 for ; Wed, 1 Feb 2006 15:34:23 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k11JYOqN003760; Wed, 1 Feb 2006 14:34:24 -0500 (EST) To: "Kevin Grittner" cc: pgsql-performance@postgresql.org Subject: Re: Planner reluctant to start from subquery In-reply-to: <43E0AA7E.EE98.0025.0@wicourts.gov> References: <43E0AA7E.EE98.0025.0@wicourts.gov> Comments: In-reply-to "Kevin Grittner" message dated "Wed, 01 Feb 2006 12:33:02 -0600" Date: Wed, 01 Feb 2006 14:34:24 -0500 Message-ID: <3759.1138822464@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.103 required=5 tests=[AWL=0.103] X-Spam-Score: 0.103 X-Spam-Level: X-Archive-Number: 200602/20 X-Sequence-Number: 17006 "Kevin Grittner" writes: > We do have a few queries where PostgreSQL is several orders of > magnitude slower. It appears that the reason it is choosing a bad plan > is that it is reluctant to start from a subquery when there is an outer > join in the FROM clause. AFAICT this case doesn't really hinge on the outer join at all. The problem is that EXISTS subqueries aren't well optimized. I would have expected an equivalent IN clause to work better. In fact, I'm not clear why the planner isn't finding the cheapest plan (which it does estimate as cheapest) from the IN version you posted. What PG version is this exactly? > ... The third query is the fastest, but isn't > portable enough for our mixed environment. Not really relevant to the problem, but what's wrong with it? Looks like standard SQL to me. regards, tom lane