开发者

MySQL queries slow after a DELETE

开发者 https://www.devze.com 2023-01-08 15:28 出处:网络
I have a two part PHP script. The first that deletes some rows in the database The second that triggers SELECT queries

I have a two part PHP script.

  1. The first that deletes some rows in the database
  2. The second that triggers SELECT queries

The second script alone runs in about 开发者_如何学C0.2 sec. When both parts are processed, the second part takes 5 sec. The next time the second script runs alone, it's back to 0.2 sec.

Any clue?


Its likely that the query has cached so it runs faster the second time, more info here. If you add SQL_NO_CACHE to the query then you should be able to determine if the cache is a factor.


Your Query-Cache for a table is 'invalidated' each time the table is updated.

The result is that any UPDATE/DELETE/INSERT to your table, will clear the query-cache of that table, and force a fresh disk read for the next SELECT. The result will be a slower query.

Here's a link to the MySQL DOCs.

If your table is incredibly large, you may want to investigate MyISAM tables and a separate Key-Cache for yet better read performance. MyISAM = fast reads, fast writes, horrible concurrency for writes/udpates. InnoDB = mediocre speed for reads, good concurrency for writes/updates.

-- J Jorgenson --

0

精彩评论

暂无评论...
验证码 换一张
取 消