Unix Technical Forum

index on different types

This is a discussion on index on different types within the Pgsql Performance forums, part of the PostgreSQL category; --> Hi folks, there's often some talk about indices cannot be used if datatypes dont match. On a larger (and ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 11:39 AM
Enrico Weigelt
 
Posts: n/a
Default index on different types


Hi folks,


there's often some talk about indices cannot be used if datatypes
dont 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.
Is the planner smart enough to see both as compatible datatype
or is manual casting required ?


thx
--
---------------------------------------------------------------------
Enrico Weigelt == metux IT service
phone: +49 36207 519931 www: http://www.metux.de/
fax: +49 36207 519932 email: contact@metux.de
---------------------------------------------------------------------
Realtime Forex/Stock Exchange trading powered by postgresSQL )
http://www.fxignal.net/
---------------------------------------------------------------------

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 11:39 AM
Michael Fuhr
 
Posts: n/a
Default Re: index on different types

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/i...atype-oid.html
http://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/

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:16 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com