Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Why does an 'OR' stop indexes from being used?
Old 04-19-2006, 01:09 AM Why does an 'OR' stop indexes from being used?
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
1) SELECT * FROM table WHERE col1='A'

2) SELECT * FROM table WHERE col1='A' OR col1='B'

Considering that we have an index on col1, does anyone know why the index is used inthe first statement but not the second?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
 
Register now for full access!
Old 04-19-2006, 06:52 AM Re: Why does an 'OR' stop indexes from being used?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
it shouldn't do although that may depend on the DB server and version

how do you know that it does?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-19-2006, 07:34 AM Re: Why does an 'OR' stop indexes from being used?
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Sorry that i wasn't clear!!!

We are using MySql 4.1 and i know by using EXPLAIN.

Also, if you take a look at and look at http://dev.mysql.com/doc/refman/5.0/...l-indexes.html and read the post Posted by [name withheld] on June 4 2003 2:21am, the poster says, 'The 'not using indexes when using OR' feature is rather annoying'

Thanks for your help and guidance.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Reply     « Reply to Why does an 'OR' stop indexes from being used?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12077 seconds with 12 queries