找出冗余索引

找出冗余索引

​ 最左原则 :例如表 A 有 3 个索引, index1(a,b),index2(a),index3(b)。index1(a,b) 最左边第一个字段包含了 index2,所以 index2 是冗余的索引,建议删掉。

mysql> select * from sys.schema_redundant_indexes limit 1\G;
*************************** 1. row ***************************
              table_schema: sakila
                table_name: customer
      redundant_index_name: idx_fk_store_id
   redundant_index_columns: store_id
redundant_index_non_unique: 1
       dominant_index_name: idx_storeid_email
    dominant_index_columns: store_id,email
 dominant_index_non_unique: 1
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `sakila`.`customer` DROP INDEX `idx_fk_store_id`
1 row in set (0.02 sec)

mysql> show index from  sakila.customer;
+----------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table    | Non_unique | Key_name          | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+----------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| customer |          0 | PRIMARY           |            1 | customer_id | A         |         599 |     NULL | NULL   |      | BTREE      |         |               |
| customer |          1 | idx_fk_store_id   |            1 | store_id    | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
| customer |          1 | idx_fk_address_id |            1 | address_id  | A         |         599 |     NULL | NULL   |      | BTREE      |         |               |
| customer |          1 | idx_last_name     |            1 | last_name   | A         |         599 |     NULL | NULL   |      | BTREE      |         |               |
| customer |          1 | idx_email         |            1 | email       | A         |         599 |     NULL | NULL   | YES  | BTREE      |         |               |
| customer |          1 | idx_storeid_email |            1 | store_id    | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
| customer |          1 | idx_storeid_email |            2 | email       | A         |         599 |     NULL | NULL   | YES  | BTREE      |         |               |
+----------+------------+-------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
7 rows in set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值