简单查询导致高数据库CPU使用率

I have the following simple MySQL query:

SELECT COUNT(*) FROM images WHERE path LIKE '%/path/to/image.jpg'

The field path has an index. Table has about 500,000 records.

Although the query takes less than a millisecond to execute, I am watching the CPU usage for MySQL ratchet higher and higher in the process list even though this is the only query. Eventually it climbs to 99%.

The only other thing the script does is increment a simple counter and then delete a file if the corresponding entry doesn't exist in the database.

The PHP code itself only uses a tiny bit of the CPU (0.3%) according to profiling.

I tried dropping it down to only do the first 5,000, but the script never finishes. I just see a blank page despite buffer flushes that are supposed to show me the progress every 25 records.

What could cause this sort of MySQL CPU usage increase over the same sort of super simple query?

查看全部
duanli6834
duanli6834
2013/11/15 23:14
  • php
  • mysql
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复