oracle hints
oracle hints
今天是2013-10-08,对于oracle hint有很多,具体可以参考联机手册:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements006.htm#BABIJGJF
http://docs.oracle.com/cd/E11882_01/server.112/e41573/hintsref.htm#PFGRF501
刚刚开始,我进行hash join连接发现如下:
SQL> select /*+use_hash(emp)*/ empno from emp,dept where dept.deptno=emp.deptno; Execution Plan
----------------------------------------------------------
Plan hash value: 716400937 -----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 140 | 1 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 14 | 140 | 1 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN | IND_EMP | 14 | 98 | 1 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN| REVERSE_INDEX | 1 | 3 | 0 (0)| 00:00:01 |
----------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 3 - access("DEPT"."DEPTNO"="EMP"."DEPTNO") SQL>
我明明指定的是emp做为驱动表然后进行hash join,但是不行,需要指定另个表,但是use_hash不能规定优化器来选择驱动表。
eg:
SQL> select /*+use_hash(emp,dept)*/ empno from emp,dept where dept.deptno=emp.deptno; Execution Plan
----------------------------------------------------------
Plan hash value: 2255485930 ----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 140 | 2 (0)| 00:00:01 |
|* 1 | HASH JOIN | | 14 | 140 | 2 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN| REVERSE_INDEX | 4 | 12 | 1 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN| IND_EMP | 14 | 98 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("DEPT"."DEPTNO"="EMP"."DEPTNO") SQL> select /*+use_hash(dept,emp)*/ empno from dept,emp where dept.deptno=emp.deptno; Execution Plan
----------------------------------------------------------
Plan hash value: 2255485930 ----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 140 | 2 (0)| 00:00:01 |
|* 1 | HASH JOIN | | 14 | 140 | 2 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN| REVERSE_INDEX | 4 | 12 | 1 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN| IND_EMP | 14 | 98 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("DEPT"."DEPTNO"="EMP"."DEPTNO") SQL>
我们可以选择使用ordered或是leading来指定optimizer选择哪个表为驱动表。
note:
The LEADING hint instructs the optimizer to use the specified set of tables as the prefix in the execution plan. This hint is more versatile than the ORDERED hint.
The LEADING hint is ignored if the tables specified cannot be joined first in the order specified because of dependencies in the join graph. If you specify two or more conflicting LEADING hints, then all of them are ignored. If you specify the ORDERED hint, it overrides all LEADING hints.
The ORDERED hint instructs Oracle to join tables in the order in which they appear in the FROM clause. Oracle recommends that you use the LEADING hint, which is more versatile than the ORDERED hint.
When you omit the ORDERED hint from a SQL statement requiring a join, the optimizer chooses the order in which to join the tables. You might want to use the ORDERED hint to specify a join order if you know something that the optimizer does not know about the number of rows selected from each table. Such information lets you choose an inner and outer table better than the optimizer could.
eg:
SQL> select /*+leading(emp) use_hash(dept,emp)*/ empno from dept ,emp where dept.deptno=emp.deptno; Execution Plan
----------------------------------------------------------
Plan hash value: 929644576 ----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 140 | 2 (0)| 00:00:01 |
|* 1 | HASH JOIN | | 14 | 140 | 2 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN| IND_EMP | 14 | 98 | 1 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN| REVERSE_INDEX | 4 | 12 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("DEPT"."DEPTNO"="EMP"."DEPTNO") SQL> select /*+leading(dept) use_hash(dept,emp)*/ empno from dept ,emp where dept.deptno=emp.deptno; Execution Plan
----------------------------------------------------------
Plan hash value: 2255485930 ----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 140 | 2 (0)| 00:00:01 |
|* 1 | HASH JOIN | | 14 | 140 | 2 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN| REVERSE_INDEX | 4 | 12 | 1 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN| IND_EMP | 14 | 98 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("DEPT"."DEPTNO"="EMP"."DEPTNO") SQL>
SQL> select /*+ordered use_hash(emp,dept)*/ empno from emp,dept where emp.deptno=dept.deptno; Execution Plan
----------------------------------------------------------
Plan hash value: 929644576 ----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 140 | 2 (0)| 00:00:01 |
|* 1 | HASH JOIN | | 14 | 140 | 2 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN| IND_EMP | 14 | 98 | 1 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN| REVERSE_INDEX | 4 | 12 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("EMP"."DEPTNO"="DEPT"."DEPTNO") SQL> select /*+ordered use_hash(emp,dept)*/ empno from dept,emp where emp.deptno=dept.deptno; Execution Plan
----------------------------------------------------------
Plan hash value: 2255485930 ----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 140 | 2 (0)| 00:00:01 |
|* 1 | HASH JOIN | | 14 | 140 | 2 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN| REVERSE_INDEX | 4 | 12 | 1 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN| IND_EMP | 14 | 98 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("EMP"."DEPTNO"="DEPT"."DEPTNO") SQL>
oracle hints的更多相关文章
- Oracle Hints详解
在向大家详细介绍Oracle Hints之前,首先让大家了解下Oracle Hints是什么,然后全面介绍Oracle Hints,希望对大家有用.基于代价的优化器是很聪明的,在绝大多数情况下它会选择 ...
- Oracle Hints具体解释
在向大家具体介绍Oracle Hints之前,首先让大家了解下Oracle Hints是什么,然后全面介绍Oracle Hints,希望对大家实用.基于代价的优化器是非常聪明的,在绝大多数情况下它会选 ...
- 普及下Oracle hints语法
普及下Oracle hints的语法:{DELETE|INSERT|SELECT|UPDATE} /*+ hint [text] [hint[text]]... */ 1.hint只能出现在诸如sel ...
- Oracle Hints详细解释
特别介绍给大家Oracle Hints之前,让我们知道下Oracle Hints什么,然后好Oracle Hints,我们希望实际.基于成本的优化器是很聪明,在大多数情况下,将选择正确的优化,减少DB ...
- 常用oracle hints
在SQL语句优化过程中,经常会用到hint, 以下是在SQL优化过程中常见Oracle中"HINT"的30个用法 1. /*+ALL_ROWS*/ 表明对语句块选择基于开销的优化方 ...
- 详解Oracle hints PQ_DISTRIBUTE
PQ_DISTRIBUTE是并行的hints中稍微复杂一点的一个 下面就这个hints做以下说明: 1.使用格式 /+ PQ_DISTRIBUTE(tablespec outer_distributi ...
- Oracle数据库基础知识
oracle数据库plsql developer 目录(?)[-] 一 SQL基础知识 创建删除数据库 创建删除修改表 添加修改删除列 oracle cascade用法 添加删除约束主键外 ...
- Oracle提示大全
Hint概述 基于代价的优化器是很聪明的,在绝大多数情况下它会选择正确的优化器,减轻了DBA的负担.但有时它也聪明反被聪明误,选择了很差的执行计划,使某个语句的执行变得奇慢无比. 此时就需要DBA进行 ...
- SQL调优 - Hints指定索引 解决慢查询案例
背景 每当交易高峰时期,可能会暴露一些平时无法发现的问题,机遇和挑战并存.下面聊聊最近解决的一个案例,因为执行计划走错导致慢查询,进而引发应用线程阻塞.线程池爆满,最后应用功能瘫痪.如何标本兼治的解决 ...
随机推荐
- oc 获取当前时间
//获取当前日期 NSDate* date = [NSDate date]; NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init]; ...
- ASP.NET Web API教程(六) 安全与身份认证
在实际的项目应用中,很多时候都需要保证数据的安全和可靠,如何来保证数据的安全呢?做法有很多,最常见的就是进行身份验证.验证通过,根据验证过的身份给与对应访问权限.同在Web Api中如何实现身份认证呢 ...
- 尝试封装自己的js库
学了js,用过jquery,然后想着让自己在js这一块有更深的提高,就想尝试着封装自己的js库,偶尔就添加自己想到的功能.有参考过其他大牛封装库的方法,不懂的地方也有借鉴过,但代码还是自己想,自己理解 ...
- java中关于static的小知识
static能够修饰属性和方法.凡是static修饰的方法和属性都是和类的关系较大,都在加载的时候要特殊处理(包括属性和类的优先加载).下面比较下static修饰属性和方法时的区别: 一.修饰属性的时 ...
- C++资源之不完全导引 (转载)
C++资源之不完全导引(完整版)- - 这文章太强了,我一定要转载,否则对不起观众,对不起自己.(liigo) 发信人: NULLNULL (空空), 信区: VC标 题: C++资源之不完全导引( ...
- Java学习----类的组织(包)
1.包的概念 javac Engine.java -d . package:打包,把类文件编译成class文件会把Engine.class 放到com/cindy/pkg1/目录下 运行Engine ...
- php5下载,apache2.4与php5整合
step1 php5下载 百度“php下载”,找到php官网 2. 点进去,选择windows downloads 3. 同样,X86对应32位,X64对应64位,Non Thread Safe是非线 ...
- silverlight中DataGrid数据高亮显示
效果如图所示, <UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.W ...
- WPF之application对象
WPF:Application简介 Application是一个地址空间,在WPF中应用程序就是在System.Windows命名空间下的一个Application实例.一个应用程序只能对应一个App ...
- URL encode 与 URL decode 的C语言实现
转载自:http://blog.csdn.net/langeldep/article/details/6264058 本文代码为从PHP代码中修改而来,只保留了2个函数. int php_url_de ...