pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rod Taylor <pg@rbt.ca>
To: mailing@impactmedia.de
Cc: Postgresql Performance <pgsql-performance@postgresql.org>
Subject: Re: No index usage with "left join"
Date: Mon, 02 Aug 2004 08:45:22 -0400
Message-ID: <1091450721.36221.104.camel@jester> (raw)
In-Reply-To: <20040802120851.B32852202B7@p15110922.pureserver.info>
References: <20040802120851.B32852202B7@p15110922.pureserver.info>

> SELECT count(*) FROM contacts LEFT JOIN companies ON contacts.sid =
> companies.intfield01
> 
> contacts.sid (type text, b-tree index on it)
> companies.intfield01 (type bigint, b-tree index on it)
<snip>
> How can I force the usage of the indexes when using "left join". Or
> any other SQL construct that does the same !? Can anybody please give
> us a hint !?

You really don't need to use indexes since you're fetching all
information from both tables.

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) as
it won't join a bigint to a text field without a cast.

Try this:
	set enable_nestloop = false;
        SELECT count(*) FROM contacts LEFT JOIN companies ON
        cast(contacts.sid as bigint) = companies.intfield01;
	set enable_nestloop = true;





view thread (5+ messages)  latest in thread

Message-ID: <1091450721.36221.104.camel@jester>
Permalink:  ../1091450721.36221.104.camel@jester/
Also on:    postgresql.org/message-id/1091450721.36221.104.camel@jester

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: pg@rbt.ca, mailing@impactmedia.de
  Subject: Re: No index usage with "left join"
  In-Reply-To: <1091450721.36221.104.camel@jester>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox