Re: Why not use index
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
Subject
Views
Written By
Posted
2163
November 08, 2015 11:14PM
1011
November 09, 2015 11:42AM
1043
November 11, 2015 12:17AM
1119
November 10, 2015 10:35AM
1215
November 11, 2015 12:15AM
Re: Why not use index
1124
November 11, 2015 03:40AM
1391
November 11, 2015 07:29PM
974
November 11, 2015 11:00PM
1119
November 12, 2015 01:48AM
1078
November 16, 2015 12:17AM