阅读背景:

为什么mysql不使用我的索引?

来源:互联网 

I have two tables:

我有两张桌子:


mysql> desc myps3t_gameusertrophyinfo;

+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| id        | int(11)      | NO   | PRI | NULL    | auto_increment |
| user_id   | int(11)      | NO   | MUL | NULL    |                |
| trophy_id | int(11)      | NO   | MUL | NULL    |                |
| date      | datetime     | NO   | MUL | NULL    |                |
| date_read | varchar(100) | NO   |     | NULL    |                |
+-----------+--------------+------+-----+---------+----------------+
5 rows in set (0.19 sec)


mysql> show index from myps3t_gameusertrophyinfo;

+---------------------------+------------+------------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table                     | Non_unique | Key_name                           | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+---------------------------+------------+------------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| myps3t_gameusertrophyinfo |          0 | PRIMARY                            |            1 | id          | A         |     4004589 |     NULL | NULL   |      | BTREE      |         |
| myps3t_gameusertrophyinfo |          0 | user_id                            |            1 | user_id     | A         |        7686 |     NULL | NULL   |      | BTREE      |         |
| myps3t_gameusertrophyinfo |          0 | user_id                            |            2 | trophy_id   | A         |     4004589 |     NULL | NULL   |      | BTREE      |         |
| myps3t_gameusertrophyinfo |          1 | myps3t_gameusertrophyinfo_403f60f  |            1 | user_id     | A         |        7686 |     NULL | NULL   |      | BTREE      |         |
| myps3t_gameusertrophyinfo |          1 | myps3t_gameusertrophyinfo_61a683d8 |            1 | trophy_id   | A         |       22624 |     NULL | NULL   |      | BTREE      |         |
| myps3t_gameusertrophyinfo |          1 | idx_gameusertrophyinfo_date        |            1 | date        | A         |     4004589 |     NULL | NULL   |      | BTREE      |         |
+---------------------------+------------+------------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
7 rows in set (0.06 sec)

mysql> desc myp



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: