L
L
LittleFatNinja2020-03-03 14:34:38
MySQL
LittleFatNinja, 2020-03-03 14:34:38

How does mysql decide which indexes to use?

There is a table with 2 separate indexes on gender (tinyint) and age (int)
AND 2 queries

explain select * from test_table where gender = 1 and age = 100;

explain select * from test_table where gender = 1 and age = 101;


Explain of the 1st query returns type: index_mergeand key: test_table_age_index,test_table_gender_index- that is, 2 indexes by age and gender are used

Explain of the 2nd query returns type: ref и key: test_table_age_index- that is, only 1 index by age is used

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Karasik, 2020-03-04
@vitaly_il1

Approximately as they said in the comment - scientifically it is called cardinality - https://www.mysqltutorial.org/mysql-index/mysql-in...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question