Documente Academic
Documente Profesional
Documente Cultură
Vivek Sharma
User Load
700
600
500
400
Linear
300
200
100
0
4
12
16
20
Resources
24
28
32
User Load
700
Desired
600
500
400
Linear
300
Actual
Problem
200
100
0
4
12
16
20
Resources
24
28
32
Why Concepts ?
Database Architecture
SGA (Shared Pool / Buffer Cache)
Read Consistency
Logical Reads / Current Gets
Concurrency Controls
Optimization, from Day ONE
Database Features
The way these Work v/s Assumptions
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HASH JOIN
|
TABLE ACCESS FULL
|
HASH JOIN
|
TABLE ACCESS FULL
|
HASH JOIN
|
TABLE ACCESS FULL
|
HASH JOIN
|
TABLE ACCESS FULL
|
HASH JOIN
|
TABLE ACCESS BY INDEX ROWID |
INDEX RANGE SCAN
|
HASH JOIN
|
TABLE ACCESS FULL
|
TABLE ACCESS BY INDEX ROWID|
INDEX RANGE SCAN
|
HZ_CUST_ACCT_SITES_ALL
HZ_PARTY_SITES
HZ_LOCATIONS
HZ_CUST_ACCOUNTS
MTL_SYSTEM_ITEMS_B
MTL_SYSTEM_ITEMS_B_N16
HR_LOCATIONS_ALL
WSH_DELIVERY_DETAILS
WSH_DELIVERY_DETAILS_TI4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
36983 |
23952 |
76710 |
22674 |
72598 |
22737 |
14291 |
22801 |
11073 |
11073 |
130K|
919 |
130K|
143K|
This is the Run Time Plan for a Query executed from Oracle Reports
Run Time > 60 Minutes
https://viveklsharma.wordpress.com/2012/02/27/query-performance-issue-sqlplus-vs-oracle-reports/
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NESTED LOOPS
|
MERGE JOIN
|
TABLE ACCESS BY INDEX ROWID |
INDEX RANGE SCAN
|
SORT JOIN
|
TABLE ACCESS BY INDEX ROWID|
INDEX RANGE SCAN
|
TABLE ACCESS BY INDEX ROWID |
INDEX RANGE SCAN
|
INDEX RANGE SCAN
|
TABLE ACCESS BY INDEX ROWID
|
INDEX RANGE SCAN
|
TABLE ACCESS BY INDEX ROWID
|
INDEX RANGE SCAN
|
|
|
WSH_TRIP_STOPS
|
WSH_TRIP_STOPS_N1
|
|
WSH_TRIPS
|
WSH_TRIPS_U1
|
WSH_DELIVERY_LEGS
|
WSH_DELIVERY_LEGS_N2
|
WSH_DELIVERY_ASSIGNMENTS_N1 |
WSH_DELIVERY_ASSIGNMENTS
|
WSH_DELIVERY_ASSIGNMENTS_N1 |
WSH_DELIVERY_DETAILS
|
WSH_DELIVERY_DETAILS_TI4
|
127
72
187
187
72
72
72
2
2
3
4
4
1
1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This is the Run Time Plan for the same Query, when executed from SQL*Plus
Run Time < 1 Minute
10
11
Shared Pool
Log
Buffer
Network
Or Local
Redo Logs
LGWR
Oracle
Server
Process
Commits / Rollbacks
Cha
nge
DBWR
Disk Reads
Buffer Cache
11g
Op
iz
tim
ati
on
12
Concepts
Redo & Undo
Read Consistency
Delayed Block Cleanout
Snapshot too old (ora-01555)
Concurrency
Locks
Latches / Mutexes
13
Undo
Opposite of Redo
Put back the Data as it was
Critical for Read-Consistency
Not an overhead, but generate as minimal as possible
14
Maintaining Concurrency
User 1 (seq 1)
Success
User 1 (seq 3)
Locked
User 2 (seq 2)
Success
User 2 (seq 4)
Deadlock
Maintaining Concurrency(Contd)
Locks
Application Enforced
Row Level Locking (TX Contention)
Ora-00060
Oracle Enforced
ITL (TX Lmode 4)
Bitmap (TX Lmode 4)
Duplicate Unique / Primary Key
TM Contention
Except for ITL, others are an Application Issue
itl.sql
16
Question Time
Is Initrans a Block level or a Table Level Parameter ?
What is the default value of Initrans for a table ?
What is the default value of Initrans for an Index ?
What is the value1 of Maxtrans ?
Maxtrans is Dictated by Block Size and is limited to max 255
Database Block Size
8192
Variable Header
48 Bytes
ITL
24 Bytes
8192-48
8144
50% of 8144
4072
4072/24
169 (round(169.66))
itl.sql
17
ITL Allocation
TM Contention
Table Level Lock
Primary Cause
Update to a Primary Key (A Bad Idea)
Unindexed Foreign Keys
User 1
(11:57:50) Updates
User 2
(11:57:51) Updates
19
TM Contention(Contd)
Table Level Lock
Primary Cause
Update to a Primary Key (A Bad Idea)
Unindexed Foreign Keys
20
User 2
(11:56:23) Queries
(11:58:15) Updates
21
rowlock.sql
22
LRU Algorithm
Protected by Latches / Mutexes (Mutual Exclusive Lock)
Contention : Frequent Allocation / De-allocation of memory
Contention : Frequent Loading of Cursors
23
Soft Parse
Sharable Parent
Cursor
Available ?
Y
Store Parent Cursor in
Library Cache
Sharable Child
Cursor
Available ?
N
Query Transformation /
Execution Plans
Execute
24
Problem
Parent
Parent
Parent
Parent
(select *
from emp)
(select *
from dept)
(SELECT *
FROM EMP)
(select *
from emp e)
Child
Child
Child
Child
25
Child 0
(Schema
X)
Child 1
(Schema
Child 2
(Schema
Child 3
(Schema
Y)
X with
OICA=10)
X with
different
bind
length)
Problem
Length
10
30
40
80
140
2040
1
2
Bind Variable
3
4
Varchar2 Rounding
32
128
Graduation
2000
4000
Event 10503
bind_graduation.sql
Sharing SQL
Why ?
For Performance Reason
Scalability
Effective Resource Utilization
Memory
CPU
How ?
Implement Bind (only when required)
Maintain Coding Standard
test_bind.sql
29
Production Downtime
Snap Id
Snap Time
Sessions Curs/Sess
--------- ------------------- -------- --------24222 18-Apr-14 11:30:27
401
74.5
24223 18-Apr-14 12:30:16
783
86.0
59.81 (mins)
19 Active
1,133.51 (mins)
Begin Snap:
End Snap:
Elapsed:
DB Time:
Cache Sizes
~~~~~~~~~~~
Begin
End
---------- ---------Buffer Cache:
23,552M
23,552M
Shared Pool Size:
12,288M
12,288M
Load Profile
~~~~~~~~~~~~
Redo size:
Logical reads:
Block changes:
Physical reads:
Physical writes:
User calls:
Parses:
Hard parses:
Sorts:
Logons:
Executes:
Transactions:
Per Second
--------------859,548.86
154,690.90
3,634.57
1,515.71
296.98
2,817.43
2,842.89
156.49
664.11
0.97
6,454.01
33.45
8K
15,112K
Per Transaction
--------------25,693.53
4,624.00
108.64
45.31
8.88
84.225.5%
84.98
4.68
19.85
0.03
192.92
Production Downtime
DB/Inst: IIMSP/IIMSP2
Snaps: 24222-24223
Statistic
Total
per Second
per Trans
-------------------------------- ------------------ -------------- ------------parse count (failures)
357,665
99.7
3.0
parse count (hard)
561,605
156.5
4.7
64% Failures
parse count (total)
10,202,613
2,842.9
85.0
Question Time
Give few Examples, when the Cursors are not shared
even after using Bind Variables ?
Optimizer Parameters
Bind Type Mismatch
Bind Variable Mismatch
SQL Trace
32
33
HLADDR
COUNT(*)
---------------- ---------07000002570F7300
8734
070000025A786078
364
070000025A5020D8
167
0700000262E9A9E0
167
07000002562DD4D0
164
07000002583D9C00
164
07000002563162C0
161
07000002563BE270
161
07000002571D9AF0
161
0700000262E9C420
161
Good Period
Bad Period
HLADDR
COUNT(*)
---------------- ---------07000002570F7300
8734
070000025A786078
364
070000025A5020D8
167
0700000262E9A9E0
167
07000002562DD4D0
164
07000002583D9C00
164
07000002563162C0
161
07000002563BE270
161
07000002571D9AF0
161
0700000262E9C420
161
Good Period
Bad Period
2306090
322980110 SELECT
FN_NEWBRANCH(CSTBS_CONTRACT.BRANCH),
CSTBS_CONTRACT.PRODUCT_CODE,
CSTMS_PRODUCT.PROD
UCT_DESCRIPTION,
BCTB_CONTRACT_MASTER.CUSTOMER_
ID,
STTMS_CUSTOMER.CUSTOMER_NAME1,
CSTBS_CON
TRACT.CONTRACT_REF_NO,
CSTBS_CONTRACT.USER_REF_
811376
2306090
322980110 SELECT
FN_NEWBRANCH(CSTBS_CONTRACT.BRANCH),
CSTBS_CONTRACT.PRODUCT_CODE,
CSTMS_PRODUCT.PROD
UCT_DESCRIPTION,
BCTB_CONTRACT_MASTER.CUSTOMER_
ID,
STTMS_CUSTOMER.CUSTOMER_NAME1,
CSTBS_CON
TRACT.CONTRACT_REF_NO,
CSTBS_CONTRACT.USER_REF_
811376
Latches / Mutexes
Concurrency
Block
2
CACHED
Block
4
Block
5
Block
6
Block
7
Block
8
Block
9
Block
10
Block
11
Block
12
Block
13
Block
14
Block
15
CACHED
CACHED
CACHED
CACHED
Block
16
Block
17
Block
18
Block
19
Block
20
Block
21
Block
22
Block
23
CACHED
db file scattered reads Count
db file sequential reads Count
5
4
Question Time
Table
Rows
10000
1 to 45 = 7 I/Os
1 to 90 = 7 I/Os
Blocks
100
46 to 300 = 8 I/Os
91 to 345 = 8 I/Os
Columns
300
In terms of performance
Is there any difference between these queries ?
44
Row Migration
Usual Index Block to Table Block
Issue Index Block to Table Block to Table Block
Impact due to Additional Hop (IO)
Impact Index Scans
Improper PCTREE Settings
table fetch continued row
table fetch continued row+table scan rows gotten
High Ratio = Row Migration, Row Chaining, > 255 Columns
row_migration.sql
45
Improper Testing
Inefficient Queries
Inefficient Indexes / Index not being used
Optimizer Statistics
Stale / Incomplete Statistics
Caching Effect
Optimizers Inability to Quantify benefit of Caches
Improper Testing
ep.sql
Bind Peeking
Introduced in 9i
Hard Parse, as if Bind is a Literal
Appropriate Plan based on Bind Value
9i & 10g, Hard Parse Bind Value Wins
11g Introduced Adaptive Cursor Sharing
Plan Upgraded, post subsequent executions
Bad Query Performance, at least once
How do you take care of a High Performance Application ?
bp.sql
Improper Testing
Inefficient Queries
Inefficient Indexes / Index not being used
Optimizer Statistics
Stale / Incomplete Statistics
Caching Effect
Optimizers Inability to Quantify benefit of Caches
Inefficient Queries
Leave Blank for ALL
Leave Blank for ALL
where
(cust_last_name=:cust_last_name or :cust_last_name is null)
and (cust_first_name=:cust_first_name or :cust_first_name is null);
Where
cust_last_name = nvl(:cust_last_name,cust_last_name)
and cust_first_name = nvl(:cust_first_name,cust_first_name);
pd.sql
Improper Testing
Inefficient Queries
Inefficient Indexes / Index not being used
Optimizer Statistics
Stale / Incomplete Statistics
Caching Effect
Optimizers Inability to Quantify benefit of Caches
ne.sql
55
Improper Testing
Inefficient Queries
Inefficient Indexes / Index not being used
Optimizer Statistics
Stale / Incomplete Statistics
Caching Effect
Optimizers Inability to Quantify benefit of Caches
Optimizer Statistics
Upto Date Statistics Object / System Statistics
Column Level relevant Inputs to Optimizer
Co-Related Column Stats
Improper Testing
Inefficient Queries
Inefficient Indexes / Index not being used
Optimizer Statistics
Stale / Incomplete Statistics
Caching Effect
Optimizers Inability to Quantify benefit of Caches
Caching Effect
Buffer Cache
Result Cache
Scalar Subquery Caching
63
Improper Testing
Inefficient Queries
Inefficient Indexes / Index not being used
Optimizer Statistics
Stale / Incomplete Statistics
Caching Effect
Optimizers Inability to Quantify benefit of Caches
Improper Testing
Inefficient Queries
Inefficient Indexes / Index not being used
Optimizer Statistics
Stale / Incomplete Statistics
Caching Effect
Optimizers Inability to Quantify benefit of Caches
Num Rows
Num Blocks
T1
100000
846
T2
100000
846
In terms of performance
Is there any difference between the two queries ?
T1
T2
ID
ID
N1
N1
N2
N3
N3
N4
N4
N5
N5
N6
N6
N7
N7
N8
N8
N9
10
N9
V6
11
V6
N10
12
N10
N11
13
N11
N2
20
130
70
4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49
1st Column
13th Column
Num Rows
Num Blocks
T1
100000
846
T2
100000
846
In terms of performance
Is there any difference between the two queries ?
Quick Questions
Mark a Query Interesting (to appear in AWR) ?
dbms_workload.add_colored_sql
Q&
A
19/08/15 10:20 PM
74