Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.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索引不能在更高的限制下工作_Mysql_Query Optimization_Primary Key - Fatal编程技术网

Mysql索引不能在更高的限制下工作

Mysql索引不能在更高的限制下工作,mysql,query-optimization,primary-key,Mysql,Query Optimization,Primary Key,我有一个包含一个主键的表。 当我跑的时候 解释按id ASC限制从新闻订单中选择*29 Mysql返回 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE news ALL NULL NULL NULL NULL 640 Using filesort

我有一个包含一个主键的表。 当我跑的时候

解释按id ASC限制从新闻订单中选择*29

Mysql返回

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra
1   SIMPLE           news    ALL      NULL           NULL    NULL      NULL     640     Using filesort
但是通过解释选择* 来自新闻 按id订购ASC 限制28 它回来了

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra
1   SIMPLE          news    index   NULL           PRIMARY  4          NULL     28   
显示新闻索引

Table, Non_unique, Key_name, Seq_in_index, Column_name, Collation, Cardinality, Sub_part, Packed, Null, Index_type, Comment  
'news', 0, 'PRIMARY', 1, 'id', 'A', 640, , '', '', 'BTREE', ''
'news', 1, 'tarix', 1, 'tarix', 'A', 106, , '', '', 'BTREE', ''
'news', 1, 'yayindil', 1, 'yayin', 'A', 3, , '', '', 'BTREE', ''
'news', 1, 'yayindil', 2, 'dil', 'A', 7, , '', '', 'BTREE', ''

我在其他桌子上检查过了,它们也可以正常工作,限制在4000。出什么事了?为什么只有在29个限制下才使用索引?

优化者试图选择最便宜的执行路径。由于表中只有640行,因此优化者选择完全扫描并不奇怪。加载包含40000行的表,您会发现在选择完整表扫描之前必须增加限制(可能到2000行左右)。

该表有多少行?两个表中的索引相似吗?查看
show index from news
output。真奇怪,您确定要查询吗?请尝试使用“`I add show index from news;通过编辑我的帖子。更改限制值会影响关键值。所有大于28的限制计数都无法使用索引?这很奇怪,但鉴于行的数量(640),至少这并不意味着性能不好。