Y
Y
yesworld2018-06-19 14:26:36
MySQL
yesworld, 2018-06-19 14:26:36

What is the correct way to use Explain in MySQL?

Hello.
I decided to calculate slow queries in the slow_query_log muscle .
I found one, on the test database of records in this table 90k+:

SELECT * FROM `Article`
WHERE `Article`.`type` = '1' 
  AND `Article`.`status` = '1' 
  AND `Article`.`publish_t` < '1529399940' 
  AND `Article`.`fixed_t` > '1529399940'
GROUP BY `Article`.`fixed_place`
ORDER BY `Article`.`fixed_t` ASC;

... I do Explain on it and get the following picture: I add
5b28e6960a3cf309289997.jpeg
an index on the fixed_t field and do Explain again.
5b28e6cf928fd603185387.jpeg
I look, the number of records has decreased to 1, but it's not entirely clear why type has become range. Simply, if you read the documentation, it says :
The type column of EXPLAIN output describes how tables are joined. The following list describes the join types, ordered from the best type to the worst:

Should I pay attention to type?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2018-06-19
@yesworld

Because now it has become easier to select the necessary rows by the fixed_t index than by the status index.
Compare:
and
The fewer lines that match the condition, the better. And type = range in the second case - because you choose not the exact value, but from the given value to infinity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question