X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 50744D1B1CD for ; Mon, 2 Aug 2004 11:04:23 -0300 (ADT) 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 35607-05 for ; Mon, 2 Aug 2004 14:03:56 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id DE00DD1B184 for ; Mon, 2 Aug 2004 11:03:46 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i72E3mqW009717; Mon, 2 Aug 2004 10:03:48 -0400 (EDT) To: Rod Taylor Cc: mailing@impactmedia.de, Postgresql Performance Subject: Re: No index usage with "left join" In-reply-to: <1091450721.36221.104.camel@jester> References: <20040802120851.B32852202B7@p15110922.pureserver.info> <1091450721.36221.104.camel@jester> Comments: In-reply-to Rod Taylor message dated "Mon, 02 Aug 2004 08:45:22 -0400" Date: Mon, 02 Aug 2004 10:03:47 -0400 Message-ID: <9716.1091455427@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/11 X-Sequence-Number: 7647 Rod Taylor writes: >> How can I force the usage of the indexes when using "left join". > Anyway, we can be fairly sure this isn't PostgreSQL 7.4 (which would > likely choose a far better plan -- hash join rather than nested loop) Indeed, the lack of any join-condition line in the EXPLAIN output implies it's 7.2 or older. IIRC 7.4 is the first release that is capable of using merge or hash join with a condition more complicated than plain "Var = Var". In this case, since the two fields are of different datatypes, the planner sees something like "Var = Var::text" (ie, there's an inserted cast function). 7.2 will just say "duh, too complicated for me" and generate a nestloop. With the columns being of different datatypes, you don't even have a chance for an inner indexscan in the nestloop. In short: change the column datatypes to be the same, or update to 7.4.something. There are no other solutions. (Well, if you were really desperate you could create a set of mergejoinable "text op bigint" comparison operators, and then 7.2 would be able to cope; but I should think that updating to 7.4 would be much less work.) regards, tom lane