当前位置:   article > 正文

orcale索引

orcale索引

数据

-- 创建表 t_index_test
drop table t_index_test;
create table t_index_test
(
    id   number,
    name varchar2(30)
);
-- 插入数据
begin
    for i in 1 .. 10000000
        loop
            insert into t_index_test values (i, 'dev' || i);
        end loop;
    commit;
end;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

在这里插入图片描述
登录

-- 验证性能 在虚拟机中set timing on可以开启sql执行时间检测
-- 没有索引的情况下 查询
select * from t_index_test where name = 'dev5555555';
  • 1
  • 2
  • 3

在这里插入图片描述

创建普通索引

-- 创建普通索引
-- create index 索引名 on 表名(索引字段);
create index index_test on t_index_test(name);
-- 验证性能 在虚拟机中set timing on可以开启sql执行时间检测
select * from t_index_test where name = 'dev5555555';
  • 1
  • 2
  • 3
  • 4
  • 5

在这里插入图片描述

唯一索引

-- 创建索引的字段必须数据不可重复(主键)
-- create unique index 索引名 on 表名(索引字段);
create unique index index_test2 on t_index_test(id);
-- 验证性能
select * from t_index_test where id = 5555555;
  • 1
  • 2
  • 3
  • 4
  • 5

在这里插入图片描述

复合索引

-- 复合索引
create index index_test3 on t_index_test (id, name);
-- 验证性能
select * from t_index_test
where name = 'dev5555555' and id = 5555555;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/892757
推荐阅读
相关标签
  

闽ICP备14008679号