MySQL Forums
Forum List  »  InnoDB

Using indexes for "IN" clauses with composite values
Posted by: Josep Blanquer
Date: April 14, 2014 10:59AM

It seems that using "IN" clauses with composite values, does not use any of the indexes that might exist for the individual keys.

For example:

SELECT * from foobar where (`field1`,`field2`) IN (('a',1) , ('b',2) ...)

won't use an index for field1, or field2 if they exist.

...so the first question I have is: why is it this way? is it an implementation issue that prevents this? or simply a feature that was not deemed important enough to be done?

What it is very puzzling to me is the fact that even if I have a covering index for all the fields in the "IN" clause...the select will still NOT use the index.

So the same example above:

SELECT * from foobar where (`field1`,`field2`) IN (('a',1) , ('b',2) ...)

.. will not use an index even if I have a composite one with (field1,field2)

Why is that? Is there a way to make this work? ("Force index" doesn't seem to help)
Would it use the indexes if these were part of a composite PK instead of an index?

Cheers,

Josep M.

Options: ReplyQuote


Subject
Views
Written By
Posted
Using indexes for "IN" clauses with composite values
1549
April 14, 2014 10:59AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.