Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
慢速MySQL使用where PK>;x_Mysql - Fatal编程技术网

慢速MySQL使用where PK>;x

慢速MySQL使用where PK>;x,mysql,Mysql,我有一个表,大约有500万行,结构如下: CREATE TABLE `books` ( `asin` char(10) CHARACTER SET latin1 NOT NULL, `title` varchar(512) NOT NULL, ...other fields... PRIMARY KEY (`asin`), KEY `lang` (`lang`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 我试图在上面运行一个脚本,为此我使用了“

我有一个表,大约有500万行,结构如下:

CREATE TABLE `books` (
  `asin` char(10) CHARACTER SET latin1 NOT NULL,
  `title` varchar(512) NOT NULL,
...other fields...
  PRIMARY KEY (`asin`),
  KEY `lang` (`lang`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
我试图在上面运行一个脚本,为此我使用了“select*from books where asin>X limit 10000”并记住最后一次PK

我希望这个查询会非常快,因为我是通过PK进行查询的,但是性能正在慢慢下降,现在查询需要将近1分钟的时间(在开始时通常会更好)。为什么会发生这种情况

举例说明:

mysql> explain select * from books where asin > 'B000OT86OY' limit 10000;
+----+-------------+-------+-------+---------------+---------+---------+------+---------+-------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows    | Extra       |
+----+-------------+-------+-------+---------------+---------+---------+------+---------+-------------+
|  1 | SIMPLE      | books | range | PRIMARY       | PRIMARY | 10      | NULL | 4670633 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+------+---------+-------------+

我能够通过asin ASC执行
更改表格书籍顺序来缓解这个问题。我想问题是,我的光盘上的行在物理上相距很远,因此在执行上述操作后,查询变得即时。

返回了多少行?@ad4s 10000每一次,有人能解释一下为什么可能会被否决吗?尝试限制100,如果仍然很慢,尝试使用“>”将PK更改为INT类型以执行更好的比较操作人员提供有关查询的更多信息由于您使用char作为主键,因此有一些特定的原因?