Get the App
SLTechnology News&Howtos  ›  Database  › 

High ratio of rows returned to index

Shulou Source: shulou.com Published: 2022-06-01 07:48:45 10月02日 Update

In MySQL, the number of rows returned by the query exceeds 20% of the total number of rows, and the execution plan will not take the index. Let's look at an example to query information with an id greater than 1.

Click (here) to collapse or open

Mysql > explain select * from test06 where id > 1

+-- +

| | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

+-- +

| | 1 | SIMPLE | test06 | ALL | idx_test03_id | NULL | NULL | NULL | 2009559 | Using where |

When the proportion of returned rows is high, the optimizer thinks that full table scanning saves time. Indexes are not used.

Tags: Ratio index query example information head line time time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL NVidia Shulou Technology Docker