1、/*+ FULL(TABLE)*/
表明对表选择全局扫描的方法.
SELECT /*+FULL(A)*/ EMP_NO,EMP_NAM FROM BSEMPMS A WHERE EMP_NO='SCOTT';
2、/*+ INDEX(TABLE INDEX_NAME) */
表明对表选择索引的扫描方法.
SELECT /*+INDEX(BSEMPMS SEX_INDEX) */ * FROM BSEMPMS WHERE SEX='M';
在多表关联查询中,指定哪个表作为驱动表,即告诉优化器首先要访问哪个表上的数据。
select /*+ leading(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ order */
让Oracle根据from后面表的顺序来选择驱动表,oracle建议使用leading,他更为灵活
select /*+ order */ t.* from t,t1 where t.id=t1.id;
/*+ use_nl(table_1,table_2) */
在多表关联查询中,指定使用nest loops方式进行多表关联。
select /*+ use_nl(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ use_nl(table_1,table_2) */
在多表关联查询中,指定使用nest loops方式进行多表关联。
select /*+ use_nl(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ use_hash(table_1,table_2) */
在多表关联查询中,指定使用hash join方式进行多表关联。
表明对表选择全局扫描的方法.
SELECT /*+FULL(A)*/ EMP_NO,EMP_NAM FROM BSEMPMS A WHERE EMP_NO='SCOTT';
2、/*+ INDEX(TABLE INDEX_NAME) */
表明对表选择索引的扫描方法.
SELECT /*+INDEX(BSEMPMS SEX_INDEX) */ * FROM BSEMPMS WHERE SEX='M';
在多表关联查询中,指定哪个表作为驱动表,即告诉优化器首先要访问哪个表上的数据。
select /*+ leading(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ order */
让Oracle根据from后面表的顺序来选择驱动表,oracle建议使用leading,他更为灵活
select /*+ order */ t.* from t,t1 where t.id=t1.id;
/*+ use_nl(table_1,table_2) */
在多表关联查询中,指定使用nest loops方式进行多表关联。
select /*+ use_nl(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ use_nl(table_1,table_2) */
在多表关联查询中,指定使用nest loops方式进行多表关联。
select /*+ use_nl(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ use_hash(table_1,table_2) */
在多表关联查询中,指定使用hash join方式进行多表关联。
select /*+ use_hash(t,t1) */ t.* from t,t1 where t.id=t1.id;
在多表关联查询中,指定使用hash join方式进行多表关联,并指定表t为驱动表。
select /*+ use_hash(t,t1) leading(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ use_merge(table_1,table_2) */
在多表关联查询中,指定使用merge join方式进行多表关联。
select /*+ use_merge(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ no_use_nl(table_1,table_2) */
在多表关联查询中,指定不使用nest loops方式进行多表关联。
select /*+ no_use_nl(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ no_use_hash(table_1,table_2) */
在多表关联查询中,指定不使用hash join方式进行多表关联。
select /*+ no_use_hash(t,t1) */ t.* from t,t1 where t.id=t1.id;
/*+ no_use_merge(table_1,table_2) */
在多表关联查询中,指定不使用merge join方式进行多表关联。
select /*+ no_use_merge(t,t1) */ t.* from t,t1 where t.id=t1.id;
其他常用的hint
/*+ parallel(table_name n) */
在sql中指定执行的并行度,这个值将会覆盖自身的并行度
select /*+ parallel(t 4) */ count(*) from t;
/*+ no_parallel(table_name) */
在sql中指定执行的不使用并行
select /*+ no_parallel(t) */ count(*) from t;
/*+ append */以直接加载的方式将数据加载入库
insert into t /*+ append */ select * from t;
/*+ dynamic_sampling(table_name n) */
设置sql执行时动态采用的级别,这个级别为0~10
select /*+ dynamic_sampling(t 4) */ * from t where id > 1234
/*+ cache(table_name) */
进行全表扫描时将table置于LRU列表的最活跃端,类似于table的cache属性
select /*+ full(employees) cache(employees) */ last_name from employees
OO(794585540) 21:10:29
重新收集统计信息就走hash了?
程程(604178834) 21:10:38
不晓得啊 明儿我在收集下统计信息
小水(994936894) 21:10:43
爱吃橙子(511040854) 21:11:11
select /*+ dynamic_sampling(t 4) */ * from t where id > 1234
爱吃橙子(511040854) 21:12:39
select /*+ dynamic_sampling(t 4) */ * from t where id > 1234
程程(604178834) 21:13:54
这句话收集统计信息 会影响其他表统计信息吗?
爱吃橙子(511040854) 21:14:05
/*+NO_MERGE(TABLE)*/
对于有可合并的视图不再合并.
例如:
SELECT /*+NO_MERGE(V) */ A.EMP_NO,A.EMP_NAM,B.DPT_NO FROM BSEMPMS A (SELECT DPT_NO,AVG(SAL) AS AVG_SAL FROM BSEMPMS B GROUP BY DPT_NO) V WHERE A.DPT_NO=V.DPT_NO AND A.SAL>V.AVG_SAL;
Plan hash value: 1516306995
---------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1364 | 454K| 52803 (1)| 00:10:34 |
|* 1 | VIEW | | 1364 | 454K| 52803 (1)| 00:10:34 |
|* 2 | WINDOW SORT PUSHED RANK | | 1364 | 98K| 52803 (1)| 00:10:34 |
|* 3 | HASH JOIN | | 1364 | 98K| 52802 (1)| 00:10:34 |
|* 4 | INDEX FAST FULL SCAN | PK_FA_DOCANALYSTRELA | 1364 | 15004 | 598 (3)| 00:00:08 |
| 5 | TABLE ACCESS BY INDEX ROWID| DOC_RESEARCHREPORTCORE | 71696 | 4410K| 52204 (1)| 00:10:27 |
|* 6 | INDEX RANGE SCAN | IND_DOC_RSCHDR7 | 71696 | | 288 (1)| 00:00:04 |
---------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ROWN"=1)
2 - filter(ROW_NUMBER() OVER ( PARTITION BY "FD"."ANALYSTID" ORDER BY
INTERNAL_FUNCTION("DR"."DOCTIME") DESC )<=1)
3 - access("FD"."DOCID"="DR"."OBJID")
4 - filter("FD"."ANALYSTID"=115733 OR "FD"."ANALYSTID"=122765 OR "FD"."ANALYSTID"=127452 OR
"FD"."ANALYSTID"=127458 OR "FD"."ANALYSTID"=127459 OR "FD"."ANALYSTID"=127614 OR
"FD"."ANALYSTID"=128072 OR "FD"."ANALYSTID"=128175 OR "FD"."ANALYSTID"=128207 OR
"FD"."ANALYSTID"=128358)
6 - access("DR"."DOCTIME">SYSDATE@!-90)
程程(604178834) 21:16:31
恩恩
贰小喵(624473797) 21:16:30
回去恶补。。。
OO(794585540) 21:16:32
贰小喵(624473797) 21:16:38
Waiting(296966488) 21:16:39
88
lizzie(522976851) 21:16:39
O(∩_∩)O哈哈~(335032569) 21:16:39
程程(604178834) 21:16:43
辛苦橙子了
O(∩_∩)O哈哈~(335032569) 21:16:45
Waiting(296966488) 21:16:48
继续啃书
小水(994936894) 21:16:54
木有啦 这么快
贰小喵(624473797) 21:17:02
原来橙子。。。是个男的,,,,,,,,,
小水(994936894) 21:17:03
辛苦橙子
Waiting(296966488) 21:17:10
爱吃橙子(511040854) 21:17:11
恩 今天就写HINT 一个写法注意的
对了 当有表别名的时候
写HINT时候 一定要写表别名
不要写表原本的名字 这样会失效的
OO兄深有体会哈
﹎往事如煙℡.<l5201314hebin@qq.com> 21:17:59
程程(604178834) 21:18:05
OO(794585540) 21:18:06
是啊 下午没写别名 怎么都不走hash
翠花上酸菜<zk554766446@qq.com> 21:18:06
今晚不是落落上课?
爱吃橙子(511040854) 21:18:53
恩 你上课吧哈
快乐(750670860) 21:19:26
菜花在培训二群
小水(994936894) 21:19:39
快乐(750670860) 21:19:39