Oracle之index_desc索引之排序升降
来源:互联网 发布:怎么用python画图 编辑:程序博客网 时间:2024/05/16 23:47
/*
结论:索引能够消除排序,这是之前学过的内容,但是如果排序是部分升序部分降序,就必须建对应部分升降序的索引,否则无法用这个来消除排序。
比如order by col1 desc col2 asc,我们可以建(col1 desc,col2 asc)的索引。
值得一提的是,如果你的语句变成 order by col1 asc col2 desc,之前的(col1 desc,col2 asc)的索引依然可以起到避免排序的作用DESCING。
这在之前的课程中描述过,请同学们自行复习。不要为此多建无意义的索引。
*/
drop table t purge;
create table t as select * from dba_objects where object_id is not null ;
set autotrace off
insert into t select * from t;
insert into t select * from t;
commit;
create index idx_t on t (owner,object_id);
alter table t modify owner not null;
alter table t modify object_id not null;
set linesize 1000
set autotrace traceonly
--听说order by 列有索引可以消除排序,测试发现,Oracle选择不用索引,排序依然存在,索引去哪儿?
select * from t a order by owner desc ,object_type asc;
执行计划
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 398K| 78M| | 19133 (1)| 00:03:50 |
| 1 | SORT ORDER BY | | 398K| 78M| 94M| 19133 (1)| 00:03:50 |
| 2 | TABLE ACCESS FULL| T | 398K| 78M| | 1177 (1)| 00:00:15 |
-----------------------------------------------------------------------------------
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
4209 consistent gets
0 physical reads
0 redo size
13981752 bytes sent via SQL*Net to client
215080 bytes received via SQL*Net from client
19517 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
292740 rows processed
--换个思路,建如下索引
drop index idx_t;
create index idx_t on t(owner desc,object_type asc);
--哦,索引再这,效率果然提高了,COST比未用索引导致排序的代价19133低,是14687。
select * from t a order by owner desc ,object_type asc;
执行计划
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 398K| 78M| 14687 (1)| 00:02:57 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 398K| 78M| 14687 (1)| 00:02:57 |
| 2 | INDEX FULL SCAN | IDX_T | 398K| | 1085 (1)| 00:00:14 |
-------------------------------------------------------------------------------------
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
52710 consistent gets
0 physical reads
0 redo size
13821025 bytes sent via SQL*Net to client
215080 bytes received via SQL*Net from client
19517 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
292740 rows processed
阅读全文
0 0
- Oracle之index_desc索引之排序升降
- 排序专题之索引排序
- oracle之索引
- oracle之位图索引
- oracle之索引
- Oracle笔记之索引
- oracle学习之索引
- oracle之索引分析
- Oracle之索引、权限
- Oracle之索引特点
- Oracle之索引
- Oracle之虚拟索引
- Oracle之位图索引
- oracle索引介绍之位图(bitmap)索引
- Oracle之函数索引修改,重建索引
- oracle性能优化之索引
- oracle全文索引之datastore_1_DIRECT_DATASTORE
- oracle全文索引之datastore_2_MULTI_COLUMN_DATASTORE
- code
- leetcode练习 Course Schedul
- 泛型委托
- Spring cloud oauth2 研究第N天
- springboot activemq 2 持久化消息 与 持久化订阅
- Oracle之index_desc索引之排序升降
- 常见排序算法-php 1.归并排序 $a = [1, 4, 6, 8, 10, 14, 16]; $b = [2, 3, 5, 8, 9, 11]; function merge_sort($a,
- 服务器使用Tomcat配置server.xml文件通过域名直接跳转到项目
- 数据库的发明者
- sftp error: Couldn't canonicalize
- HTTP缓存机制一二三
- 集合数据类型的操作
- cf723D 连通块
- 阿里云短信验证