Mysql优化(3) 索引优化

2021/7/19 19:05:48

本文主要是介绍Mysql优化(3) 索引优化,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

 

下面我们为表t2创建一个索引:

[SQL] 纯文本查看 复制代码
001 002 003 004 005 006 007 008 009 010 011 mysql> create index in_id on t2(id); Query OK, 0 rows affected (0.01 sec) Records: 0  Duplicates: 0  Warnings: 0   mysql> show index from t2; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | t2    |          1 | in_id    |            1 | id          | A         |        NULL |     NULL | NULL   | YES  | BTREE      |         | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ 1 row in set (0.00 sec)


并插入1000万行的数据。

然后再用:

[SQL] 纯文本查看 复制代码
001 explain select * from t2 where id=1;


或者

[SQL] 纯文本查看 复制代码
001 desc select * from t2 where id=1;


查询其影响行数。决定其是否需要优化

http://www.sodu666.com/ZhuShenQi/

http://tieba.sodu666.com/

 



这篇关于Mysql优化(3) 索引优化的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程