In MySQL 8.0, when querying the total number of table records, the analysis optimization of the timeout
1. An interface request response timeout, because count(*) SQL takes 54 seconds. The amount of data in the table exceeds 10 million. as shown in Figure 1
SELECT
count(*) AS AGGREGATE
FROM
`tables`
2. The table field Shipping_Type has an index to add, and its value is only 1 and 2 possibilities. Decide to add the where condition Shipping_Type in (1,2). The query time is 3 seconds. as shown in Figure 2
SELECT
count(*) AS AGGREGATE
FROM
`tables`
WHERE
shipping_type IN (
1,
2)
3. The final decision is based on the primary key ID as the WHERE condition, in order to maintain the uniformity of the WHERE conditions of all count sql. Add WHERE ID > 0 when a COUNT SQL does not exist where condition exists. It took 4 seconds, in line with expectations. as shown in Figure 3


