简体   繁体   English

MySql Innodb表奇怪的SELECT锁/超时

[英]MySql Innodb table strange SELECT lock / timeout

I'm having a strange problem with a SELECT in an Innodb table, it never returns, I waited more than two hours to see if I get the results but no, still waiting. 我在Innodb表中的SELECT遇到了一个奇怪的问题,它永远不会返回,我等待了两个多小时,看看是否能得到结果,但仍然等待。

CREATE TABLE `example` (
  `id` int(11) NOT NULL,
  `done` tinyint(2) NOT NULL DEFAULT '0',
  `agent` tinyint(4) NOT NULL DEFAULT '0',
  `text` varchar(256) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `da_idx` (`done`,`agent`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |

The query that I can't obtain the results is: 我无法获得结果的查询是:

SELECT id, text FROM example WHERE done = 0 AND agent = 0 LIMIT 120;

First I thought in some index optimization or lock problem, I was some time researching that but then I found this: 首先,我想到了一些索引优化或锁定问题,我花了一些时间对此进行研究,但后来发现了这一点:

SELECT id FROM example WHERE done = 0 AND agent = 0 LIMIT 120;
...
...
...
120 rows in set (0.27 sec)


SELECT text FROM example WHERE done = 0 AND agent = 0 LIMIT 120;
...
...
...
120 rows in set (0.83 sec)

Now I'm lost, how obtaining id or text column separately with the exactly same query (same WHERE and LIMIT) works perfect and then obtaining both of them not?? 现在我迷路了,如何使用完全相同的查询(相同的WHERE和LIMIT)分别获取id或text列是完美的,然后又不能同时获取它们呢?

Executing the "SELECT id, text..." again after that two queries have the same effect, never returns. 在两个查询具有相同的效果之后,再次执行“ SELECT id,text ...”,再也不会返回。

Any help is appreciated, an Innodb guru could help ;) 感谢任何帮助,Innodb专家可以帮助您;)

Added information: Doesn't look like a transaction lock problem, look at the exponential increase of the response times for the next queries: 补充信息:看起来不像是事务锁定问题,请查看下一个查询的响应时间呈指数增长:

SELECT id, text FROM example WHERE done = 0 AND agent = 0 limit 109;
...
109 rows in set (0.31 sec)

SELECT id, text FROM example WHERE done = 0 AND agent = 0 limit 110;
...
110 rows in set (3.98 sec)

SELECT id, text FROM example WHERE done = 0 AND agent = 0 limit 111;
...
111 rows in set (4 min 5.00 sec)

I found the solution to my own question and I want to share here because it was quite strange, at least for me. 我找到了自己问题的解决方案,我想在这里分享,因为这很奇怪,至少对我而言。

I always thought that the time delay that the mysql client returns after each query (for example "120 rows in set (0.27 sec)") was the time that takes to the mysql server to generate that result, but not. 我一直认为,mysql客户端在每次查询后返回的时间延迟(例如“设置的120行(0.27秒)”)是mysql服务器生成该结果所花费的时间,但是不是。

The problem was a network problem! 问题是网络问题! With no relation at all with the mysql server! 与mysql服务器毫无关系!

So, I found, opposed to what I always thought, that the time after each query showed by the mysql client includes the network delay . 因此,与我一直想的相反,我发现mysql客户端显示的每个查询之后的时间包括网络延迟 The same requests at the same time from a server in the same datacenter as the mysql server and another from another country returns a different time(considerabily different). 来自与mysql服务器位于同一数据中心的同一服务器上的同一时间所发出的相同请求,以及来自另一个国家/地区的另一个服务器所发出的相同请求,将返回不同的时间(相差很大)。

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

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