简体   繁体   English

MySQL的第一个UPDATE查询非常慢,随后的UPDATE非常快

[英]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. “ numreviews”和“ userID”两个字段均具有有助于无关的SELECT查询的索引。

The problem I am experiencing is when running the first UPDATE query. 我遇到的问题是在运行第一个UPDATE查询时。 It can take up to 1 minute. 最多可能需要1分钟。 When I run it seconds later for another userID it usually takes milliseconds. 当我几秒钟后为另一个userID运行它时,通常需要几毫秒。

This pattern is very consistent. 这种模式是非常一致的。

Any suggestions would be appreciated. 任何建议,将不胜感激。 This is on MySQL 5.1.11 running on Windows Server 2008 R2 Datacenter. 这是在Windows Server 2008 R2数据中心上运行的MySQL 5.1.11上。 I've tried restarting IIS many times and restarting the database also. 我尝试过多次重新启动IIS,并且也重新启动了数据库。

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 . 看来这可能是由于MySQL如何使用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 您也可以使用--skip-name-resolve启动服务器,或增加HOST_CACHE_SIZE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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