Professional Documents
Culture Documents
Carlos Sierra
Carlos Sierra
ACS Motivation
SQL Processing
Hard parsing is expensive!
!! Hard parse side effects
! CPU consumption ! Latch contention
!! Unknowns
! Is :b1 between low and high values of channel_id? ! Is :b1 a popular value of channel_id? ! Are there any rows with value :b1 for channel_id?
!! Penalty
! Possible suboptimal plans
!! Penalty
! Possible suboptimal plans for subsequent executions on skewed data
8
!! Penalty
! Marginal increase in CPU and memory overhead
10
ACS Mechanics
significantly
! Flag cursor as bind aware ! Start generating multiple optimal plans for this query on next hard parse
Bind Sensitive
Minimum requirements
!! SQL has explicit binds
! Or literals and cursor_sharing is force
13
Bind Aware
How to become bind aware?
!! Significant changes in data volume manipulated by cursor
! A few rows versus a few thousands of rows ! A few thousands of rows versus a few millions of rows
14
Plan Selection
Based on selectivity profile of predicates
!! Evaluate selectivity of predicates at soft parse !! Compare to a non-persistent selectivity profile !! If within ranges of a known profile then select associated plan !! Else hard parse
! Compute and execute newly generated plan ! Create selectivity profile for new plan or update profile of existing plan
15
!! V$SQL_CS_STATISTICS
! Data volume manipulated (rows processed)
!! V$SQL_CS_HISTOGRAM
! Record keeping of data volume per execution (small, medium, large)
!! V$SQL_CS_SELECTIVITY
! Predicates selectivity profiles
16
18
19
20
21
Query q1 q2 q3 q4 q5
:b1 9 5 2 9 2
AP1 N1
AP2 N2
22
Query q1 q2 q3 q4 q5
:b1 9 5 2 9 2
23
Query q1 q2 q3 q4 q5
:b1 9 5 2 9 2
24
Query q1 q2 q3 q4 q5
:b1 9 5 2 9 2
:b2 33 32 999 33
!! v$sql_cs_histogram
! Bucket(0): S ! Bucket(1): M ! Bucket(2): L
999 FTS/FTS
ACS Demo
Query q1 q2 q3 q4 q5
:b1 9 5 2 9 2
:b2 33 32 999 33
Bucket
Aware
Child
Actual
999 FTS/FTS
27
Query q1 q2 q3 q4 q5
:b1 9 5 2 9 2
:b2 33 32 999 33
Bucket 1 0 2 2 2
Aware
Child
Actual
999 FTS/FTS
28
Query q1 q2 q3 q4 q5
:b1 9 5 2 9 2
:b2 33 32 999 33
Bucket 1 0 2 2 2
Aware N N Y Y Y
Child
Actual
999 FTS/FTS
29
Query q1 q2 q3 q4 q5
:b1 9 5 2 9 2
:b2 33 32 999 33
Bucket 1 0 2 2 2
Aware N N Y Y Y
Child 0 0 1 2 3
999 FTS/FTS
30
Query q1 q2 q3 q4 q5
:b1 9 5 2 9 2
:b2 33 32 999 33
Bucket 1 0 2 2 2
Aware N N Y Y Y
Child 0 0 1 2 3
999 FTS/FTS
31
Query q5 q4 q3 q2 q1
:b1 2 9 2 5 9
:b2 33 999 32 33
Bucket
Aware
Child
Actual
999 FTS/FTS
32
Query q5 q4 q3 q2 q1
:b1 2 9 2 5 9
:b2 33 999 32 33
Bucket 2 2 2 0 1
Aware
Child
Actual
999 FTS/FTS
33
Query q5 q4 q3 q2 q1
:b1 2 9 2 5 9
:b2 33 999 32 33
Bucket 2 2 2 0 1
Aware N N N N Y
Child
Actual
999 FTS/FTS
34
Query q5 q4 q3 q2 q1
:b1 2 9 2 5 9
:b2 33 999 32 33
Bucket 2 2 2 0 1
Aware N N N N Y
Child 0 0 0 0 1
999 FTS/FTS
35
Query q5 q4 q3 q2 q1
:b1 2 9 2 5 9
:b2 33 999 32 33
Bucket 2 2 2 0 1
Aware N N N N Y
Child 0 0 0 0 1
999 FTS/FTS
36
Query q5 q4 q3 q1 q2
:b1 2 9 2 9 5
:b2 33 999 33 32
Bucket 2 2 2 1 0
Aware
Child
Actual
999 FTS/FTS
37
Query q5 q4 q3 q1 q2
:b1 2 9 2 9 5
:b2 33 999 33 32
Bucket 2 2 2 1 0
Aware N N N N N
Child
Actual
999 FTS/FTS
38
Query q5 q4 q3 q1 q2
:b1 2 9 2 9 5
:b2 33 999 33 32
Bucket 2 2 2 1 0
Aware N N N N N
Child 0 0 0 0 0
999 FTS/FTS
39
Query q5 q4 q3 q1 q2
:b1 2 9 2 9 5
:b2 33 999 33 32
Bucket 2 2 2 1 0
Aware N N N N N
Child 0 0 0 0 0
999 FTS/FTS
40
Closing Remarks
Query q3 q4 q5
:b1 2 9 2
Child 1 2 3
43
Query q3 q4 q5
:b1 2 9 2
Child 1 2 3
44
Query q3 q4 q5
:b1 2 9 2
Child 1 2 3
45
46
47
Conclusions
ACS can produce multiple optimal plans for one query
!! ACS only applies to a subset of queries with binds !! ACS requires a ramp-up process (few executions) !! In some cases cursor may fail to become bind aware !! To force a cursor become bind aware use CBO Hint !! ACS is not persistent !! ACS works well with SQL Plan Management
48
Give Away
Script sqlt/utl/coe_gen_sql_patch.sql (MOS 215187.1)
!! Creates a SQL Patch for one SQL_ID !! Turns on EVENT 10053 for SQL_ID !! Hints on SQL Patch
! GATHER_PLAN_STATISTICS ! MONITOR ! BIND_AWARE
49
50