oracle 索引的几种方式
一、查询索引的高度
select index_name,
blevel,
leaf_blocks,
num_rows,
distinct_keys,
clustering_factor
from user_ind_statistics
where table_name in( 'T1','T2','T3');
2. 索引存储列值(可优化聚合)
2.1索引特性之存列值优化count
drop table t purge;
create table t as select * from dba_objects;
update t set object_id=rownum;
commit;
create index idx1_object_id on t(object_id);
set autotrace on
select count(*) from t;
--count无法用到
修改代码让count用到索引
select count(*) from t where object_id is not null;
修改代码让count用到索引
修改代码让count用到索引
alter table t modify OBJECT_ID not null;
select count(*) from t;
2.2主键让count用到索引
drop table t purge;
create table t as select * from dba_objects;
update t set object_id=rownum;
alter table t add constraint pk1_object_id primary key (OBJECT_ID);
set autotrace on
select count(*) from t;
2.3索引特性之存列值优化sum avg
drop table t purge;
create table t as select * from dba_objects;
create index idx1_object_id on t(object_id);
set autotrace on
set linesize 1000
set timing on
select sum(object_id) from t;
2.4sum avg不走索引的代价
select /*+full(t)*/ sum(object_id) from t;
3 索引本身有序(可优化排序)
3.1索引特性之有序优化order by
set autotrace traceonly
set linesize 1000
drop table t purge;
create table t as select * from dba_objects;
select * from t where object_id>2 order by object_id;
--无索引的order by 语句必然会排序
索引让order by 语句排序消失
create index idx_t_object_id on t(object_id);
set autotrace traceonly
select * from t where object_id>2 order by object_id;
3.2 索引特性之有序优化Max/Min
--MAX/MIN 的索引优化
drop table t purge;
create table t as select * from dba_objects;
update t set object_id=rownum;
alter table t add constraint pk_object_id primary key (OBJECT_ID);
set autotrace on
set linesize 1000
select max(object_id) from t;
MAX/MIN 语句用不到索引性能低下
select /*+full(t)*/ max(object_id) from t;
3.3 MAX/MIN 用索引与数据量增加的影响
set autotrace off
drop table t_max purge;
create table t_max as select * from dba_objects;
insert into t_max select * from t_max;
insert into t_max select * from t_max;
insert into t_max select * from t_max;
insert into t_max select * from t_max;
insert into t_max select * from t_max;
select count(*) from t_max;
create index idx_t_max_obj on t_max(object_id);
set autotrace on
select max(object_id) from t_max;
4 组合索引选用
4.1 仅等值无范围查询时,组合的顺序不影响性能
drop table t purge;
create table t as select * from dba_objects;
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
update t set object_id=rownum ;
commit;
create index idx_id_type on t(object_id,object_type);
create index idx_type_id on t(object_type,object_id);
set autotrace off
alter session set statistics_level=all ;
set linesize 366
type_id,id顺序组合索引
select /*+index(t,idx_id_type)*/ * from t where object_id=20 and object_type='TABLE';
select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));
--id、type_id顺序组合索引
select /*+index(t,idx_type_id)*/ * from t where object_id=20 and object_type='TABLE';
select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));
4.2 组合索引最佳顺序一般是将等值查询的列置前
将等值查询的列置前
select /*+index(t,idx_id_type)*/ * from t where object_id>=20 and object_id<2000 and object_type='TABLE';
select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));
将等值查询的列置后
select /*+index(t,idx_type_id)*/ * from t where object_id>=20 and object_id<2000 and object_type='TABLE';
oracle 索引的几种方式的更多相关文章
- .Net 中读写Oracle数据库常用两种方式
.net中连接Oracle 的两种方式:OracleClient,OleDb转载 2015年04月24日 00:00:24 10820.Net 中读写Oracle数据库常用两种方式:OracleCli ...
- plsql 连接oracle数据库的2种方式
plsql 连接oracle数据库的2种方式 CreationTime--2018年8月10日09点50分 Author:Marydon 方式一:配置tnsnames.ora 该文件在instan ...
- 关于ORACLE索引的几种扫描方式
------------恢复内容开始------------ ------------恢复内容开始------------ 一条sql执行的效率因执行计划的差异而影响,经常说这条sql走索引了,那条s ...
- Oracle备份的几种方式
这里使用Oracle 12C来大概演示说明一下rman的基本用法,这里不会深入讨论,因为本人也只是刚刚才接触,只是结合了网上的一些文章以及自己的实践来总结并拿出来大家学习,谢谢 目录 一.关于备份与恢 ...
- oracle 分页的两种方式
实例:查询5-8名学生的姓名与成绩 --oracle的分页1 between 方式(分三次查询,第一次只作排序,第二次给表加上rownum序列,第三次为查询结果) select s.scorenumb ...
- lucene创建索引的几种方式(一)
什么是索引: 根据你输入的值去找,这个值就是索引 第一种创建索引的方式: 根据文件来生成索引,如后缀为.txt等的文件 步骤: 第一步:FSDirectory.open(Paths.get(url)) ...
- oracle 数据库连接的四种方式
Oracle Thin JDBC Driver驱动程序包名:ojdbc14.jar.ojdbc6.jar驱动程序类名: oracle.jdbc.driver.OracleDriverJDBC URL: ...
- PHP 重置数组为连续数字索引的几种方式
原文链接:https://blog.csdn.net/zhang197093/article/details/78606916 推荐的方式 array_values 方法 这样方式无论对普通数组还是 ...
- Springboot调用Oracle存储过程的几种方式
因工作需要将公司SSH项目改为Spingboot项目,将项目中部分需要调用存储过程的部分用entityManagerFactory.unwrap(SessionFactory.class).openS ...
随机推荐
- Linux中ssh介绍与ssh+key密钥登陆部署
环境内核信息: [root@zabbix- ~]# uname -a Linux zabbix- -.el6.x86_64 # SMP Tue Mar :: UTC x86_64 x86_64 x86 ...
- 【Spring】1、Spring 中的监听器 Listener
一.接口 1.EventListener 2.HttpSessionAttributeListener 继承EventListener接口 HttpSessionAttributeListener ...
- 使用git push命令如何忽略不想提交的文件夹或者文件
如下场景是在window下的操作. 在使用node的时候有个node_modules文件夹很大,一般情况下不想提交,忽略的办法如: 方法一(来自评论区):直接在仓库根目录:执行命令echo 'node ...
- <a>标签里面直接嵌套图片,<img>下面出现一小段空白的原因
今天在写页面时,发现在a标签,里面嵌入<img>底部会出现空白的问题! 请看示例代码: <a style="border: 2px dashed blue"> ...
- 【pygame游戏编程】第二篇-----移动图像
Learning From Here import pygame import sys pygame.init() screen_width = 640 screen_high = 480 scree ...
- layui 图片上传+表单提交+ Spring MVC
Layui 的上传是最常用的, 不可或缺, 记录一下代码, 以后复制都能用!! 1.前端HTML: <div class="layui-form-item"> < ...
- BZOJ3413: 匹配(后缀自动机 线段树合并)
题意 题目链接 Sol 神仙题Orz 后缀自动机 + 线段树合并... 首先可以转化一下模型(想不到qwq):问题可以转化为统计\(B\)中每个前缀在\(A\)中出现的次数.(画一画就出来了) 然后直 ...
- 【读书笔记】iOS-开发者证书
虽然使用通配符听起来很赞,但问题是使用这种App ID的应用无法使用苹果的Push Notification服务以及应用内支付服务. 如果你有钱的话,建议单独买一个设备用于开发,将来你可能会安装iOS ...
- JavaScript长时间未操作自动退出登录
主要是通过mouseover 来监听有没有进行当前页面操作,通过未操作时间和设定退出的时间做比较,从而退出登录. var oldTime = new Date().getTime(); var new ...
- CentOS7:解决Packagekit占用yum问题
首先: vim /etc/yum/pluginconf.d/langpacks.conf 将第一行:enable=1改为enable=0 然后执行一下yum命令,发现还会占用,杀死线程即可.