在索引列上运行一个简单的查询,但它需要超过 500 毫秒。这些查询经常运行,因此它在很大程度上影响了性能。
表中只有不到 1M 行,一个非常简单的表。使用 MyISAM。我不明白为什么它要检查所有行,好像它忽略了索引!我尝试在该字段上添加第二个索引,一个普通的索引而不是唯一索引,没有任何区别。感谢您的关注。
# Time: 130730 22:00:07
# User@Host: engine[engine] @ engine [10.0.0.6]
# Query_time: 0.511209 Lock_time: 0.000050 Rows_sent: 1 Rows_examined: 932048
SET timestamp=1375236007;
SELECT * FROM `marketplacesales`.`sales_order` WHERE `marketplace_orderid` = 823123693003;
+---------------------+-----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+-----------------------+------+-----+---------+----------------+
| id | mediumint(8) unsigned | NO | PRI | NULL | auto_increment |
| marketplace_id | smallint(5) unsigned | NO | MUL | NULL | |
| marketplace_orderid | varchar(255) | NO | UNI | NULL | |
| datetime | datetime | NO | | NULL | |
| added | datetime | NO | MUL | NULL | |
| phone | varchar(255) | YES | | NULL | |
| email | varchar(255) | YES | | NULL | |
| company | varchar(255) | NO | | NULL | |
| name | varchar(255) | NO | | NULL | |
| address1 | varchar(255) | NO | | NULL | |
| address2 | varchar(255) | NO | | NULL | |
| city | varchar(255) | NO | | NULL | |
| state | varchar(255) | NO | | NULL | |
| zip | varchar(255) | NO | | NULL | |
| country | varchar(255) | NO | | NULL | |
+---------------------+-----------------------+------+-----+---------+----------------+
EXPLAIN SELECT * FROM `marketplacesales`.`sales_order` WHERE `marketplace_orderid` = 823123693003;
+----+-------------+-------------+------+-------------------------------------------+------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------+------+-------------------------------------------+------+---------+------+--------+-------------+
| 1 | SIMPLE | sales_order | ALL | marketplace_orderid,marketplace_orderid_2 | NULL | NULL | NULL | 932053 | Using where |
+----+-------------+-------------+------+-------------------------------------------+------+---------+------+--------+-------------+
1 row in set (0.00 sec)