美文网首页
sql自学笔记(十四)——MySQL8.0版本的新特性(四)

sql自学笔记(十四)——MySQL8.0版本的新特性(四)

作者: itczt | 来源:发表于2019-05-02 11:01 被阅读0次

优化器索引

  • 隐藏索引
  • 降序索引
  • 函数索引

隐藏索引

  • MySQL8.0开始支持隐藏索引(invisible index),不可见索引。
  • 隐藏索引不会被优化器使用,但仍然需要进行维护。
  • 应用场景:软删除,灰度发布。

新版本对应隐藏索引的使用情况

进入测试数据库
use testdb;
创建一张测试表
create table t1(i int, j int);
在这两个字段上分别创建两个索引
create index i _ idx on t1(i);//普通索引
creste index j _ idx on t1(j) invisible;//隐藏索引
查看一下
shhow index from t1\G

查询优化器对索引的默认使用情况
explan select * from t1 where i = 1; 
explan select * from t1 where j = 1; 

通过优化器看见隐藏索引
查询优化器的开关

select @@oaptimizer _ switch\G 
打开之后再来查询
explain select * from  t1 where j = 1;

设置索引的可见或不可见

alter table t1 alter index i _ idx visible; 置为不可见
alter table t1 alter index j _ idx invisible;
MySQL限定了对主键的不可见
create table t2(i int not null);
尝试一下对tablele t2 设置不可见的主键
alter table t2 add primary key pk _ t2(i)invisbie;

相关文章

网友评论

      本文标题:sql自学笔记(十四)——MySQL8.0版本的新特性(四)

      本文链接:https://www.haomeiwen.com/subject/pnognqtx.html