MySQL Forums
Forum List  »  Optimizer & Parser

Re: Why not use index
Posted by: Øystein Grøvlen
Date: November 11, 2015 03:40AM

Hi,

MySQL will only use index lookup (so-called ref access) when join condition is a conjunction of equality predicates. Otherwise, if join condition contains OR or range predicates (e.g., t1.x < t2.y), it may decide whether to use index dynamically for every look-up. Then, whether the index is used or not, will be based on the estimated number of rows that will have to be fetched for the given value.

In your case, for example, it will, for each row in t1, ask the storage engine for an estimate of how many rows in t2 will have the value of either t1.mid or t1.sid. If the total is less than 15% or so of the total number of rows in t2, it will normally use the index for lookup. When this approach is used, EXPLAIN will show "Range checked for each record" in the Extra column. Does it not do that in your case?

Øystein Grøvlen,
Senior Principal Software Engineer,
MySQL Group, Oracle,
Trondheim, Norway

Options: ReplyQuote


Subject
Views
Written By
Posted
1633
November 08, 2015 11:14PM
820
November 09, 2015 11:42AM
843
November 11, 2015 12:17AM
876
November 10, 2015 10:35AM
1030
November 11, 2015 12:15AM
Re: Why not use index
913
November 11, 2015 03:40AM
1148
November 11, 2015 07:29PM
811
November 11, 2015 11:00PM
890
November 12, 2015 01:48AM
871
November 16, 2015 12:17AM


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.