oracle實驗記錄 (分析oracle硬解析&軟解析&fast soft parse(2))

fufuh2o發表於2009-10-18

關於pl/sql ,動態SQL 的parse

SQL> conn tr/a123
已連線。
SQL> select distinct sid from v$mystat;

       SID
----------
       140
SQL> select serial# from v$session where sid=140;

   SERIAL#
----------
        21
SQL> show user
USER 為 "TR"
SQL> create table t1 (a int, b int);

表已建立。

SQL> ed
已寫入 file afiedt.buf

  1   declare
  2    begin
  3    for i in 1..1000 loop
  4   insert into t1 values(i,i+1);
  5    end loop;
  6    commit;
  7*  end;
SQL> /

PL/SQL 過程已成功完成。

SQL> execute sys.dbms_stats.gather_table_stats('tr','t1');

PL/SQL 過程已成功完成。


SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                 6
session cursor cache count                                               29
parse count (total)                                                      58
parse count (hard)                                                        9

SQL> execute dbms_system.set_sql_trace_in_session(140,21,true);

PL/SQL 過程已成功完成。

  1  declare
  2  begin
  3  for i in 1..100 loop
  4  execute immediate 'select * from t1 where a=1';
  5  end loop;
  6* end;
SQL> /

PL/SQL 過程已成功完成。

SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                 6
session cursor cache count                                               29
parse count (total)                                                      64
parse count (hard)                                                       13


SQL> select PREV_HASH_VALUE,sql_HASH_VALUE from v$session where sid=140;

PREV_HASH_VALUE SQL_HASH_VALUE
--------------- --------------
     2867764059     2867764059
SQL> col sql_text format a30
SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS from v$sqlarea where has
h_value=2867764059;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS
------------------------------ ------------- ---------- -----------
declare begin for i in 1..100              1          1           1
loop execute immediate 'select
 * from t1 where a=1'; end loo
p; end;

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS,hash_value,PARSING_SCHEM
A_NAME from v$sqlarea where sql_text='select * from t1 where a=1';

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
select * from t1 where a=1                 1        100           1 1489680637
TR

SQL> /

PL/SQL 過程已成功完成。

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS,hash_value,PARSING_SCHEM
A_NAME from v$sqlarea where sql_text='select * from t1 where a=1';

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
select * from t1 where a=1                 1        200           2 1489680637
TR


SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS from v$sqlarea where has
h_value=2867764059;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS
------------------------------ ------------- ---------- -----------
declare begin for i in 1..100              1          2           2
loop execute immediate 'select
 * from t1 where a=1'; end loo
p; end;


SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                 6
session cursor cache count                                               29
parse count (total)                                                      66~~~
parse count (hard)                                                       13
SQL> /

PL/SQL 過程已成功完成。

SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                 6
session cursor cache count                                               30~~cache cursor了
parse count (total)                                                      68~~~~
parse count (hard)                                                       13

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS from v$sqlarea where has
h_value=2867764059;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS
------------------------------ ------------- ---------- -----------
declare begin for i in 1..100              1          3           3
loop execute immediate 'select
 * from t1 where a=1'; end loo
p; end;


SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS,hash_value from v$sqlare
a where sql_text='select * from t1 where a=1';

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
select * from t1 where a=1                 1        300           3 1489680637


SQL> host tkprof D:\oracle\product\10.2.0\admin\xh\udump\xh_ora_34720.trc d:\t1.txt


TKPROF: Release 10.2.0.1.0 - Production on 星期三 9月 30 14:23:38 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


declare
begin
for i in 1..100 loop
execute immediate 'select * from t1 where a=1';
end loop;
end;

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        3      0.01       0.00          0          0          0           0
Execute      3      0.43       0.51          0          0          0           3
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        6      0.45       0.52          0          0          0           3

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 67 
********************************************************************************

select *
from
 t1 where a=1


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        3      0.00       0.00          0          0          0           0
Execute    300      0.00       0.00          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      303      0.00       0.00          0          0          0           0

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 67     (recursive depth: 1)~~~~~~

Rows     Row Source Operation
-------  ---------------------------------------------------
      0  TABLE ACCESS FULL T1 (cr=0 pr=0 pw=0 time=400 us)

 

 

SQL> ed
已寫入 file afiedt.buf

  1  declare
  2  begin
  3  for i in 1..100 loop
  4  execute immediate 'select * from t1 where a='||i||'';
  5  end loop;
  6* end;
SQL> /

PL/SQL 過程已成功完成。

 


SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                 8
session cursor cache count                                               30
parse count (total)                                                     175
parse count (hard)                                                      118~~~~~多了N 多HARD PARSE 基本是多了 101次

SQL> select PREV_HASH_VALUE,sql_HASH_VALUE from v$session where sid=140;

PREV_HASH_VALUE SQL_HASH_VALUE
--------------- --------------
     3622731519     3622731519

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS from v$sqlarea where has
h_value=3622731519;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS
------------------------------ ------------- ---------- -----------
declare begin for i in 1..100              1          1           1
loop execute immediate 'select
 * from t1 where a='||i||''; e
nd loop; end;

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS,hash_value,PARSING_SCHEM
A_NAME from v$sqlarea where sql_text like 'select * from t1 where a=%' and rownum<1
0
  2  ;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
select * from t1 where a=36                1          1           1 1421345405
TR

select * from t1 where a=55                1          1           1  667289837
TR

select * from t1 where a=49                1          1           1 3372485161
TR


SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
select * from t1 where a=34                1          1           1 4024442497
TR

select * from t1 where a=33                1          1           1 2085625811
TR

select * from t1 where a=92                1          1           1 3843959062
TR


SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
select * from t1 where a=8                 1          1           1 4204407230
TR

select * from t1 where a=60                1          1           1 3229626287
TR

select * from t1 where a=88                1          1           1  639251647
TR


已選擇9行。

 

 

 

 

 

SQL> /

PL/SQL 過程已成功完成。

 

 

 

SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                 9
session cursor cache count                                               30
parse count (total)                                                     276~~~多了101次
parse count (hard)                                                      118

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS from v$sqlarea where has
h_value=3622731519;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS
------------------------------ ------------- ---------- -----------
declare begin for i in 1..100              1          2           2
loop execute immediate 'select
 * from t1 where a='||i||''; e
nd loop; end;


SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS,hash_value,PARSING_SCHEM
A_NAME from v$sqlarea where sql_text like 'select * from t1 where a=%' and rownum<1
0;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
select * from t1 where a=36                1          2           2 1421345405
TR

select * from t1 where a=55                1          2           2  667289837
TR

select * from t1 where a=49                1          2           2 3372485161
TR


SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
select * from t1 where a=34                1          2           2 4024442497
TR

select * from t1 where a=33                1          2           2 2085625811
TR

select * from t1 where a=92                1          2           2 3843959062
TR


SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
select * from t1 where a=8                 1          2           2 4204407230
TR

select * from t1 where a=60                1          2           2 3229626287
TR

select * from t1 where a=88                1          2           2  639251647
TR


已選擇9行。

 

SQL> host tkprof D:\oracle\product\10.2.0\admin\xh\udump\xh_ora_34720.trc d:\t1.tx


TKPROF: Release 10.2.0.1.0 - Production on 星期三 9月 30 14:43:51 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


declare
begin
for i in 1..100 loop
execute immediate 'select * from t1 where a='||i||'';
end loop;
end;

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.00       0.00          0          0          0           0
Execute      2      0.12       0.11          0          0          0           2
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.12       0.12          0          0          0           2

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 67 


select *
from
 t1 where a=2


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.00       0.00          0          0          0           0
Execute      2      0.00       0.00          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.00          0          0          0           0

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 67     (recursive depth: 1)

Rows     Row Source Operation
-------  ---------------------------------------------------
      0  TABLE ACCESS FULL T1 (cr=0 pr=0 pw=0 time=4 us)

.............................
.............................
select *
from
 t1 where a=100


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.00       0.00          0          0          0           0
Execute      2      0.00       0.00          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.00          0          0          0           0

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 67     (recursive depth: 1)

Rows     Row Source Operation
-------  ---------------------------------------------------
      0  TABLE ACCESS FULL T1 (cr=0 pr=0 pw=0 time=3 us)

 

 

 

  1  declare
  2  begin
  3  for i in 1..100 loop
  4  execute immediate 'select * from t1 where a=:x' using i;
  5  end loop;
  6* end;
  7  /

PL/SQL 過程已成功完成。

SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                 9
session cursor cache count                                               30
parse count (total)                                                     278
parse count (hard)                                                      120~~~~~2 次hard parse

 

SQL> select PREV_HASH_VALUE,sql_HASH_VALUE from v$session where sid=140;

PREV_HASH_VALUE SQL_HASH_VALUE
--------------- --------------
     1335041921     1335041921

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS from v$sqlarea where has
h_value=1335041921;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS
------------------------------ ------------- ---------- -----------
declare begin for i in 1..100              1          1           1
loop execute immediate 'select
 * from t1 where a=:x' using i
; end loop; end;


SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS,hash_value,PARSING_SCHEM
A_NAME from v$sqlarea where sql_text='select * from t1 where a=:x';

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
select * from t1 where a=:x                1        100           1 3289402228
TR


SQL> /

PL/SQL 過程已成功完成。

 

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS,hash_value,PARSING_SCHEM
A_NAME from v$sqlarea where sql_text='select * from t1 where a=:x';

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
select * from t1 where a=:x                1        200           2 3289402228~~~~~~~解析2次
TR


SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS from v$sqlarea where has
h_value=1335041921;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS
------------------------------ ------------- ---------- -----------
declare begin for i in 1..100              1          2           2~~~~~~~~~解析2次
loop execute immediate 'select
 * from t1 where a=:x' using i
; end loop; end;


SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                 9~~沒變
session cursor cache count                                               30
parse count (total)                                                     280~~~2次soft parse
parse count (hard)                                                      120~~沒變

 


********************************************************************************

declare
begin
for i in 1..100 loop
execute immediate 'select * from t1 where a=:x' using i;
end loop;
end;

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.00       0.00          0          0          0           0
Execute      2      0.01       0.02          0          0          0           2
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.01       0.02          0          0          0           2

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 67 
********************************************************************************

select *
from
 t1 where a=:x


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.00       0.00          0          0          0           0
Execute    200      0.01       0.00          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      202      0.01       0.00          0          0          0           0

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 67     (recursive depth: 1)

Rows     Row Source Operation
-------  ---------------------------------------------------
      0  TABLE ACCESS FULL T1 (cr=0 pr=0 pw=0 time=268 us)

 


********************************************************************************


  1  declare
  2  begin
  3  for i in 1..100 loop
  4  insert into t1 values(1,1);
  5  end loop;
  6  commit;
  7* end;
  8  /

PL/SQL 過程已成功完成。


SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                 9
session cursor cache count                                               30
parse count (total)                                                     283
parse count (hard)                                                      122

SQL> select PREV_HASH_VALUE,sql_HASH_VALUE from v$session where sid=140;

PREV_HASH_VALUE SQL_HASH_VALUE
--------------- --------------
     2403475982     2403475982

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS from v$sqlarea where has
h_value=2403475982;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS
------------------------------ ------------- ---------- -----------
declare begin for i in 1..100              1          1           1
loop insert into t1 values(1,1
); end loop; commit; end;

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS,hash_value,PARSING_SCHEM
A_NAME from v$sqlarea where sql_text like'INSERT INTO T1 VALUES%';

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
INSERT INTO T1 VALUES(1,1)                 1        100           1 2479797333
TR
INSERT INTO T1 VALUES(:B1 ,:B1             1       1000           1   7809332 ~~~~~~~~~~~~~建表時的
 +1)
TR


SQL> host tkprof D:\oracle\product\10.2.0\admin\xh\udump\xh_ora_34720.trc d:\t1.txt


TKPROF: Release 10.2.0.1.0 - Production on 星期三 9月 30 15:16:52 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

declare
begin
for i in 1..100 loop
insert into t1 values(1,1);
end loop;
commit;
end;

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.01          0          0          0           1
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        2      0.00       0.01          0          0          0           1

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 67 
********************************************************************************

INSERT INTO T1
VALUES
(1,1)


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.01       0.00          0          0          0           0
Execute    100      0.00       0.00          0          1        107         100
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      101      0.01       0.00          0          1        107         100

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 67     (recursive depth: 1)

SQL> ed
已寫入 file afiedt.buf

  1  declare
  2  begin
  3  for i in 1..100 loop
  4  insert into t1 values(i,i+1);
  5  end loop;
  6  commit;
  7* end;
  8  /

PL/SQL 過程已成功完成。

SQL> select PREV_HASH_VALUE,sql_HASH_VALUE from v$session where sid=140;

PREV_HASH_VALUE SQL_HASH_VALUE
--------------- --------------
     2278035423     2278035423

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS from v$sqlarea where has
h_value=2278035423;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS
------------------------------ ------------- ---------- -----------
declare begin for i in 1..100              1          1           1
loop insert into t1 values(i,i
+1); end loop; commit; end;


SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                10
session cursor cache count                                               30
parse count (total)                                                     286
parse count (hard)                                                      124~~~~2次hard parse


SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS,hash_value,PARSING_SCHEM
A_NAME from v$sqlarea where sql_text like'INSERT INTO T1 VALUES%';

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
INSERT INTO T1 VALUES(1,1)                 1        100           1 2479797333
TR

INSERT INTO T1 VALUES(:B1 ,:B1             2       1100           2   78093321
 +1)
TR

SQL> host tkprof D:\oracle\product\10.2.0\admin\xh\udump\xh_ora_34720.trc d:\t1.txt


TKPROF: Release 10.2.0.1.0 - Production on 星期三 9月 30 15:22:54 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


declare
begin
for i in 1..100 loop
insert into t1 values(i,i+1);
end loop;
commit;
end;

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.01       0.00          0          0          0           0
Execute      1      0.01       0.01          0          0          0           1
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        2      0.03       0.02          0          0          0           1

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 67 
********************************************************************************

INSERT INTO T1
VALUES
(:B1 ,:B1 +1)


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute    100      0.00       0.00          0          1        107         100
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      101      0.00       0.00          0          1        107         100

Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: CHOOSE
Parsing user id: 67     (recursive depth: 1)


SQL> /

PL/SQL 過程已成功完成。

SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS,hash_value,PARSING_SCHEM
A_NAME from v$sqlarea where sql_text like'INSERT INTO T1 VALUES%';

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS HASH_VALUE
------------------------------ ------------- ---------- ----------- ----------
PARSING_SCHEMA_NAME
------------------------------
INSERT INTO T1 VALUES(1,1)                 1        100           1 2479797333
TR

INSERT INTO T1 VALUES(:B1 ,:B1             2       1200           3   78093321
 +1)
TR


SQL> select b.name,a.value from v$sesstat a,v$statname b where a.statistic#=b.stati
stic# and a.sid=140  and b.name in('parse count (total)','parse count (hard)','open
ed cursors current','session cursor cache hits','session cursor cache count');

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
opened cursors current                                                   15
session cursor cache hits                                                11~~~~~
session cursor cache count                                               30
parse count (total)                                                     289~~~~~~~3次解析
parse count (hard)                                                      124


SQL> select  SQL_TEXT,VERSION_COUNT,EXECUTIONS,PARSE_CALLS from v$sqlarea where has
h_value=2278035423;

SQL_TEXT                       VERSION_COUNT EXECUTIONS PARSE_CALLS
------------------------------ ------------- ---------- -----------
declare begin for i in 1..100              1          2           2
loop insert into t1 values(i,i
+1); end loop; commit; end;


declare
begin
for i in 1..100 loop
insert into t1 values(i,i+1);
end loop;
commit;
end;

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        3      0.01       0.00          0          0          0           0
Execute      3      0.01       0.02          0          0          1           2
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        6      0.03       0.03          0          0          1           2

Misses in library cache during parse: 1
Parsing user id: 67     (recursive depth: 1)
********************************************************************************

INSERT INTO T1
VALUES
(:B1 ,:B1 +1)


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.00       0.00          0          0          0           0
Execute    200      0.01       0.01          0          2        213         200
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      202      0.01       0.01          0          2        213         200

Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: CHOOSE
Parsing user id: 67     (recursive depth: 1)

 

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12020513/viewspace-616812/,如需轉載,請註明出處,否則將追究法律責任。

相關文章