Get the App
SLTechnology News&Howtos  ›  Database  › 

Optimization of COUNT (*) by InnoDB under MySQL 5.7

Shulou Source: shulou.com Published: 2022-06-01 14:05:43 09月30日 Update

In MySQL 5.7COUNT (), the total number of tables can be quickly obtained by selecting a clustered index and making an internal handler function call.

The execution plan shows: Extra:Select tables optimized away

In previous versions, the COUNT () request would normally be: scan the normal index to get this total.

6. The execution plan shows: Extra:Using index

If the clustered index is large (or the table has a large amount of data) and is not fully loaded into the buffer pool, the query mode of MySQL 5.7may be slower instead of using the original way (MySQL 5.6)

Solution: force the general index, but you still need to add WHERE conditions, otherwise it will not work.

Select count () from stock force index (idx_stock) where id > 0

Extra:using where,using index

Tags: Index normal large total method no function method data condition version or mandatory query select Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MySQL Xiaomi Redmi Microsoft