MySQL Forums
Forum List  »  Optimizer & Parser

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


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

Written By
November 08, 2015 11:14PM
November 09, 2015 11:42AM
November 11, 2015 12:17AM
November 10, 2015 10:35AM
November 11, 2015 12:15AM
Re: Why not use index
November 11, 2015 03:40AM
November 11, 2015 07:29PM
November 11, 2015 11:00PM
November 12, 2015 01:48AM
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.