|
I had a perfect example of this same issue happening on my production DB. So I loaded up MonYog and watched the processlist refresh every second until I noticed a pattern. I started seeing an update query that would take about a second or two to run. When multiple people were trying to update the same table, those queries would start to get backed up and take longer to run and more and more connections would build up. I looked at what was wrong with the query and discovered that there was a composite primary key on two fields. I'll call these two fields f1 and f2. They were in the order of (f1, f2) and this is important because when you have a composite key, the order is important. The where condition was only looking at f2 which means that an index wasn't being used at all. If it would have been on f1, than the index would be used or if the where condition looked at both the index would be used. For my issue, the query needed to look at both so we simply changed it to do so and it picked up the index, which took the query down to milliseconds. Another option would have been to also add single index on f2.
|