SQL PROFILE使用简单,不区分大小写,回车,空格,但是对DBA写HINT的能力要求比较高,因为SQL PROFILE要求HINT必须写明查询块名,
SQL PROFILE还有其他一些牛逼的特性。
我的示例里教了大家偷懒的做法,但是有时间我们还是最好认真把query block的东西学下。
Create table LX_DB as select * from dba_objects;
create index idx_lxdb_id on LX_DB(object_id);
步骤二-------------------------查看SQL默认执行计划,走了索引
explain plan for select * from LX_DB where object_id= :a;
select * from table(dbms_xplan.display(null,null,'outline'));-------------------通过指定outline可以获取到系统为我们生成的hint
-----------------------------------------------
| Id | Operation | Name |
-----------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | TABLE ACCESS BY INDEX ROWID| LX_DB |
|* 2 | INDEX RANGE SCAN | idx_lxdb_id |
-----------------------------------------------
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
INDEX_RS_ASC(@"SEL$1" "LX_DB"@"SEL$1 " ("LX_DB"."OBJECT_ID"))
OUTLINE_LEAF(@"SEL$1")
ALL_ROWS
DB_VERSION('11.1.0.7')
OPTIMIZER_FEATURES_ENABLE('11.1.0.7')
IGNORE_OPTIM_EMBEDDED_HINTS
END_OUTLINE_DATA
*/
步骤3-------------------------如果我们想让它走全表扫描,获取全表扫描HINT
explain plan for select /*+ full(LX_DB) */* from LX_DB where object_id= :a;-----------增加HINT
select * from table(dbms_xplan.display(null,null,'outline'));------------可以看到全表扫描的hint已经为我们生成了,我们选取必要的hint就OK了,其他的可以不要
-------------------------------------
| Id | Operation | Name |
-------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | TABLE ACCESS FULL| LX_DB |
-------------------------------------
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
FULL(@"SEL$1" "LX_DB"@"SEL$1 ")
OUTLINE_LEAF(@"SEL$1")
ALL_ROWS
DB_VERSION('11.1.0.7')
OPTIMIZER_FEATURES_ENABLE('11.1.0.7')
IGNORE_OPTIM_EMBEDDED_HINTS
END_OUTLINE_DATA
*/
步骤4--------------------------使用sql profile
declare
v_hints sys.sqlprof_attr;
begin
v_hints := sys.sqlprof_attr('FULL(@"SEL$1" "LX_DB"@"SEL$1")' ); ----------从上面Outline Data部分获取到的HINT
dbms_sqltune.import_sql_profile('select * from LX_DB where object_id= :a', ----------SQL语句部分
v_hints,
'LX_DB', --------------------------------PROFILE 的名字
force_match => true);
end;
/
步骤五-------------------------查看是否生效,已经生效了
explain plan for select * from LX_DB where object_id= :a;
select * from table(dbms_xplan.display(null,null,'outline'));-
--------------------------------------
| Id | Operation | Name |
--------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | TABLE ACCESS FULL| LX_DB |
--------------------------------------
Note
-----
- SQL profile "LX_DB" used for this statement
**********本博客所有内容均为原创,如有转载请注明作者和出处!!!**********
Name: guoyJoe
QQ: 252803295
Email: oracledba_cn@hotmail.com
Blog: http://blog.csdn.net/guoyJoe
ITPUB: http://www.itpub.net/space-uid-28460966.html
OCM: http://education.oracle.com/education/otn/YGuo.HTM
_____________________________________________________________
加群验证问题:哪些SGA结构是必需的,哪些是可选的?否则拒绝申请!!!
答案在:http://blog.csdn.net/guoyjoe/article/details/8624392
Oracle@Paradise 总群:127149411
Oracle@Paradise No.1群:177089463(已满)
Oracle@Paradise No.2群:121341761
Oracle@Paradise No.3群:140856036