Mysql's Laterowlookups (delayed row lookup) bitsCN.com
Mysql Late row lookups (delayed row lookup)
SQL code
Create table '201430122handler '(
'Id' int (11) not null AUTO_INCREMENT,
'Uid' int (11) not null,
'Content' varchar (50) not null,
Primary key ('id '),
KEY '201430122handler _ idx_uid '('uid ')
) ENGINE = InnoDB
There are 60 million data records in it. now we simulate paging by uid.
To view the content on page 7, use
SQL code
Select SQL _NO_CACHE * from 20130122 handler
Order by uid LIMIT 120,20
Finding 20 pieces of data is almost an instant task.
If the user is abnormal, click Page 102 and use
SQL code
Select SQL _NO_CACHE * from 20130122 handler
Order by uid LIMIT 2020,20
Search for 20 pieces of data and find that the performance is quite poor.
It seems that mysql reads 2040 secondary records from the 20130122handler_idx_uid index in this case,
Then, the system executes 2040 primary key queries and returns 20 results. Therefore, 2020 primary key queries are wasted.
This method can be used to reduce useless row lookup.
SQL code
Select SQL _NO_CACHE m. * from (
Select uid from 20130122 handler
Order by uid LIMIT 2020,20) t, 20130122 handler m
Where t. uid = m. uid
This is because 20130122handler_idx_uid is a secondary index, so row lookup is required.
Used
SQL code
Select SQL _NO_CACHE * from 20130122 handler
Order by id LIMIT 120,20
Select SQL _NO_CACHE * from 20130122 handler
Order by id LIMIT 2040,20
The difference is not obvious.
BitsCN.com