From: Michael Fuhr <mike@fuhr.org>
To: postgresql performance list <pgsql-performance@postgresql.org>
Subject: Re: index on different types
Date: Thu, 28 Apr 2005 21:28:34 -0600
Message-ID: <20050429032834.GA68494@winnie.fuhr.org> (raw)
In-Reply-To: <20050429023512.GB26200@nibiru.borg.metux.de>
References: <20050429023512.GB26200@nibiru.borg.metux.de>
On Fri, Apr 29, 2005 at 04:35:13AM +0200, Enrico Weigelt wrote:
>
> there's often some talk about indices cannot be used if datatypes
> dont match.
PostgreSQL 8.0 is smarter than previous versions in this respect.
It'll use an index if possible even when the types don't match.
> On a larger (and long time growed) application I tend to use OID
> for references on new tables while old stuff is using integer.
If you're using OIDs as primary keys then you might wish to reconsider.
See the caveats in the documentation and in the FAQ:
http://www.postgresql.org/docs/8.0/interactive/datatype-oid.htmlhttp://www.postgresql.org/docs/faqs.FAQ.html#4.12> Is the planner smart enough to see both as compatible datatype
> or is manual casting required ?
You can use EXPLAIN to see what the planner will do, but be aware
that the planner won't always use an index even if it could: if it
thinks a sequential scan would be faster then it won't use an index.
To see if using an index is possible, you could set enable_seqscan
to off before executing EXPLAIN. In any case, a foreign key column
probably ought to have the same type as the column it references --
is there a reason for making them different?
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
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: mike@fuhr.org
Subject: Re: index on different types
In-Reply-To: <20050429032834.GA68494@winnie.fuhr.org>
* 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