首页 > Linux操作系统 > Linux操作系统 > 动态SQL中hint是否失效
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
SQL> conn fantasy/oracle
已连接。
SQL> select * from test1 where tname='fantasy';
执行计划
----------------------------------------------------------
Plan hash value: 3460867755
--------------------------------------------------------------------------------
-----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-----
| 0 | SELECT STATEMENT | | 1 | 10 | 2 (0)| 00:00
:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TEST1 | 1 | 10 | 2 (0)| 00:00
:01 |
|* 2 | INDEX RANGE SCAN | TT | 1 | | 1 (0)| 00:00
:01 |
--------------------------------------------------------------------------------
-----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("TNAME"='fantasy')
SQL> select /*+ full(test1) */* from test1 where tname='fantasy';
执行计划
----------------------------------------------------------
Plan hash value: 4122059633
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 10 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST1 | 1 | 10 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("TNAME"='fantasy')
SQL> alter session set tracefile_identifier='fantasy';
会话已更改。
SQL> alter session set sql_trace=true;
会话已更改。
SQL> declare
2 v_sql varchar(500);
3 begin
4 v_sql :='select /*+ full(test1) */* from test1 where tname=''fantasy''';
5 execute immediate v_sql;
6 end;
7 /
PL/SQL 过程已成功完成。
SQL> alter session set sql_trace=false;
会话已更改。
select /*+ full(test1) */*
from
test1 where tname='fantasy'
tkprof之后发现:
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 55 (recursive depth: 1)
Rows Row Source Operation
------- ---------------------------------------------------
0 TABLE ACCESS FULL TEST1 (cr=0 pr=0 pw=0 time=7 us)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/16158219/viewspace-558030/ ,如需转载,请注明出处,否则将追究法律责任。