Answer the question
In order to leave comments, you need to log in
What to do with indexes with low selectivity?
There is a column where only yes or no values can be, the selection on it is long. Composite index made on 2 EXPLAIN fields shows that the index is not used and even possible_keys NULL he does not want to recognize it even as a possible index.
1. What to do in this case?
2. What to do if there are many such columns where only 0 or 1 is possible in the database?
Table structure:
mydate date type by default NULL
members int(10)
Query:
SELECT `members`, `domain`
FROM `table` WHERE `mydate` IS NULL ORDER BY `members` DESC LIMIT 100000,800
Answer the question
In order to leave comments, you need to log in
> LIMIT 100000,800
you have a heavy query in itself, and it looks like pagination.
Every time you need to get elements starting with #, mysql has to look up all # elements.
If the index is not in use, you can "force" mysql to use it .
Well, in general, if this is some kind of interface, then you probably need to think about why the user needs elements starting from 100k. Physically, he cannot view such a number of elements.
Make a composite index: mydate - members. You have a 50% full table scan :)
And yes, members-mydate is a different index, so it could not be used.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question