前言:
在mysql生成千万级的测试数据这一章节中,我们生成了一张千万级的数据表.
索引的优化对于数据库查询优化而言是最有效的手段.
为了验证索引优化的威力,我们做了下面一个demo.
1.表未添加索引之前的效果
mysql> explain select * from card where card_id=9999999;
+----+-------------+-------+------+---------------+------+---------+------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+---------+-------------+
| 1 | SIMPLE | card | ALL | NULL | NULL | NULL | NULL | 9703851 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+---------+-------------+
1 row in set (0.00 sec)
mysql> select * from card where card_id=9999999;
+---------+--------------------------------------+
| card_id | card_number |