Pergunta

I have mysql (5.7) innodb table, and run a select query and using an Id foreign key. for the first query on this Id foreign key condition, the query took a lot of time to execute, and If I run another condition on select with the same id foreign key, it run so fast.

Why is that so? and how could I optimize my queries select to run fastely in the first execution?

Foi útil?

Solução

No, you cannot optimize a query to run as fast on the first run as on the second. This is because during the first run the database caches information in the system. The second time it is run, if the information is still in the cache, then the database will reuse that info to make the second query faster.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a dba.stackexchange
scroll top