简体   繁体   中英

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.

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??

Executing the "SELECT id, text..." again after that two queries have the same effect, never returns.

Any help is appreciated, an Innodb guru could help ;)

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.

The problem was a network problem! With no relation at all with the mysql server!

So, I found, opposed to what I always thought, that the time after each query showed by the mysql client includes the network delay . 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).

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