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 8A128D9853 for ; Fri, 11 Nov 2005 13:17:54 -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 51693-05 for ; Fri, 11 Nov 2005 17:17:53 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id E8853D8ED9 for ; Fri, 11 Nov 2005 13:17:52 -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 jABHGX8I019852; Fri, 11 Nov 2005 12:16:33 -0500 (EST) To: Mitchell Skinner cc: Richard Huxton , pgsql-performance@postgresql.org Subject: Re: same plan, add 1 condition, 1900x slower In-reply-to: <1131728255.10481.51.camel@firebolt> References: <1131630176.29496.91.camel@enzian> <10164.1131643400@sss.pgh.pa.us> <1131700635.29496.136.camel@enzian> <437485DB.50005@archonet.com> <18120.1131718624@sss.pgh.pa.us> <1131722682.29496.229.camel@enzian> <18883.1131723210@sss.pgh.pa.us> <19095.1131724394@sss.pgh.pa.us> <1131728255.10481.51.camel@firebolt> Comments: In-reply-to Mitchell Skinner message dated "Fri, 11 Nov 2005 08:57:35 -0800" Date: Fri, 11 Nov 2005 12:16:33 -0500 Message-ID: <19851.1131729393@sss.pgh.pa.us> From: Tom Lane 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/212 X-Sequence-Number: 15469 Mitchell Skinner writes: > On Fri, 2005-11-11 at 10:53 -0500, Tom Lane wrote: >> what you need to do is incorporate the "source" value into the >> external_id_map index key somehow. Then the index scan would be able to >> realize that there is no possibility of finding another row with source >> = 'SCH'. The simplest way is just to make a 2-column index > I thought that's what I had done with the > external_id_map_source_target_id index: > "external_id_map_source_target_id" btree (source, target_id) > If I changed that index to be (target_id, source) would it make a difference? [ fools around with a test case ... ] Seems like not :-(. PG is not bright enough to realize that an index on (source, target_id) can be used with a mergejoin on target_id, because the index sort order isn't compatible. (Given the equality constraint on source, there is an effective compatibility. I had thought that 8.1 might be able to detect this, but it seems not to in a simple test case --- there may be a bug involved there. In any case 8.0 definitely won't see it.) An index on (target_id, source) would be recognized as mergejoinable, but that doesn't solve the problem because an index condition on the second column doesn't provide enough information to know that the scan can stop early. Given your comment that the correlation is accidental, it may be that there's not too much point in worrying. The planner is picking this plan only because it notices the asymmetry in key ranges, and as soon as some more rows get added with higher-numbered target_ids it will shift to something else (probably a hash join). regards, tom lane