MySQL slow query - “Waiting for query cache lock”

后端 未结 2 1616
小鲜肉
小鲜肉 2020-12-14 02:35

I am running a simple query on a simple table on the same machine as the server running 5.5. It is taking 22sec to return ~7000 rows from a 20 million row table. Upon prof

相关标签:
2条回答
  • 2020-12-14 02:51

    I solved my slow query problem. To summarize the problem, it was taking 22sec to query 7000 rows from a 20mln row, 1.7GB indexed table. The problem was that the cache was too small and the query had to go to disk for every query. I would think the disk access would be faster than what I was seeing because I was going off an indexed column so the amount of data read off disk should have been small. But I'm guessing there is a lot of overhead with accessing the InnoDB storage on disk.

    Once I set innodb_buffer_pool_size=1024M in the my.ini file, the initial query would take a long time, but all subsequent queries would finish in under a second.

    Unfortunately, the profiling didn't really help.

    0 讨论(0)
  • 2020-12-14 02:56

    This is a known problem with MySQL. It's really well described here:

    https://web.archive.org/web/20160129162137/http://www.psce.com/blog/kb/how-query-cache-can-cause-performance-problems/

    Query cache can help you a lot but at the same time it can become a bottleneck.

    0 讨论(0)
提交回复
热议问题