Mysql Limit optimization scheme analysis

 

There are 150000000 pieces of data in the table mytable for testing

The time data results of LIMIT 30000 are as follows:

SELECT id
FROM mytable
ORDER BY
id
LIMIT 30000, 10

about 52ms

SELECT *
FROM mytable
ORDER BY
id
LIMIT 30000, 10

about 140ms

140/52=3 (2 to 3 times faster)

The time data results of LIMIT 300000 are as follows:

SELECT id
FROM mytable
ORDER BY
id
LIMIT 300000, 10

about 156ms

SELECT *
FROM mytable
ORDER BY
id
LIMIT 3000000, 10

about 1297ms

1297/156 = 9 (9-10 times faster)

The time data results of LIMIT 3000000 are as follows:

 

11918/1247 = 9 (speed provides 9-10 times)

It can be roughly estimated that when the ID method is used for optimization, the speed can be increased by about 10 times when the LIMIT reaches the level of 100,000 and millions.

SELECT t.*
FROM (
SELECT id
FROM mytable
ORDER BY
id
LIMIT 10000, 10
) q
JOIN mytable t 
ON t.id = q.id

 

You can see the article

https://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325462356&siteId=291194637