MySQL explain filtered column jumping 4,100 with i

2020-07-10 20:26发布

问题:

My Query:

EXPLAIN EXTENDED SELECT  `artwork`.`id` ,  `artwork`.`added` 
FROM  `artwork` 
ORDER BY  `artwork`.`added` DESC 
LIMIT 0 , 6

When I added an index on "added" to avoid using filesort and use index instead the output of explained went from

id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE artwork ALL NULL NULL NULL NULL 302 100.00 Using filesort

to

id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE artwork index NULL added 4 NULL 6 5033.33  

and I'm concerned about the filtered going up approximently 4,100 - I can't find on Google what filtered means

回答1:

Hey, it's actually good news. It shows how many rows your limitations are removing from the result set. In this case, that would be your LIMIT statement. See the manual:

The filtered column indicates an estimated percentage of table rows that will be filtered by the table condition. That is, rows shows the estimated number of rows examined and rows × filtered / 100 shows the number of rows that will be joined with previous tables. This column is displayed if you use EXPLAIN EXTENDED.



回答2:

From the docs:

filtered

The filtered column indicates an estimated percentage of table rows that will be filtered by the table condition. That is, rows shows the estimated number of rows examined and rows × filtered / 100 shows the number of rows that will be joined with previous tables. This column is displayed if you use EXPLAIN EXTENDED. (New in MySQL 5.1.12)

Basically, it's ratio of records returned to records fetched.

Its goal is to show how selective your WHERE / ON conditions are and what would be the benefit of creating an index on them.

Note that this field has little sense for the queries with LIMIT, since it's always calculated without regard to the LIMIT clause, which rows is calculated with regard to the latter.