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指定索引 解决慢查询案例
背景 每当交易高峰时期,可能会暴露一些平时无法发现的问题,机遇和挑战并存.下面聊聊最近解决的一个案例,因为执行计划走错导致慢查询,进而引发应用线程阻塞.线程池爆满,最后应用功能瘫痪.如何标本兼治的解决 ...
随机推荐
- C# 键值对排序
static void Main(string[] args) { SortedList sl = new SortedList(); sl.Add("001", "Za ...
- 从零开始 WIN8.1 下Android 开发环境搭建
一.JDK安装 当前最新版本是JDK8.0 地址http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-21331 ...
- 初学者自学笔记-this的用法
请注意:这是自学者的笔记,只是个人理解,并非技术分享,如有错误请指正. "this"的意思,简单而言,就是"这个",也就是"当前".谁调用它 ...
- storm简介[ZZ]
场景 伴随着信息科技日新月异的发展,信息呈现出爆发式的膨胀,人们获取信息的途径也更加多样.更加便捷,同时对于信息的时效性要求也越来越高.举个搜索 场景中的例子,当一个卖家发布了一条宝贝信息时,他希望的 ...
- Visual studio 2015程序转Eclipse gun编译出现的问题总结
Visual studio 2015程序转Eclipse gun编译出现的问题总结 1.C++11支持 1)Project settings project右键-> c/c++ build -& ...
- C语言基础程序设计
1 概论 程序(指令和数据的集合)在运行时,首先会被加载到内存(此时称为进程),然后由CPU通过控制器的译码从内存中读取指令,并按照指令的要求,从存储器中取出数据进行指定的运算和逻辑操作等加工,然后再 ...
- PHP 编译问题PEAR package PHP_Archive not installed的解决
php 的编译时需要依赖pear package ,目前的问题错误"PEAR package PHP_Archive not installed",已经明显报出这个问题. 因此编译 ...
- JavaScript 实现触点式弹出菜单插件
之前做项目时经常用到一种触点式弹出菜单或者导航的功能,这个功能的主要应用场景是:web页面中多层分级导航或者子功能目录,但又考虑到页面区域有限,于是就考虑到在鼠标移动到某导航按钮上或者点击时,系统将在 ...
- linq 多个left join 和 sql union all -> linq union 方法
( from s in Base_SysMenus join r in Base_RoleRights on s.Menu_Id equals r.Menu_Id into temp f ...
- JSP 结构
网络服务器需要一个JSP引擎,也就是一个容器来处理JSP页面. 容器负责截获对JSP页面的请求.本教程使用内嵌JSP容器的Apache来支持JSP开发. JSP容器与Web服务器协同合作,为JSP的正 ...