Professional Documents
Culture Documents
Todays Presentation
Half a dozen real-life examples
scenario command-line efforts resolution
de de de SQL*Plus validate
SQL_TEXT ------------------------------------------------------SELECT ITEM_ID FROM ITEM_TRANSLATIONS WHERE SOURCE_ID = :b1 AND SUBSTR(SOURCE_SKU_CODE,1,6) = :b2 AND SYSDATE BETWEEN START_DATE_ACTIVE AND NVL (END_DATE_ACTIVE, SYSDATE)
We Found a Bottleneck!
PROCEDURE edi_validate_and_load (p_cust_id IN NUMBER) IS CURSOR c_get_item_id (cp_cust_id IN NUMBER, cp_sku IN VARCHAR2) IS SELECT item_id FROM item_translations WHERE source_id = cp_cust_id AND source_sku_code LIKE cp_sku || '%' AND SYSDATE BETWEEN start_date_active AND NVL (end_date_active, SYSDATE);
SELECT
sql_text, disk_reads, executions, disk_reads / DECODE (executions, 0, 1, executions) reads_per_exec FROM v$sqlarea ORDER BY disk_reads;
SELECT sql_text, buffer_gets, executions, buffer_gets / DECODE (executions, 0, 1, executions) gets_per_exec FROM v$sqlarea ORDER BY buffer_gets;
A case-insensitive query turns out to be very inefficient. Now we know what to tune.
2
3 4 5 6
FROM
WHERE AND AND
v$statname A, v$sesstat B
B.statistic# IN (12, 37, 38, 39, 119, 123, 139, 140, 141) B.sid = 63 A.statistic# = B.statistic#;
NAME VALUE ------------------------------ ---------CPU used by this session 1292 db block gets 10186 consistent gets 86810 physical reads 346 table scans (long tables) 0 table scan rows gotten 1054 sorts (memory) 826 sorts (disk) 0 sorts (rows) 4693
NAME VALUE ------------------------------ ---------CPU used by this session 7274 db block gets 10294 consistent gets 86813 physical reads 346 table scans (long tables) 0 table scan rows gotten 1054 sorts (memory) 826 sorts (disk) 0 sorts (rows) 4693
3
4 5 6
WHERE
AND AND
2
3 4
FROM
WHERE AND
v$session A, v$sqlarea B
B.address = A.sql_address A.sid = 13;
Let me guess! The transactions table is about 10,000 blocks in size and the extracted column is not indexed.
c INTEGER;
i INTEGER; BEGIN c := dbms_sql.open_cursor;
dbms_sql.parse (c,
'ALTER SESSION SET TIMED_STATISTICS=TRUE', dbms_sql.native); i := dbms_sql.execute (c);
dbms_sql.close_cursor (c);
dbms_session.set_sql_trace (TRUE); END;
SQL>
Misses in library cache during parse: 1 Optimizer goal: RULE Parsing user id: 142 (BUILD4P2) Rows ------0 0 254 115 253 254 114539 253 254 115 254 129 129 Execution Plan --------------------------------------------------SELECT STATEMENT GOAL: RULE MERGE JOIN (OUTER) SORT (JOIN) NESTED LOOPS (OUTER) NESTED LOOPS (OUTER) TABLE ACCESS GOAL: ANALYZED (BY ROWID) OF 'MNME' INDEX GOAL: ANALYZED (FULL SCAN) OF 'MNME_I1' (UNIQUE) TABLE ACCESS GOAL: ANALYZED (BY ROWID) OF 'LCONTYPE' INDEX GOAL: ANALYZED (UNIQUE SCAN) OF 'LCONTYPE_PK' (UNIQUE) TABLE ACCESS GOAL: ANALYZED (BY ROWID) OF 'MTAX' INDEX GOAL: ANALYZED (UNIQUE SCAN) OF 'MTAX_I1' (UNIQUE) SORT (JOIN) TABLE ACCESS GOAL: ANALYZED (FULL) OF 'LPOST
The optimizer can behave differently from one Oracle version to the next.
Resources
Oracle Server Tuning - Overview of the tuning process - How to use SQL Trace and TKPROF Oracle Server Reference - Descriptions of all v$ views High Performance SQL Tuning by Guy Harrison - Lots of tuning tips - Discussion of GUI tools available on the Internet
www.dbspecialists.com/present.html
- Download this presentation - Download a companion white paper
Contact Information
Ian Jones: ijones@dbspecialists.com Roger Schrag: rschrag@dbspecialists.com
Database Specialists, Inc. 388 Market Street, Suite 400 San Francisco, CA 94111 415/344-0500