利用函数索引优化<>
2014-02-26 20:44
309 查看
SQL> select count(*),ID from test_2 group by id; COUNT(*) ID ---------- ---------- 131072 1 1179648 2 select count(*) from test_2 where id <>2;------利用函数索引优化: select count(*) from test_2 where id <>2;SQL> SQL> select count(*) from test_2 where id <>2; Execution Plan ---------------------------------------------------------- Plan hash value: 1548797762 ----------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 3 | 801 (6)| 00:00:10 | | 1 | SORT AGGREGATE | | 1 | 3 | | | |* 2 | TABLE ACCESS FULL| TEST_2 | 655K| 1920K| 801 (6)| 00:00:10 | ----------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter("ID"<>2) Statistics ---------------------------------------------------------- 0 recursive calls 0 db block gets 3463 consistent gets 1182 physical reads 0 redo size 413 bytes sent via SQL*Net to client 385 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed 创建函数索引: create index idx2 on test_2(case when ID=2 then null else '@' end); select /*+ index(test_2 idx2) */ count(*) from test_2 where (case when ID=2 THEN NULL ELSE '@' END)='@'; select /*+ index(test_2 idx2) */ count(*) from test_2 where (case when ID=2 THEN NULL ELSE '@' END)='@'; SQL> Execution Plan ---------------------------------------------------------- Plan hash value: 2399724746 -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 3 | 242 (2)| 00:00:03 | | 1 | SORT AGGREGATE | | 1 | 3 | | | |* 2 | INDEX RANGE SCAN| IDX2 | 131K| 384K| 242 (2)| 00:00:03 | -------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access(CASE "ID" WHEN 2 THEN NULL ELSE '@' END ='@') Statistics ---------------------------------------------------------- 8 recursive calls 0 db block gets 241 consistent gets 0 physical reads 0 redo size 413 bytes sent via SQL*Net to client 385 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed 逻辑读大大降低 使用不等于优化 必须保证<>过滤后的数据占表比例数据少才可以。
相关文章推荐
- 利用函数索引优化<>
- <<Oracle数据库性能优化艺术(第五期)>> 第7周 索引和分区(包括11g下新的组合分区)
- SQL Server 重建索引|索引重组|索引的碎片检查 (MSSQL个人笔记之数据库优化之路 六<SQL2005以上>)
- <python>Python的函数参数传递:传值?引用?
- <深入浅出>根据函数调用过程谈栈回溯原理
- 关于OpenCV中利用函数cvConvert实现图像数据类型转换(8U->16S)
- 性能优化:使用SparseArray代替HashMap<Integer,Object>
- <类模板 的 成员函数的特化>及<类 的 成员模板函数的特化>
- Android最佳性能实践——布局优化技巧之<include>、<merge>标签及仅在需要时才加载布局的:ViewStub
- #include<time.h> 库函数详解
- Screensaver<用线段树维护函数系数>
- android 布局优化标签<include/>、<merge />、<ViewStub />
- <android里图片下载工具类AsyncImageLoader分析> 后续:优化
- C#中怎样将List<自己定义>转为Json格式 及相关函数-DataContractJsonSerializer
- <转>C语言中的文件输入输出函数
- <<c++ primer>> 函数指针的笔记
- <<js>>每个函数都有作用域链
- PostgreSQL学习笔记6之函数和操作符<二>
- struts2 <s:iterator/>怎样取得循环的索引?
- 二叉树的创建--(2)运算符重载<<、>>以及CreateBinaryTree、Traverse、PrintBTree函数