简体   繁体   中英

MySQL first UPDATE query is very slow, subsequent UPDATE very fast

I have a query:

Update users set Numreviews = 1 where userID = 12345

Both fields 'numreviews' and 'userID' have indexes that help unrelated SELECT queries.

The problem I am experiencing is when running the first UPDATE query. It can take up to 1 minute. When I run it seconds later for another userID it usually takes milliseconds.

This pattern is very consistent.

Any suggestions would be appreciated. This is on MySQL 5.1.11 running on Windows Server 2008 R2 Datacenter. I've tried restarting IIS many times and restarting the database also.

Maybe the the initial time is things basically waking up, connecting/handshaking etc.

It appears that this can be caused by how MySQL uses DNS . The link explains this in more detail, but basically when you first connect there is a reverse lookup when you first connect. There are a couple of ways to fix this. The easiest (assuming you are running this from an application) is to set up pooling for your application. This is good to do anyway.

You can also start your server with --skip-name-resolve , or increasing your HOST_CACHE_SIZE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM