ORACLE常用hint记录【不断更新中】

HINT在判断SQL性能问题时,有时会启一个快捷作用,是一个调优SQL强大工具

1./*+ driving_site(table)  */ --将过滤的条件于远端完成再传过来,如在A服务器上过滤再将结果传到B服务器上,原则是哪个表数据小就将它与远端大表匹配再将结果返回;

2./*+ index(t idx_id) */--指定索引

3./*+ append */ --数据直接插入到高水位上面(与insert连用),外加并行/*+ append parallel(table,4) */

4./*+ index(view.t1 idx_name) */ --对视图中的基表进行指定走索引

5./*+ parallel(table,4) */eg. select /*+ parallel(t1,4) */ * from  t1;并发执行前加alter session enable parallel dml;

注意:当使用HINT时如果结果集不完整或有错,优化器将忽略它;

6.优化器相关

alter system set optimizer_mode=first_rows(all_rows) --系统级别设置,也可在会话级别session

select  /*+ first_rows(20) */ * from t1 where id<20; --CBO模式

select  /*+ all_rows */ * from t1 where id<20; --CBO模式

-在SQL中使用HINT的优先级要高于optimizer_mode的参数设定;

select  /*+ rule */ * from t1;  --RBO优化器模式

7.访问路径相关的hint

包含:cluster,full,hash,index,no_index,index_asc,index_desc,index_combine,index_join,index_ffs,index_ss,index_ss_asc,index_ss_desc,no_index_ffs,no_index_ss,ordered,leading,use_hash,no_use_hash;

select  /*+ full(t1) */ * from t1;--全表扫描

select  /*+ index(t1 idx_name) */ * from t1 where object_id>2;使用指定索引

select  /*+ no_index(t1 idx_name) */ * from t1 where object_id>2; --不使用指定索引

select  /*+ index_desc(t1 idx_name) */ * from t1 where object_id=2; --按索引降序顺序访问数据

select /*+ index_combine(t1 idx_name) */ * from t1;--选择位图索引

select /*+ index_ffs(t1  idx_name) */ from t1 where object_id <100; --索引快速全表扫描(把索引当作一个表看待)

select /*+ index_join(t1 idx_name1 idx_name2) */ * from t1 where object_id=5 and status='VALID'; --同时使用条件列上的相关索引

select /*+ index_ss(t1 index_name) */ * from t1 where object_id=99;  --跳跃式扫描

select /*+ leading(t1,t) */ t.* from t,t1 where t1.object_id=t.object_id; --指定t1为驱动作,优化器先访问此表

select /*+ ordered */ t.* from t,t1 where t1.id=t.id;   --指定按from 后面表的顺序选择驱表,t作为驱动表

select /*+ use_nl(t1,t) */ t.* from t1,t where t1.object_id=t.object_id;--使用NEST LOOP表连接,适合含有小表数据关联,如一大一小

select /*+ use_hash(t1,t) */ t.* from t1,t where t1.object_id=t.object_id;--使用HASH表连接,适合两个大表关联

select /*+ use_merge(t1,t) */t.* from t1,t where t1.object_id=t.object_id;--使用合并排序表连接

select /*+ no_use_nl(t1,t) */ t.* from t1,t where t1.object_id=t.object_id; --不使用NEST LOOP表连接

select /*+ no_use_hash(t1,t) */ t.* from t1,t where t1.object_id=t.object_id;--不使用HASH表连接

select /*+ no_use_merge(t1,t) */t.* from t1,t where t1.object_id=t.object_id; --不使用合并排序表连接


8.并行相关hint

select /*+ parallel(t 4) */ count(*) from t1; --开启表的4个并行度

select /*+ no_parallel(t) */ count(*) from t1; --不使用并行

表默认的degree(user_tables)如果不为0,默认开启并行针对select;

9.其它hint

select /*+ dynamic_sampling(t 4) */ * from t where id>134;--4为采样级别

select /*+ full(t1) cache(t1) */ object_id from t1;--将表t1放在LRU端最活跃处,相当于表属性的cache(keep);

--以上大部份资料来源于谭怀远《让ORACLE跑得更快》学习












你可能感兴趣的:(ORACLE常用hint记录【不断更新中】)