oracle 使用leading, use_nl, rownum调优
来源:互联网 发布:php网站破解工具 编辑:程序博客网 时间:2024/06/03 16:53
/*+LEADING(TABLE)*/
将指定的表作为连接次序中的首表.
/*+USE_NL(TABLE)*/
将指定表与嵌套的连接的行源进行连接,并把指定表作为内部表.
成本计算方法:
设小表100行,大表100000行。
两表均有索引:
如果小表在内,大表在外(驱动表)的话,则扫描次数为:
100000+100000*2 (其中2表示IO次数,一次索引,一次数据)
如果大表在内,小表在外(驱动表)的话,则扫描次数为:
100+100*2.
两表均无索引:
如果小表在内,大表在外的话,则扫描次数为:
100000+100*100000
如果大表在内,小表在外的话,则扫描次数为:
100+100000*100
注意:如果一个表有索引,一个表没有索引,ORACLE会将没有索引的表作驱动表。如果两个表都有索引,则外表作驱动表。如果两个都没索引的话,则也是外表作驱动表。
2、使用index直接匹配索引来查询数据提高查询速度
/*+INDEX(TABLE INDEX_NAME)*/
表明对表选择索引的扫描方法.
3、当判断某几个表中是否存在某种关系的行时可使用rownum=1来作为条件而加快速度,如果必须有多行才满足条件时,可设置rownum <= n。
例如:获得一个v_count值判断是否大于0
equipment表 几万条,controledpnsnrange 几千条
select
count(sc.pmnum)
into
v_count
from
equipment e,
sal_controledpnsnrange sc
where
(sc.new_min_item_no <= e.itemnum)
and (sc.new_max_item_no >= e.itemnum)
and (sc.new_min_serial_no <= e.serialnum)
and (sc.new_max_serial_no >= e.serialnum)
and e.itemnum = a_item_no;
执行时间大约为3分钟。
代码修改后:
select /*+ leading(e) use_nl(sc) */
count(sc.pmnum)
into
v_count
from
equipment e,
sal_controledpnsnrange sc
where
(sc.new_min_item_no <= e.itemnum)
and (sc.new_max_item_no >= e.itemnum)
and (sc.new_min_serial_no <= e.serialnum)
and (sc.new_max_serial_no >= e.serialnum)
and e.itemnum = a_item_no;
执行时间大约为45秒。
代码再次修改后:
select /*+ leading(e) use_nl(sc) */
count(sc.pmnum)
into
v_count
from
equipment e,
sal_controledpnsnrange sc
where
(sc.new_min_item_no <= e.itemnum)
and (sc.new_max_item_no >= e.itemnum)
and (sc.new_min_serial_no <= e.serialnum)
and (sc.new_max_serial_no >= e.serialnum)
and e.itemnum = a_item_no
and rownum = 1;
执行时间大约为4秒。
转自: http://www.cnblogs.com/GoDevil/archive/2008/08/29/1279439.html
- oracle 使用leading, use_nl, rownum调优
- oracle 使用leading, use_nl, rownum调优
- oracle 使用leading, use_nl, rownum调优
- oracle 使用leading, use_nl, rownum调优
- oracle 使用leading, use_nl, rownum调优
- oracle 使用leading, use_nl, rownum调优
- [转]oracle 使用leading, use_nl, rownum调优例子
- Hint&ordered&leading&use_nl
- hints ordered leading use_nl
- oracle:rownum 使用
- ORACLE的rownum使用
- oracle rownum使用小记
- oracle rownum的使用
- oracle的rownum使用
- oracle rownum 使用详解
- oracle rownum的使用
- Oracle 优化 ordered 和leading 使用
- Oracle Hint:USE_NL、USE_MERGE、USE_HASH
- 二叉树的深度
- HDU4289-Control(最小割定理)
- curl访问不需要等待返回值的情况
- iOS UITextField属性全解
- Flash Builder 4:进程意外终止。 application descriptor not found 启动命令详细信息:
- oracle 使用leading, use_nl, rownum调优
- shell 中的单引号和双引号
- spark internal - 作业调度
- 二叉树的遍历
- christian louboutin men and Deng Deng Jiaying expressed the hope that the idea of � oing his girl
- [小技巧] Notepad++关闭拼写检查
- tiffany outlet italia CD action
- abercrombie outlet causing the school attention. 16
- OC中6种多线程的使用方式