Оракул - разница между последовательными получает в Автотрассировки и последовательное чтение в SQL-трассировки



Вопрос



В чем разница между непротиворечивым получением в Autotrace и непротиворечивым чтением в SQL Trace?



Фон



Запустите SQL на схеме Oracle demo HR и запустите Autotrace и SQL Trace (внизу). Я ожидал, что номер прочитанного блока будет таким же, однако Autotrace Consistent Gets равен 21, а SQL Trace Consistent Read равен 15. Интересно, в чем разница?



Таблицы не обновлялись, и следы говорят, что кэша не было. Мисс, поэтому я думаю, что блоки, необходимые SQL, были все в кэше.



Таблица блоков данных USER_INDEXES составляет 5 сотрудников и отделов. Строки 107 и 27 соответственно.




SELECT /*+USE_HASH(e d) */ e.employee_id, e.first_name||' '||e.last_name as full_name, d.department_name
FROM
employees e, departments d
WHERE
e.department_id=d.department_id;



Окружающая среда



Oracle 11G R2 на Windows x64
Кадровая демонстрационной схемы.



Автоматическая Трассировка




Execution Plan
----------------------------------------------------------
Plan hash value: 2052257371

----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 106 | 4028 | 7 (15)| 00:00:01 |
|* 1 | HASH JOIN | | 106 | 4028 | 7 (15)| 00:00:01 |
| 2 | TABLE ACCESS FULL| DEPARTMENTS | 27 | 432 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMPLOYEES | 107 | 2354 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")


Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
21 consistent gets
0 physical reads
0 redo size
4502 bytes sent via SQL*Net to client
601 bytes received via SQL*Net from client
9 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
106 rows processed

1 SELECT /*+USE_HASH(e d) */ e.employee_id, e.first_name||' '||e.last_name as full_name, d.department_name
2 FROM
3 employees e, departments d
4 WHERE
5 e.department_id=d.department_id
6 -- AND d.department_name = 'IT'
7*




ТРАССИРОВКА SQL




SELECT /*+USE_HASH(e d) */ e.employee_id, e.first_name||' '||e.last_name as full_name, d.department_name
FROM
employees e, departments d
WHERE
e.department_id=d.department_id

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 2 0.00 0.00 0 15 0 106
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.00 0.00 0 15 0 106

Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 85

Rows Row Source Operation
------- ---------------------------------------------------
106 HASH JOIN (cr=15 pr=0 pw=0 time=105 us cost=7 size=4028 card=106)
27 TABLE ACCESS FULL DEPARTMENTS (cr=7 pr=0 pw=0 time=26 us cost=3 size=432 card=27)
107 TABLE ACCESS FULL EMPLOYEES (cr=8 pr=0 pw=0 time=106 us cost=3 size=2354 card=107)


Весь выход TKPROF
TKPROF: релиз 11.2.0.1.0-разработка на СБ 22 ноября 20: 05: 34 2014



Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Trace file: nr_ora_6352_HR.trc
Sort options: default

********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************

SQL ID: 909v6n80saka9
Plan Hash: 0
ALTER SESSION SET SQL_TRACE=true


call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 0 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 1 0.00 0.00 0 0 0 0

Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 85
********************************************************************************

SELECT /*+USE_HASH(e d) */ e.employee_id, e.first_name||' '||e.last_name as full_name, d.department_name
FROM
employees e, departments d
WHERE
e.department_id=d.department_id

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 2 0.00 0.00 0 15 0 106
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.00 0.00 0 15 0 106

Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 85

Rows Row Source Operation
------- ---------------------------------------------------
106 HASH JOIN (cr=15 pr=0 pw=0 time=105 us cost=7 size=4028 card=106)
27 TABLE ACCESS FULL DEPARTMENTS (cr=7 pr=0 pw=0 time=26 us cost=3 size=432 card=27)
107 TABLE ACCESS FULL EMPLOYEES (cr=8 pr=0 pw=0 time=106 us cost=3 size=2354 card=107)

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

SQL ID: at7597y1bruv1
Plan Hash: 0
ALTER SESSION SET SQL_TRACE=false


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: 1
Optimizer mode: ALL_ROWS
Parsing user id: 85



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

OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.00 0 0 0 0
Execute 3 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 15 0 106
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 7 0.00 0.00 0 15 0 106

Misses in library cache during parse: 1
Misses in library cache during execute: 1


OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS

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

Misses in library cache during parse: 0

3 user SQL statements in session.
0 internal SQL statements in session.
3 SQL statements in session.
********************************************************************************
Trace file: nr_ora_6352_HR.trc
Trace file compatibility: 11.1.0.7
Sort options: default

1 session in tracefile.
3 user SQL statements in trace file.
0 internal SQL statements in trace file.
3 SQL statements in trace file.
3 unique SQL statements in trace file.
48 lines in trace file.
0 elapsed seconds in trace file.




Обновление



Предыдущем векторизация был выполнен из SQLплюс отпуск 11.2.0.1.0 и трассировка SQL из SQL разработчик 4.0.1.14. Запустив трассировку SQL из того же SQL Plus, результаты совпали...



TKPROF: Release 11.2.0.1.0 - Development on Sun Nov 23 11:22:13 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Trace file: nr_ora_2836_HR.trc
Sort options: default

********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************

SQL ID: 909v6n80saka9
Plan Hash: 0
ALTER SESSION SET SQL_TRACE=true


call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 0 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 1 0.00 0.00 0 0 0 0

Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 85
********************************************************************************

SELECT /*+USE_HASH(e d) */ e.employee_id, e.first_name||' '||e.last_name as full_name, d.department_name
FROM
employees e, departments d
WHERE
e.department_id=d.department_id

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 9 0.00 0.00 0 21 0 106
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 11 0.00 0.00 0 21 0 106

Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 85

Rows Row Source Operation
------- ---------------------------------------------------
106 HASH JOIN (cr=21 pr=0 pw=0 time=0 us cost=7 size=4028 card=106)
27 TABLE ACCESS FULL DEPARTMENTS (cr=7 pr=0 pw=0 time=26 us cost=3 size=432 card=27)
107 TABLE ACCESS FULL EMPLOYEES (cr=14 pr=0 pw=0 time=0 us cost=3 size=2354 card=107)

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

SQL ID: at7597y1bruv1
Plan Hash: 0
ALTER SESSION SET SQL_TRACE=false


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: 1
Optimizer mode: ALL_ROWS
Parsing user id: 85



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

OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.00 0 0 0 0
Execute 3 0.00 0.00 0 0 0 0
Fetch 9 0.00 0.00 0 21 0 106
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 14 0.00 0.00 0 21 0 106

Misses in library cache during parse: 1
Misses in library cache during execute: 1


OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS

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

Misses in library cache during parse: 0

3 user SQL statements in session.
0 internal SQL statements in session.
3 SQL statements in session.
********************************************************************************
Trace file: nr_ora_2836_HR.trc
Trace file compatibility: 11.1.0.7
Sort options: default

1 session in tracefile.
3 user SQL statements in trace file.
0 internal SQL statements in trace file.
3 SQL statements in trace file.
3 unique SQL statements in trace file.
55 lines in trace file.
0 elapsed seconds in trace file.
576   1  

1 ответ:

Разница заключается в том, что выходные данные tkprof показывают вашу единственную инструкцию SELECT, но раздел статистики вывода autotrace суммирует 2 инструкции, Ваш SELECT плюс 1 рекурсивный вызов, как указано в первой строке этого раздела.

Несколько примеров рекурсивных вызовов: триггеры (INSERT, UPDATE, DELETE), динамическая выборка (в случае отсутствия статистики таблицы) или внутренние операторы, запрашивающие данные из словаря данных при первом выполнении.

Попробуйте запустить оператор по крайней мере дважды с autotrace, и проверьте, сохраняется ли этот 1 рекурсивный вызов при последовательном выполнении. Если это так, трассировка SQL должна содержать как инструкцию SELECT, так и рекурсивный SQL. Вы должны сравнить их сумму с выходом autotrace. Tkprof сообщает рекурсивный уровень для операторов SQL, найденных в файле трассировки,а также общую сводку.

Comments

    Ничего не найдено.