Is MySQL slow to query for the first time?

problem description

there is a user table with

in it.
uid
regdate //
reg_package //
reg_channel //
...

now I have a SQL query for user data

SELECT * FROM `user` ORDER BY `regdate` DESC  LIMIT 0,50;

there is a multi-column index on this table. idx_regdate_reg_package_reg_channel (key_len has 202)
this SQL also uses this index (using EXPLAIN to see)

question

When

this statement is executed for the first time, the query speed of is very slow , and then it will be much faster. I am very confused here
PS:. I know that InnoDB indexes need buffering. Does it have anything to do with buffering?

The reason why

is slow does not lie in this sentence. If I made a mistake, I checked. It is select COUNT (*) FROM user that the sentence is slow


there are many caches in the database, sql parsing cache, query result cache, index cache, you say slow first, then fast, probably query result cache. You can try to change the parameters in the second query:

as for the first time

SELECT * FROM `user` ORDER BY `regdate` DESC LIMIT 0,50;

second time

SELECT * FROM `user` ORDER BY `regdate` DESC LIMIT 5,55;

see if it's slow, too?


if the amount of data is large, please do not use select *, it is recommended to use select field

Menu