SlideShare uma empresa Scribd logo
1 de 72
Baixar para ler offline
Combining	
  
Adap-ve	
  Cursor	
  Sharing	
  (ACS)	
  Flexibility	
  
with	
  	
  
SQL	
  Plan	
  Management	
  (SPM)	
  Stability	
  
Carlos	
  Sierra	
  
Carlos	
  Sierra	
  
• 
• 
• 
• 
• 

Consultant/Developer/DBA	
  
Oracle	
  Performance	
  
SQLTXPLAIN	
  (SQLT)	
  
SQL	
  Tuning	
  
Tools	
  

Enkitec	
  (c)	
  2014	
  

2	
  
Topics	
  
• 
• 
• 
• 

Plan	
  Flexibility	
  and	
  Plan	
  Stability	
  
Adap-ve	
  Cursor	
  Sharing	
  (ACS)	
  
SQL	
  Plan	
  Management	
  (SPM)	
  
Combining	
  ACS	
  and	
  SPM	
  

Enkitec	
  (c)	
  2014	
  

3	
  
Plan	
  Flexibility	
  
•  Cost-­‐based	
  Op-mizer	
  (CBO)	
  
–  Introduced	
  in	
  Oracle	
  7	
  
–  Computes	
  an	
  Op-mal	
  Plan	
  based	
  on	
  	
  
•  Heuris-cs	
  
•  Query	
  Predicates	
  
•  Schema	
  Object	
  Sta-s-cs	
  
•  Several	
  Others	
  

Enkitec	
  (c)	
  2014	
  

4	
  
Flexibility:	
  Good	
  or	
  Evil?	
  
•  CBO	
  Mission	
  
–  Compute	
  an	
  Op-mal	
  Plan	
  for	
  a	
  given	
  SQL	
  and	
  its	
  Data	
  

•  Plans	
  have	
  many	
  and	
  complex	
  Dependencies	
  
•  CBO	
  Performance	
  
–  Successful	
  most	
  of	
  the	
  -mes	
  
•  Produces	
  a	
  sub-­‐op-mal	
  Plan	
  some&mes	
  

Enkitec	
  (c)	
  2014	
  

5	
  
DBA	
  Recurrent	
  Bad	
  Dream	
  
•  A	
  business	
  cri-cal	
  process	
  experiences	
  an	
  
occasional	
  slow	
  down	
  
–  Same	
  SQL	
  usually	
  runs	
  very	
  quickly	
  
–  Developers	
  claim	
  they	
  haven’t	
  changed	
  anything	
  
–  Users	
  claim	
  they	
  do	
  the	
  same	
  every	
  -me	
  
–  Business	
  is	
  sick	
  and	
  -red	
  of	
  repor-ng	
  this	
  to…	
  YOU!	
  

Enkitec	
  (c)	
  2014	
  

6	
  
Plan	
  Performs	
  Inconsistently?	
  (1)	
  
• 
• 
• 
• 
• 
• 

Concurrency	
  with	
  some	
  other	
  Process	
  
State	
  of	
  Buffer	
  Cache	
  
RAC	
  Node	
  Affinity	
  
CPU	
  Starva-on	
  
Sudden	
  Changes	
  on	
  Data	
  Volume	
  
Inconsistent	
  Performance	
  through	
  Database	
  Link	
  
Enkitec	
  (c)	
  2014	
  

7	
  
Plan	
  Performs	
  Inconsistently?	
  (2)	
  
• 
• 
• 
• 
• 

Downgraded	
  Parallel	
  Execu-on	
  
Crossing	
  Small-­‐Table	
  Threshold	
  
Resource	
  Manager	
  Direc-ve	
  
Plan	
  Flips	
  
Many	
  Others…	
  

Enkitec	
  (c)	
  2014	
  

8	
  
WHY	
  a	
  Plan	
  Flips?	
  (1)	
  
• 
• 
• 
• 
• 

Bind	
  Variable	
  Peeking	
  with	
  Histograms	
  
Outdated	
  Schema	
  Object	
  (SO)	
  Sta-s-cs	
  
Missing	
  SO	
  Sta-s-cs	
  
Fresh	
  SO	
  Sta-s-cs	
  
New	
  Empty	
  Par--ons	
  

Enkitec	
  (c)	
  2014	
  

9	
  
WHY	
  a	
  Plan	
  Flips?	
  (2)	
  
•  Incomplete	
  set	
  of	
  CBO	
  Hints	
  
–  Either	
  on	
  SQL	
  Text	
  or	
  SQL	
  Profile	
  

•  Dropped,	
  Invalid,	
  Invisible	
  or	
  new	
  Indexes	
  
•  Index	
  or	
  Table	
  rebuild	
  
•  Two	
  or	
  more	
  Plans	
  with	
  similar	
  Cost	
  

Enkitec	
  (c)	
  2014	
  

10	
  
WHY	
  a	
  Plan	
  Flips?	
  (3)	
  
• 
• 
• 
• 

Database	
  Parameters	
  Changes	
  
CBO	
  System	
  Sta-s-cs	
  Changes	
  
Asynchronous	
  SO	
  Sta-s-cs	
  Gathering	
  
Many	
  Others…	
  

Enkitec	
  (c)	
  2014	
  

11	
  
How	
  to	
  Mi-gate	
  Plan	
  Flipping	
  
•  Sound	
  CBO	
  Sta-s-cs	
  
•  Default	
  CBO	
  Parameters	
  
•  Regulate	
  Global	
  Changes	
  

Enkitec	
  (c)	
  2014	
  

12	
  
Plan	
  Flexibility	
  Allies	
  
• 
• 
• 
• 
• 
• 

CBO	
  Parameters	
  
CBO	
  Sta-s-cs	
  
Dynamic	
  Sampling	
  
Cardinality	
  Feedback	
  
Cursor	
  Sharing	
  
Adap,ve	
  Cursor	
  Sharing	
  (ACS)	
  
Enkitec	
  (c)	
  2014	
  

13	
  
Plan	
  Stability	
  Tools	
  
• 
• 
• 
• 

CBO	
  Hints	
  
Stored	
  Outlines	
  
SQL	
  Profiles	
  
SQL	
  Plan	
  Management	
  (SPM)	
  

Enkitec	
  (c)	
  2014	
  

14	
  
Cursor	
  Sharing	
  
•  Use	
  of	
  Bind	
  Variables	
  instead	
  of	
  Literals	
  
–  AND	
  p.prod_category	
  LIKE	
  'Sooware%’	
  
–  AND	
  p.prod_category	
  LIKE	
  :b5	
  

•  Goal:	
  Reduce	
  Hard	
  Parsing	
  
–  Improve	
  Scalability	
  
•  Reduce	
  CPU	
  u-liza-on	
  
•  Reduce	
  Shared	
  Memory	
  footprint	
  
Enkitec	
  (c)	
  2014	
  

15	
  
Cursor	
  Sharing	
  Shortcomings	
  
•  Flipping	
  Plans	
  
–  Exacerbated	
  by	
  Histograms	
  on	
  Skewed	
  Data	
  	
  
–  AND	
  c.cust_marital_status	
  =	
  :b2	
  
•  :b2	
  :=	
  ‘married’	
  
•  :b2	
  :=	
  ‘widow’	
  

–  Plan	
  is	
  computed	
  at	
  hard	
  parse	
  
•  Plan	
  becomes	
  a	
  long	
  term	
  moving	
  target	
  

Enkitec	
  (c)	
  2014	
  

16	
  
Adap-ve	
  Cursor	
  Sharing	
  (ACS)	
  
•  11g+	
  
•  Mul-ple	
  Op-mal	
  Plans	
  per	
  SQL	
  
–  As	
  per	
  “Selec-vity”	
  of	
  Predicates	
  
•  :b2	
  :=	
  ‘married’	
  (close	
  to	
  60%	
  maybe)	
  
•  :b2	
  :=	
  ‘widow’	
  (this	
  one	
  is	
  more	
  selec-ve)	
  

Enkitec	
  (c)	
  2014	
  

17	
  
ACS	
  Challenges	
  
•  Minimize	
  Resources	
  Impact	
  
–  Monitor	
  only	
  a	
  subset	
  of	
  SQL	
  Statements	
  
–  Ac-vate	
  ACS	
  only	
  for	
  a	
  subset	
  of	
  the	
  monitored	
  SQL	
  
–  Share	
  Execu-ons	
  Plans	
  through	
  a	
  “Selec-vity	
  Profile”	
  
Bind	
  Aware	
  
ACS	
  

Bind	
  Sensi-ve	
  
All	
  Statements	
  
Enkitec	
  (c)	
  2014	
  

18	
  
Becoming	
  Bind	
  Sensi-ve	
  
1.  SQL	
  has	
  Range	
  Predicates	
  on	
  Bind	
  Variables	
  
–  AND	
  c.cust_year_of_birth	
  BETWEEN	
  :b3	
  AND	
  :b4	
  
–  AND	
  p.prod_category	
  LIKE	
  :b5	
  

2.  SQL	
  has	
  Equality	
  Predicates	
  on	
  Bind	
  Variables	
  and	
  
Column	
  has	
  a	
  Histogram	
  
–  AND	
  c.cust_marital_status	
  =	
  :b2	
  
–  AND	
  TO_CHAR(s.-me_id,	
  'YYYY')	
  =	
  :b6	
  
Enkitec	
  (c)	
  2014	
  

19	
  
Becoming	
  Bind	
  Aware	
  
1.  Rows	
  Processed	
  change	
  substan-ally	
  between	
  
Execu-ons	
  
–  Between	
  a	
  few	
  rows	
  to	
  millions	
  

2.  Rows	
  Processed	
  oscillate	
  significantly	
  between	
  
Execu-ons	
  
–  Between	
  a	
  few	
  rows	
  and	
  a	
  few	
  thousand	
  
–  Between	
  a	
  few	
  thousand	
  and	
  millions	
  
Enkitec	
  (c)	
  2014	
  

20	
  
ACS	
  Monitoring	
  
•  V$SQL	
  (State)	
  
–  is_shareable	
  
–  is_bind_sensi-ve	
  
–  is_bind_aware	
  

•  V$SQL_CS_STATISTICS	
  (Rows	
  Processed)	
  
•  V$SQL_CS_HISTOGRAM	
  (3	
  Buckets	
  S/M/L)	
  
•  V$SQL_CS_SELECTIVITY	
  (Selec-vity	
  Profile)	
  
Enkitec	
  (c)	
  2014	
  

21	
  
Rows	
  Processed	
  
• 
• 
• 
• 

v$sql_cs_sta-s-cs.rows_processed	
  
Updated	
  only	
  at	
  hard	
  parse	
  
A	
  measure	
  of	
  amount	
  of	
  work	
  on	
  Execu-on	
  Plan	
  
Three	
  sizes:	
  S/M/L	
  
–  0:	
  Small	
  	
  
–  1:	
  Medium	
  	
  
–  2:	
  Large	
  
Enkitec	
  (c)	
  2014	
  

22	
  
Rows	
  Processed	
  
• 
• 
• 
• 

v$sql_cs_sta-s-cs.rows_processed	
  
Updated	
  only	
  at	
  hard	
  parse	
  
A	
  measure	
  of	
  amount	
  of	
  work	
  on	
  Execu-on	
  Plan	
  
Three	
  sizes:	
  S/M/L	
  
–  0:	
  Small	
  (less	
  than	
  1K	
  rows)	
  
–  1:	
  Medium	
  (between	
  1k	
  and	
  1m	
  rows)	
  
–  2:	
  Large	
  (more	
  than	
  1m	
  rows)	
  
Enkitec	
  (c)	
  2014	
  

23	
  
ACS	
  Buckets	
  
•  v$sql_cs_histogram.bucket_id	
  
–  0:	
  Small	
  
–  1:	
  Medium	
  
–  2:	
  Large	
  

•  v$sql_cs_histogram.count	
  
–  Incremented	
  with	
  each	
  Execu-on	
  as	
  per	
  
•  v$sql_cs_sta-s-cs.rows_processed	
  
Enkitec	
  (c)	
  2014	
  

24	
  
Rows	
  Processed	
  and	
  ACS	
  Buckets	
  
IF	
  	
  	
  	
  v$sql_cs_statistics.rows_processed	
  <	
  1K	
  THEN	
  
	
  	
  	
  	
  	
  	
  v$sql_cs_histogram.count(0)++	
  
ELSIF	
  v$sql_cs_statistics.rows_processed	
  <	
  1M	
  THEN	
  
	
  	
  	
  	
  	
  	
  v$sql_cs_histogram.count(1)++	
  
ELSE	
  	
  	
  
	
  	
  	
  	
  	
  	
  v$sql_cs_histogram.count(2)++	
  
END	
  IF	
  
	
  
	
  
	
  
Enkitec	
  (c)	
  2014	
  
25	
  
Becoming	
  Bind	
  Aware	
  
1.  Small	
  and	
  Large	
  buckets	
  have	
  a	
  value	
  
–  bucket_id.count(0)	
  >	
  0	
  AND	
  bucket_id.count(2)	
  >	
  0	
  

2.  Two	
  adjacent	
  buckets	
  have	
  same	
  non-­‐zero	
  value	
  
–  bucket_id.count(0)	
  =	
  bucket_id.count(1)	
  >	
  0	
  
–  bucket_id.count(1)	
  =	
  bucket_id.count(2)	
  >	
  0	
  	
  

Enkitec	
  (c)	
  2014	
  

26	
  
Rows	
  Processed	
  per	
  Execu-on	
  
• 
• 
• 
• 
• 
• 
• 

10(0)…	
  50(0)…	
  3,000,000(2)…	
  BA	
  
30(0)…	
  3,000(1)…	
  BA	
  
2,000,000(2)…	
  1(0)…	
  BA	
  
0(0)…	
  10,000(1)…	
  BA	
  
3,000(1)…	
  2,000(1)…	
  200(0)…	
  300(0)…	
  BA	
  
10…	
  100…	
  500…	
  2,000…	
  3,000…	
  5,000…	
  BA	
  
rows_processed(bucket_id)…	
  Bind	
  Aware(BA)	
  
Enkitec	
  (c)	
  2014	
  

27	
  
WHY	
  becoming	
  BA	
  is	
  important?	
  
•  Mul-ple	
  Op-mal	
  Plans	
  are	
  created	
  aoer	
  Cursor	
  
becomes	
  Bind	
  Aware	
  

Enkitec	
  (c)	
  2014	
  

28	
  
Sample	
  Query	
  (1)	
  
SELECT	
  p.prod_subcategory_desc	
  subcatagory,	
  
	
  	
  	
  	
  	
  	
  	
  SUM(amount_sold)	
  amount_sold	
  
	
  	
  FROM	
  sh.customers	
  c,	
  
	
  	
  	
  	
  	
  	
  	
  sh.products	
  p,	
  
	
  	
  	
  	
  	
  	
  	
  sh.sales	
  s	
  
	
  WHERE	
  c.cust_gender	
  =	
  'M'	
  
	
  	
  	
  AND	
  c.cust_marital_status	
  =	
  'single'	
  
	
  	
  	
  AND	
  c.cust_year_of_birth	
  BETWEEN	
  1913	
  AND	
  1990	
  
	
  	
  	
  AND	
  p.prod_category	
  LIKE	
  'Software%'	
  
	
  	
  	
  AND	
  TO_CHAR(s.time_id,	
  'YYYY')	
  =	
  '2001'	
  
	
  	
  	
  AND	
  s.cust_id	
  =	
  c.cust_id	
  
	
  	
  	
  AND	
  s.prod_id	
  =	
  p.prod_id	
  
	
  GROUP	
  BY	
  
	
  	
  	
  	
  	
  	
  	
  p.prod_subcategory_desc	
  
	
  ORDER	
  BY	
  
	
  	
  	
  	
  	
  	
  	
  p.prod_subcategory_desc;	
  
Enkitec	
  (c)	
  2014	
  

29	
  
Sample	
  Query	
  (2)	
  
•  Based	
  on	
  Sample	
  Schema	
  SH	
  
–  With	
  CBO	
  Histograms	
  in	
  all	
  Columns	
  
•  Not	
  a	
  requirement	
  for	
  this	
  ACS	
  test	
  

• 
• 
• 
• 

3	
  Tables	
  with	
  Filter	
  Predicates	
  
2	
  Joins	
  
6	
  possible	
  Join	
  Orders	
  
Several	
  possible	
  Execu-on	
  Plans	
  
Enkitec	
  (c)	
  2014	
  

30	
  
Demo	
  1	
  
•  5	
  Execu-ons	
  of	
  Sample	
  Query	
  using	
  Literals	
  
–  Different	
  values	
  for	
  each	
  Execu-on	
  
•  Sequence	
  1,	
  2,	
  3,	
  4	
  and	
  5	
  

–  Each	
  Execu-on	
  performs	
  a	
  Hard	
  Parse	
  
–  Each	
  Execu-on	
  computes	
  a	
  “new”	
  Plan	
  
–  Each	
  seems	
  to	
  be	
  an	
  “Op-mal”	
  Plan	
  

Enkitec	
  (c)	
  2014	
  

31	
  
Demo	
  2	
  
•  5	
  Execu-ons	
  of	
  Sample	
  Query	
  using	
  Binds	
  
–  Different	
  values	
  for	
  each	
  Execu-on	
  
•  Sequence	
  1,	
  2,	
  3,	
  4	
  and	
  5	
  

–  Each	
  Execu-on	
  performs	
  a	
  Hard	
  Parse	
  
•  Forced	
  with	
  a	
  Cursor	
  Flush	
  before	
  the	
  Execu-on	
  

–  Each	
  computes	
  a	
  “new”	
  Op-mal	
  Plan	
  
•  Almost	
  same	
  as	
  “with	
  Literals”	
  

Enkitec	
  (c)	
  2014	
  

32	
  
Demo	
  2	
  Results	
  
Query	
   Rows	
  Processed	
   ACS	
  Bucket	
   Plan	
  Hash	
  Value	
  
1	
  

1,483,124	
  

2	
  

2048551027	
  

2	
  

1,272,154	
  

2	
  

3022804314	
  

3	
  

1,014,876	
  

2	
  

2326939410	
  

4	
  

716,168	
  

1	
  

2163719564	
  

5	
  

530	
  

0	
  

2163719564	
  

Enkitec	
  (c)	
  2014	
  

33	
  
Demo	
  3	
  
•  5	
  Execu-ons	
  of	
  Sample	
  Query	
  using	
  Binds	
  
–  Different	
  values	
  for	
  each	
  Execu-on	
  
•  Sequence	
  1,	
  2,	
  3,	
  4	
  and	
  5	
  

–  No	
  Cursor	
  Flush	
  between	
  Execu-ons	
  
–  First	
  Execu-on	
  computes	
  a	
  “new”	
  Op-mal	
  Plan	
  
–  All	
  Execu-ons	
  use	
  same	
  Plan…	
  

Enkitec	
  (c)	
  2014	
  

34	
  
Demo	
  3	
  Results	
  
Query	
   Rows	
  Processed	
   ACS	
  Bucket	
   Op,mal	
  Plan	
   ACS	
  Aware	
  

Executed	
  

1	
  

1,483,124	
  

2	
  

2048551027	
  

N	
  

2048551027	
  

2	
  

1,272,154	
  

2	
  

3022804314	
  

N	
  

2048551027	
  

3	
  

1,014,876	
  

2	
  

2326939410	
  

N	
  

2048551027	
  

4	
  

716,168	
  

1	
  

2163719564	
  

N	
  

2048551027	
  

5	
  

530	
  

0	
  

2163719564	
  

N	
  

2048551027	
  

Enkitec	
  (c)	
  2014	
  

35	
  
Demo	
  4	
  
•  5	
  Execu-ons	
  of	
  Sample	
  Query	
  using	
  Binds	
  
–  Different	
  values	
  for	
  each	
  Execu-on	
  
•  Sequence	
  5,	
  4,	
  3,	
  2	
  and	
  1	
  

–  No	
  Cursor	
  Flush	
  between	
  Execu-ons	
  
–  Cursor	
  becomes	
  Bind	
  Aware	
  aoer	
  2nd	
  Execu-on	
  
–  All	
  Execu-ons	
  used	
  an	
  Op-mal	
  Plan	
  

Enkitec	
  (c)	
  2014	
  

36	
  
Demo	
  4	
  Results	
  
Query	
   Rows	
  Processed	
   ACS	
  Bucket	
   Op,mal	
  Plan	
   Bind	
  Aware	
  

Executed	
  

5	
  

530	
  

0	
  

2163719564	
  

N	
  

2163719564	
  

4	
  

716,168	
  

1	
  

2163719564	
  

N	
  

2163719564	
  

3	
  

1,014,876	
  

2	
  

2326939410	
  

Y	
  

2326939410	
  

2	
  

1,272,154	
  

2	
  

3022804314	
  

Y	
  

3022804314	
  

1	
  

1,483,124	
  

2	
  

2048551027	
  

Y	
  

2048551027	
  

Enkitec	
  (c)	
  2014	
  

37	
  
Demo	
  5	
  
•  5	
  Execu-ons	
  of	
  Sample	
  Query	
  using	
  Binds	
  
–  Different	
  values	
  for	
  each	
  Execu-on	
  
•  Sequence	
  5,	
  1,	
  2,	
  3	
  and	
  4	
  

–  No	
  Cursor	
  Flush	
  between	
  Execu-ons	
  
–  Cursor	
  becomes	
  Bind	
  Aware	
  aoer	
  2nd	
  Execu-on	
  
–  All	
  but	
  one	
  Execu-ons	
  used	
  an	
  Op-mal	
  Plan	
  

Enkitec	
  (c)	
  2014	
  

38	
  
Demo	
  5	
  Results	
  
Query	
   Rows	
  Processed	
   ACS	
  Bucket	
   Op,mal	
  Plan	
   Bind	
  Aware	
  

Executed	
  

5	
  

530	
  

0	
  

2163719564	
  

N	
  

2163719564	
  

1	
  

1,483,124	
  

2	
  

2048551027	
  

N	
  

2163719564	
  

2	
  

1,272,154	
  

2	
  

3022804314	
  

Y	
  

3022804314	
  

3	
  

1,014,876	
  

2	
  

2326939410	
  

Y	
  

2326939410	
  

4	
  

716,168	
  

1	
  

2163719564	
  

Y	
  

2163719564	
  

Enkitec	
  (c)	
  2014	
  

39	
  
Controlling	
  ACS	
  with	
  CBO	
  Hint	
  
•  /*+	
  BIND_AWARE	
  */	
  
–  Bypasses	
  the	
  monitoring	
  phase	
  of	
  a	
  Bind	
  Sensi-ve	
  SQL	
  

•  /*+	
  NO_BIND_AWARE	
  */	
  
–  Turns	
  off	
  ACS	
  for	
  given	
  SQL	
  

Enkitec	
  (c)	
  2014	
  

40	
  
Controlling	
  ACS	
  with	
  SQL	
  Patch	
  
•  SYS.DBMS_SQLDIAG_INTERNAL.I_CREATE_PATCH	
  
–  sql_text	
  
–  hint_text	
  =>	
  BIND_AWARE	
  

•  Script	
  sqlpch.sql	
  

Enkitec	
  (c)	
  2014	
  

41	
  
ACS	
  Plan	
  Selec-on	
  
•  On	
  every	
  Execu-on	
  of	
  Bind	
  Aware	
  Cursor	
  
–  Compute	
  Selec-vity	
  of	
  each	
  qualifying	
  Predicate	
  
–  Search	
  Selec-vity	
  within	
  Range	
  of	
  values	
  on	
  ACS	
  
Selec-vity	
  Profile	
  
–  If	
  within	
  Range,	
  lookup	
  Child	
  Number	
  and	
  use	
  its	
  Plan	
  
–  Else,	
  Hard	
  Parse	
  and	
  Execute	
  newly	
  computed	
  Plan	
  
•  If	
  same	
  as	
  exis-ng	
  Plan,	
  then	
  update	
  Selec-vity	
  Profile	
  
•  Else,	
  create	
  Selec-vity	
  Profile	
  for	
  new	
  Child	
  Number	
  
Enkitec	
  (c)	
  2014	
  

42	
  
Selec-vity	
  Profile	
  (1)	
  
•  v$sql_cs_selec-vity	
  
–  predicate	
  
–  range_id	
  
•  low	
  and	
  high	
  (selec-vi-es)	
  

–  child_number	
  

Enkitec	
  (c)	
  2014	
  

43	
  
Selec-vity	
  Profile	
  (2)	
  
	
  	
  	
  	
  	
  	
  CHILD	
  PREDICATE	
  	
  	
  	
  	
  RANGE_ID	
  LOW	
  	
  	
  	
  	
  	
  	
  	
  HIGH	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  <=B4	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.860941	
  	
  	
  1.052262	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  =B1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.602369	
  	
  	
  0.736229	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  =B2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.455337	
  	
  	
  0.556523	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  >=B3	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.182445	
  	
  	
  0.222988	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  B5	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.306250	
  	
  	
  0.374306	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  <=B4	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.892666	
  	
  	
  1.091036	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  =B1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.297574	
  	
  	
  0.363702	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  =B2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.455337	
  	
  	
  0.556523	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  >=B3	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.077947	
  	
  	
  0.095268	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  B5	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.306250	
  	
  	
  0.374306	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  <=B4	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.836835	
  	
  	
  1.022798	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  =B1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.297574	
  	
  	
  0.363702	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  =B2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.002085	
  	
  	
  0.002548	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  >=B3	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.221447	
  	
  	
  0.270657	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  B5	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  0.306250	
  	
  	
  0.374306	
  
Enkitec	
  (c)	
  2014	
  

44	
  
ACS	
  Summary	
  
•  ACS	
  is	
  capable	
  of	
  producing	
  mul-ple	
  Op-mal	
  
Execu-on	
  Plans	
  per	
  SQL	
  
•  During	
  ramp-­‐up	
  sub	
  Op-mal	
  Plans	
  may	
  happen	
  
•  ACS	
  Metadata	
  resides	
  in	
  Memory	
  (not	
  Persistent)	
  
•  ACS	
  provides	
  desirable	
  Plan	
  Flexibility	
  
•  ACS	
  does	
  not	
  address	
  the	
  Plan	
  Stability	
  concern	
  
Enkitec	
  (c)	
  2014	
  

45	
  
SQL	
  Plan	
  Management	
  
•  11g+	
  
•  Mul-ple	
  Persistent	
  Op-mal	
  Execu-on	
  Plans	
  per	
  
SQL	
  
•  Only	
  “accepted”	
  and	
  “enabled”	
  Plans	
  are	
  Executed	
  
•  New	
  Plans	
  are	
  acknowledged	
  but	
  not	
  Executed	
  
•  Goal:	
  Plan	
  Stability	
  with	
  controlled	
  Flexibility	
  	
  
Enkitec	
  (c)	
  2014	
  

46	
  
SQL	
  Plan	
  Baseline	
  
•  A	
  set	
  of	
  Plans	
  available	
  to	
  the	
  CBO	
  for	
  a	
  given	
  SQL	
  
–  Iden-fied	
  by	
  SQL	
  Handle	
  and	
  Signature	
  	
  
•  Hash	
  func-on	
  on	
  SQL	
  Text	
  
•  dbms_sqltune.sqltext_to_signature	
  

–  View	
  dba_sql_plan_baselines	
  
•  enabled	
  =	
  YES	
  
•  accepted	
  =	
  YES	
  
•  reproduced	
  =	
  YES	
  
Enkitec	
  (c)	
  2014	
  

47	
  
Plan	
  History	
  
•  Content	
  of	
  dba_sql_plan_baselines	
  
•  Includes	
  SQL	
  Plan	
  Baseline	
  	
  
•  Includes	
  Pending	
  Plans	
  
–  accepted	
  =	
  NO	
  and	
  last_verified	
  is	
  NULL	
  

•  Includes	
  Rejected	
  Plans	
  
–  accepted	
  =	
  NO	
  and	
  last_verified	
  is	
  not	
  NULL	
  

•  Includes	
  Disabled	
  Plans	
  
Enkitec	
  (c)	
  2014	
  

48	
  
Methods	
  to	
  Create	
  a	
  Plan	
  Baseline	
  
1.  Capture	
  
2.  Load	
  
a.  Cursor	
  Cache	
  (CUR)	
  
b.  SQL	
  Tuning	
  Set	
  (STS)	
  
c.  Stored	
  Outline	
  

3.  Migra-on	
  

1.  Capture	
  
2.  Load	
  
a. 
b. 
c. 
d. 
e. 

CUR	
  
STS	
  
AWR	
  
SPA	
  
TRC	
  

3.  Migra-on	
  

Enkitec	
  (c)	
  2014	
  

49	
  
Capturing	
  a	
  SQL	
  Plan	
  Baseline	
  (1)	
  
•  Set	
  op-mizer_use_sql_plan_baselines	
  to	
  TRUE	
  
(default)	
  
•  Set	
  op-mizer_capture_sql_plan_baselines	
  to	
  TRUE	
  
(default	
  is	
  FALSE)	
  
–  Set	
  this	
  parameter	
  at	
  SESSION	
  level	
  

•  Execute	
  SQL	
  2	
  -mes	
  
•  Set	
  op-mizer_capture_sql_plan_baselines	
  to	
  
FALSE	
  
Enkitec	
  (c)	
  2014	
  

50	
  
Capturing	
  a	
  SQL	
  Plan	
  Baseline	
  (2)	
  

Enkitec	
  (c)	
  2014	
  

51	
  
Loading	
  SQL	
  Plan	
  Baseline	
  from	
  Cache	
  
•  dbms_spm.load_plans_from_cursor_cache	
  
–  Inputs	
  
•  sql_id	
  
•  plan_hash_value	
  (opt)	
  

–  Outputs	
  
•  Number	
  of	
  Plans	
  loaded	
  

Enkitec	
  (c)	
  2014	
  

52	
  
Demo	
  6	
  
•  Load	
  Plans	
  for	
  Query	
  out	
  of	
  Demo	
  5	
  
–  demo5.sql	
  
–  load_plans.sql	
  

•  Execute	
  Demo	
  5	
  again	
  and	
  review	
  Plan	
  History	
  
–  demo5.sql	
  
–  list_plans.sql	
  

•  Execute	
  demo5.sql	
  twice	
  and	
  verify	
  results	
  
Enkitec	
  (c)	
  2014	
  

53	
  
Demo	
  6	
  Results	
  (aoer	
  1st	
  demo5.sql)	
  
	
  	
  	
  	
  	
  	
  CHILD	
  	
  EXECUTIONS	
  BUFFER_GETS	
  PLAN_HASH_VALUE	
  SHAR	
  SENS	
  AWRE	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  	
  	
  	
  	
  	
  	
  	
  9090	
  	
  	
  	
  	
  	
  3022804314	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  N	
  
	
  
	
  	
  	
  	
  	
  	
  CHILD	
  	
  	
  BUCKET_ID	
  	
  	
  	
  	
  	
  	
  COUNT	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  
Note	
  
-­‐-­‐-­‐-­‐-­‐	
  
	
  	
  	
  -­‐	
  SQL	
  plan	
  baseline	
  SQL_PLAN_652hmt7yxthdwd624c0cd	
  used	
  for	
  this	
  statement	
  
	
  
CREATED	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  PLAN_NAME	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ENA	
  ACC	
  REP	
  FIX	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐	
  -­‐-­‐-­‐	
  -­‐-­‐-­‐	
  -­‐-­‐-­‐	
  
28-­‐DEC-­‐13	
  02.03.43.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdw501f1424	
  YES	
  YES	
  YES	
  NO	
  
28-­‐DEC-­‐13	
  02.03.43.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdwb6c39290	
  YES	
  YES	
  YES	
  NO	
  
28-­‐DEC-­‐13	
  02.03.43.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdwd624c0cd	
  YES	
  YES	
  YES	
  NO	
  
28-­‐DEC-­‐13	
  02.03.50.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdwc82a6b0c	
  YES	
  NO	
  	
  YES	
  NO	
  

Enkitec	
  (c)	
  2014	
  

54	
  
Demo	
  6	
  Results	
  (aoer	
  4rd	
  demo5.sql)	
  
	
  	
  	
  	
  	
  	
  CHILD	
  	
  EXECUTIONS	
  BUFFER_GETS	
  PLAN_HASH_VALUE	
  SHAR	
  SENS	
  AWRE	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  4274	
  	
  	
  	
  	
  	
  2163719564	
  N	
  	
  	
  	
  Y	
  	
  	
  	
  N	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  3030	
  	
  	
  	
  	
  	
  3022804314	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  3030	
  	
  	
  	
  	
  	
  2326939410	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  1587	
  	
  	
  	
  	
  	
  2163719564	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  
Note	
  
-­‐-­‐-­‐-­‐-­‐	
  
	
  	
  	
  -­‐	
  SQL	
  plan	
  baseline	
  SQL_PLAN_652hmt7yxthdwb6c39290	
  used	
  for	
  this	
  statement	
  
	
  
CREATED	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  PLAN_NAME	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ENA	
  ACC	
  REP	
  FIX	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐	
  -­‐-­‐-­‐	
  -­‐-­‐-­‐	
  -­‐-­‐-­‐	
  
28-­‐DEC-­‐13	
  02.03.43.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdw501f1424	
  YES	
  YES	
  YES	
  NO	
  
28-­‐DEC-­‐13	
  02.03.43.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdwb6c39290	
  YES	
  YES	
  YES	
  NO	
  
28-­‐DEC-­‐13	
  02.03.43.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdwd624c0cd	
  YES	
  YES	
  YES	
  NO	
  
28-­‐DEC-­‐13	
  02.03.50.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdwc82a6b0c	
  YES	
  NO	
  	
  YES	
  NO	
  

Enkitec	
  (c)	
  2014	
  

55	
  
Demo	
  7	
  
•  Drop	
  SQL	
  Plan	
  Baseline	
  
–  drop_plans.sql	
  

•  Create	
  SQL	
  Patch	
  with	
  /*+	
  BIND_AWARE	
  */	
  Hint	
  
–  sqlpch.sql	
  connected	
  as	
  SYS	
  

•  Load	
  Plans	
  for	
  Query	
  out	
  of	
  Demo	
  5	
  
–  demo5.sql	
  
–  load_plans.sql	
  
Enkitec	
  (c)	
  2014	
  

56	
  
Demo	
  7	
  Results	
  
	
  	
  	
  	
  	
  	
  CHILD	
  	
  EXECUTIONS	
  BUFFER_GETS	
  PLAN_HASH_VALUE	
  SHAR	
  SENS	
  AWRE	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  3052	
  	
  	
  	
  	
  	
  2163719564	
  N	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  3030	
  	
  	
  	
  	
  	
  2048551027	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  3030	
  	
  	
  	
  	
  	
  3022804314	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  3030	
  	
  	
  	
  	
  	
  2326939410	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  4	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  1587	
  	
  	
  	
  	
  	
  2163719564	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  
	
  
CREATED	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  PLAN_NAME	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ENA	
  ACC	
  REP	
  FIX	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐	
  -­‐-­‐-­‐	
  -­‐-­‐-­‐	
  -­‐-­‐-­‐	
  
28-­‐DEC-­‐13	
  02.31.11.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdw501f1424	
  YES	
  YES	
  YES	
  NO	
  
28-­‐DEC-­‐13	
  02.31.11.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdwb6c39290	
  YES	
  YES	
  YES	
  NO	
  
28-­‐DEC-­‐13	
  02.31.11.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdwc82a6b0c	
  YES	
  YES	
  YES	
  NO	
  
28-­‐DEC-­‐13	
  02.31.11.000000	
  PM	
  	
  	
  SQL_PLAN_652hmt7yxthdwd624c0cd	
  YES	
  YES	
  YES	
  NO	
  
	
  
	
  

Enkitec	
  (c)	
  2014	
  

57	
  
Demo	
  8	
  
•  Execute	
  queries	
  1-­‐5	
  and	
  observe	
  how	
  number	
  of	
  
Execu-ons	
  increases	
  per	
  Child	
  Cursor	
  
–  flush.sql	
  
–  demo8.sql	
  
–  demo8.sql	
  
–  demo8.sql	
  

Enkitec	
  (c)	
  2014	
  

58	
  
Demo	
  8	
  Results	
  

	
  CHILD	
  	
  EXECUTIONS	
  BUFFER_GETS	
  PLAN_HASH_VALUE	
  SHAR	
  SENS	
  AWRE	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  1585	
  	
  	
  	
  	
  	
  2163719564	
  N	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  3030	
  	
  	
  	
  	
  	
  2048551027	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  3030	
  	
  	
  	
  	
  	
  3022804314	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  3030	
  	
  	
  	
  	
  	
  2326939410	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  4	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  3172	
  	
  	
  	
  	
  	
  2163719564	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  
Note	
  
-­‐-­‐-­‐-­‐-­‐	
  
	
  	
  	
  -­‐	
  SQL	
  patch	
  "sqlpch_8u0n7w1jug5dg"	
  used	
  for	
  this	
  statement	
  
	
  	
  	
  -­‐	
  SQL	
  plan	
  baseline	
  SQL_PLAN_652hmt7yxthdwb6c39290	
  used	
  for	
  this	
  statement	
  
	
  
	
  	
  	
  	
  	
  	
  CHILD	
  	
  EXECUTIONS	
  BUFFER_GETS	
  PLAN_HASH_VALUE	
  SHAR	
  SENS	
  AWRE	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  1585	
  	
  	
  	
  	
  	
  2163719564	
  N	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  6060	
  	
  	
  	
  	
  	
  2048551027	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  6060	
  	
  	
  	
  	
  	
  3022804314	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  6060	
  	
  	
  	
  	
  	
  2326939410	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  4	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  4	
  	
  	
  	
  	
  	
  	
  	
  6344	
  	
  	
  	
  	
  	
  2163719564	
  Y	
  	
  	
  	
  Y	
  	
  	
  	
  Y	
  	
  

Enkitec	
  (c)	
  2014	
  

59	
  
Evolving	
  a	
  Plan	
  
•  Evolving	
  a	
  Plan	
  means	
  “accep-ng”	
  it	
  
–  Promo-ng	
  it	
  from	
  Plan	
  History	
  into	
  SQL	
  Plan	
  Baseline	
  

•  dbms_spm.evolve_sql_plan_baseline	
  
–  sql_handle	
  (opt)	
  
–  plan_name	
  (opt)	
  
–  verify	
  (default	
  YES)	
  
–  commit	
  (default	
  YES)	
  
Enkitec	
  (c)	
  2014	
  

60	
  
Demo	
  9	
  
•  Drop	
  SQL	
  Plan	
  Baseline	
  
–  drop_plans.sql	
  

•  Capture	
  SQL	
  Plan	
  Baseline	
  with	
  1	
  accepted	
  Plan	
  
–  demo9.sql	
  
–  list_plans.sql	
  

•  Evolve	
  all	
  Plans	
  on	
  Plan	
  History	
  
–  evolve.sql	
  
Enkitec	
  (c)	
  2014	
  

61	
  
FIXED	
  Flag	
  
•  When	
  set	
  to	
  YES	
  
–  Only	
  FIXED	
  Plans	
  are	
  considered	
  for	
  Plan	
  Selec-on	
  
–  No	
  more	
  Plans	
  are	
  Captured	
  into	
  Plan	
  History	
  

Enkitec	
  (c)	
  2014	
  

62	
  
Plan	
  Selec-on	
  (1)	
  
•  At	
  hard	
  parse	
  when	
  SQL	
  Plan	
  Baseline	
  (SPB)	
  exists	
  
1.  CBO	
  computes	
  an	
  “Op-mal”	
  Plan	
  (OP)	
  
• 

Adap-ve	
  Cursor	
  Sharing	
  is	
  used	
  if	
  applicable	
  

2.  If	
  OP	
  exists	
  in	
  SPB	
  then	
  execute	
  this	
  OP	
  
3.  If	
  OP	
  does	
  not	
  exist	
  in	
  SPB	
  then	
  store	
  it	
  in	
  Plan	
  History	
  
a. 

If	
  there	
  are	
  FIXED	
  Plans	
  in	
  SPB	
  
i. 

Re-­‐cost	
  all	
  FIXED	
  Plans	
  using	
  Binds	
  and	
  execute	
  cheapest	
  

b.  If	
  there	
  are	
  no	
  FIXED	
  Plans	
  in	
  SPM	
  
i. 

Re-­‐cost	
  all	
  Plans	
  using	
  Binds	
  and	
  execute	
  cheapest	
  
Enkitec	
  (c)	
  2014	
  

63	
  
Plan	
  Selec-on	
  (2)	
  

Enkitec	
  (c)	
  2014	
  

64	
  
Demo	
  10	
  
•  FIX	
  one	
  Plan	
  from	
  SQL	
  Plan	
  Baseline	
  
–  alter_plans.sql	
  

•  Verify	
  only	
  one	
  Plan	
  was	
  Executed	
  
–  flush.sql	
  
–  demo8.sql	
  
–  demo8.sql	
  

Enkitec	
  (c)	
  2014	
  

65	
  
SPM	
  Summary	
  
•  SPM	
  provides	
  much	
  desired	
  Plan	
  Stability	
  
–  Only	
  “approved”	
  Plans	
  are	
  allowed	
  to	
  Execute	
  

•  ACS	
  can	
  generate	
  a	
  healthy	
  stock	
  of	
  Op-mal	
  Plans	
  
–  You	
  can	
  restrict	
  them	
  to	
  work	
  under	
  SPM	
  

•  Combining	
  ACS	
  and	
  SPM	
  you	
  can	
  obtain	
  
–  Plan	
  Flexibility	
  and	
  Plan	
  Stability	
  

Enkitec	
  (c)	
  2014	
  

66	
  
SPM/ACS	
  Suggested	
  Strategy	
  
•  Use	
  dbms_applica-on_info.set_module	
  in	
  your	
  
code	
  to	
  set	
  MODULE	
  and	
  ACTION	
  
•  Use	
  dbms_spm.load_plans_from_cursor_cache	
  
filtering	
  with	
  MODULE	
  or	
  ACTION	
  
•  Use	
  sys.dbms_sqldiag_internal.i_create_patch	
  to	
  
SQL	
  Patch	
  with	
  BIND_AWARE	
  the	
  SQL	
  on	
  Baselines	
  	
  
•  Use	
  dbms_spm.evolve_sql_plan_baseline	
  to	
  verify	
  
and	
  evolve	
  periodically	
  good	
  performing	
  Plans	
  
Enkitec	
  (c)	
  2014	
  

67	
  
Oracle	
  Pack	
  Licenses	
  
•  DBMS_SPM	
  
–  No	
  Oracle	
  Pack	
  License	
  

•  DBMS_SQLTUNE	
  
–  Oracle	
  Tuning	
  Pack	
  

•  AWR	
  
–  Oracle	
  Diagnos-cs	
  Pack	
  

Enkitec	
  (c)	
  2014	
  

68	
  
References	
  (1)	
  
•  Random	
  Slowdown	
  by	
  Jonathan	
  Lewis	
  
–  h{p://jonathanlewis.wordpress.com/2013/12/23/
plan-­‐changes/	
  

•  Using	
  SQL	
  Patch	
  to	
  add	
  hints	
  to	
  a	
  packaged	
  
applica-on	
  
–  h{ps://blogs.oracle.com/op-mizer/entry/
how_can_i_hint_a	
  
Enkitec	
  (c)	
  2014	
  

69	
  
References	
  (2)	
  
•  SQL	
  Plan	
  Management	
  SPM	
  Aware	
  Op-mizer	
  
–  h{ps://blogs.oracle.com/op-mizer/entry/
sql_plan_management_part_2_of_4_spm_aware_opmizer	
  

•  SQLTXPLAIN	
  MOS	
  215187.1	
  
–  sqlt/utl/spm	
  

Enkitec	
  (c)	
  2014	
  

70	
  
References	
  (3)	
  
•  Oracle®	
  Database	
  PL/SQL	
  Packages	
  and	
  Types	
  
Reference	
  
–  11g	
  Release	
  2	
  (11.2)	
  
–  Part	
  Number	
  E25788-­‐04	
  

Enkitec	
  (c)	
  2014	
  

71	
  
Contact	
  Informa-on	
  
•  carlos.sierra@enkitec.com	
  
•  carlos-­‐sierra.net	
  
•  @csierra_usa	
  

Enkitec	
  (c)	
  2014	
  

72	
  

Mais conteúdo relacionado

Semelhante a Combining ACS Flexibility with SPM Stability

Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...Enkitec
 
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan StabilityUsing SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan StabilityCarlos Sierra
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresJitendra Singh
 
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveApache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveXu Jiang
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteChris Baynes
 
Macy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightMacy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightDataStax Academy
 
Foundations of streaming SQL: stream & table theory
Foundations of streaming SQL: stream & table theoryFoundations of streaming SQL: stream & table theory
Foundations of streaming SQL: stream & table theoryDataWorks Summit
 
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...StreamNative
 
moabcon2012 - Transitioning from Grid Engine
moabcon2012 - Transitioning from Grid Enginemoabcon2012 - Transitioning from Grid Engine
moabcon2012 - Transitioning from Grid EngineFrédérick Lefebvre
 
SQLServerDays2012_SSIS_CDC
SQLServerDays2012_SSIS_CDCSQLServerDays2012_SSIS_CDC
SQLServerDays2012_SSIS_CDCKoenVerbeeck
 
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1Navneet Upneja
 
Some Iceberg Basics for Beginners (CDP).pdf
Some Iceberg Basics for Beginners (CDP).pdfSome Iceberg Basics for Beginners (CDP).pdf
Some Iceberg Basics for Beginners (CDP).pdfMichael Kogan
 
Self-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
Self-serve analytics journey at Celtra: Snowflake, Spark, and DatabricksSelf-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
Self-serve analytics journey at Celtra: Snowflake, Spark, and DatabricksGrega Kespret
 
Sql source control
Sql source controlSql source control
Sql source controlAndyPickett
 
Introduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overviewIntroduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overviewAnvith S. Upadhyaya
 
Windows Azure: Lessons From the Field
Windows Azure: Lessons From the FieldWindows Azure: Lessons From the Field
Windows Azure: Lessons From the FieldMichael Collier
 
Meeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with ScyllaMeeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with ScyllaScyllaDB
 

Semelhante a Combining ACS Flexibility with SPM Stability (20)

Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
 
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan StabilityUsing SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and Underscores
 
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveApache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache Calcite
 
Macy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightMacy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-Flight
 
Foundations of streaming SQL: stream & table theory
Foundations of streaming SQL: stream & table theoryFoundations of streaming SQL: stream & table theory
Foundations of streaming SQL: stream & table theory
 
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...
Pulsar in the Lakehouse: Overview of Apache Pulsar and Delta Lake Connector -...
 
seminar100326a.pdf
seminar100326a.pdfseminar100326a.pdf
seminar100326a.pdf
 
moabcon2012 - Transitioning from Grid Engine
moabcon2012 - Transitioning from Grid Enginemoabcon2012 - Transitioning from Grid Engine
moabcon2012 - Transitioning from Grid Engine
 
SQLServerDays2012_SSIS_CDC
SQLServerDays2012_SSIS_CDCSQLServerDays2012_SSIS_CDC
SQLServerDays2012_SSIS_CDC
 
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1
 
Some Iceberg Basics for Beginners (CDP).pdf
Some Iceberg Basics for Beginners (CDP).pdfSome Iceberg Basics for Beginners (CDP).pdf
Some Iceberg Basics for Beginners (CDP).pdf
 
Self-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
Self-serve analytics journey at Celtra: Snowflake, Spark, and DatabricksSelf-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
Self-serve analytics journey at Celtra: Snowflake, Spark, and Databricks
 
Sql source control
Sql source controlSql source control
Sql source control
 
SQL Tuning 101
SQL Tuning 101SQL Tuning 101
SQL Tuning 101
 
sqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdfsqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdf
 
Introduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overviewIntroduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overview
 
Windows Azure: Lessons From the Field
Windows Azure: Lessons From the FieldWindows Azure: Lessons From the Field
Windows Azure: Lessons From the Field
 
Meeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with ScyllaMeeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with Scylla
 

Mais de Enkitec

Using Angular JS in APEX
Using Angular JS in APEXUsing Angular JS in APEX
Using Angular JS in APEXEnkitec
 
Controlling execution plans 2014
Controlling execution plans   2014Controlling execution plans   2014
Controlling execution plans 2014Enkitec
 
Engineered Systems: Environment-as-a-Service Demonstration
Engineered Systems: Environment-as-a-Service DemonstrationEngineered Systems: Environment-as-a-Service Demonstration
Engineered Systems: Environment-as-a-Service DemonstrationEnkitec
 
Think Exa!
Think Exa!Think Exa!
Think Exa!Enkitec
 
In Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry OsborneIn Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry OsborneEnkitec
 
In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1Enkitec
 
Mini Session - Using GDB for Profiling
Mini Session - Using GDB for ProfilingMini Session - Using GDB for Profiling
Mini Session - Using GDB for ProfilingEnkitec
 
Profiling Oracle with GDB
Profiling Oracle with GDBProfiling Oracle with GDB
Profiling Oracle with GDBEnkitec
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the TradeEnkitec
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsEnkitec
 
SQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeSQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeEnkitec
 
Oracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture PerformanceOracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture PerformanceEnkitec
 
OGG Architecture Performance
OGG Architecture PerformanceOGG Architecture Performance
OGG Architecture PerformanceEnkitec
 
APEX Security Primer
APEX Security PrimerAPEX Security Primer
APEX Security PrimerEnkitec
 
How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?Enkitec
 
Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Enkitec
 
Profiling the logwriter and database writer
Profiling the logwriter and database writerProfiling the logwriter and database writer
Profiling the logwriter and database writerEnkitec
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014Fatkulin hotsos 2014
Fatkulin hotsos 2014Enkitec
 
Why You May Not Need Offloading
Why You May Not Need OffloadingWhy You May Not Need Offloading
Why You May Not Need OffloadingEnkitec
 
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEX
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEXLOBS, BLOBS, CLOBS: Dealing with Attachments in APEX
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEXEnkitec
 

Mais de Enkitec (20)

Using Angular JS in APEX
Using Angular JS in APEXUsing Angular JS in APEX
Using Angular JS in APEX
 
Controlling execution plans 2014
Controlling execution plans   2014Controlling execution plans   2014
Controlling execution plans 2014
 
Engineered Systems: Environment-as-a-Service Demonstration
Engineered Systems: Environment-as-a-Service DemonstrationEngineered Systems: Environment-as-a-Service Demonstration
Engineered Systems: Environment-as-a-Service Demonstration
 
Think Exa!
Think Exa!Think Exa!
Think Exa!
 
In Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry OsborneIn Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry Osborne
 
In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1
 
Mini Session - Using GDB for Profiling
Mini Session - Using GDB for ProfilingMini Session - Using GDB for Profiling
Mini Session - Using GDB for Profiling
 
Profiling Oracle with GDB
Profiling Oracle with GDBProfiling Oracle with GDB
Profiling Oracle with GDB
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 
SQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeSQL Tuning Tools of the Trade
SQL Tuning Tools of the Trade
 
Oracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture PerformanceOracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture Performance
 
OGG Architecture Performance
OGG Architecture PerformanceOGG Architecture Performance
OGG Architecture Performance
 
APEX Security Primer
APEX Security PrimerAPEX Security Primer
APEX Security Primer
 
How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?
 
Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)
 
Profiling the logwriter and database writer
Profiling the logwriter and database writerProfiling the logwriter and database writer
Profiling the logwriter and database writer
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014Fatkulin hotsos 2014
Fatkulin hotsos 2014
 
Why You May Not Need Offloading
Why You May Not Need OffloadingWhy You May Not Need Offloading
Why You May Not Need Offloading
 
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEX
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEXLOBS, BLOBS, CLOBS: Dealing with Attachments in APEX
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEX
 

Último

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Último (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Combining ACS Flexibility with SPM Stability

  • 1. Combining   Adap-ve  Cursor  Sharing  (ACS)  Flexibility   with     SQL  Plan  Management  (SPM)  Stability   Carlos  Sierra  
  • 2. Carlos  Sierra   •  •  •  •  •  Consultant/Developer/DBA   Oracle  Performance   SQLTXPLAIN  (SQLT)   SQL  Tuning   Tools   Enkitec  (c)  2014   2  
  • 3. Topics   •  •  •  •  Plan  Flexibility  and  Plan  Stability   Adap-ve  Cursor  Sharing  (ACS)   SQL  Plan  Management  (SPM)   Combining  ACS  and  SPM   Enkitec  (c)  2014   3  
  • 4. Plan  Flexibility   •  Cost-­‐based  Op-mizer  (CBO)   –  Introduced  in  Oracle  7   –  Computes  an  Op-mal  Plan  based  on     •  Heuris-cs   •  Query  Predicates   •  Schema  Object  Sta-s-cs   •  Several  Others   Enkitec  (c)  2014   4  
  • 5. Flexibility:  Good  or  Evil?   •  CBO  Mission   –  Compute  an  Op-mal  Plan  for  a  given  SQL  and  its  Data   •  Plans  have  many  and  complex  Dependencies   •  CBO  Performance   –  Successful  most  of  the  -mes   •  Produces  a  sub-­‐op-mal  Plan  some&mes   Enkitec  (c)  2014   5  
  • 6. DBA  Recurrent  Bad  Dream   •  A  business  cri-cal  process  experiences  an   occasional  slow  down   –  Same  SQL  usually  runs  very  quickly   –  Developers  claim  they  haven’t  changed  anything   –  Users  claim  they  do  the  same  every  -me   –  Business  is  sick  and  -red  of  repor-ng  this  to…  YOU!   Enkitec  (c)  2014   6  
  • 7. Plan  Performs  Inconsistently?  (1)   •  •  •  •  •  •  Concurrency  with  some  other  Process   State  of  Buffer  Cache   RAC  Node  Affinity   CPU  Starva-on   Sudden  Changes  on  Data  Volume   Inconsistent  Performance  through  Database  Link   Enkitec  (c)  2014   7  
  • 8. Plan  Performs  Inconsistently?  (2)   •  •  •  •  •  Downgraded  Parallel  Execu-on   Crossing  Small-­‐Table  Threshold   Resource  Manager  Direc-ve   Plan  Flips   Many  Others…   Enkitec  (c)  2014   8  
  • 9. WHY  a  Plan  Flips?  (1)   •  •  •  •  •  Bind  Variable  Peeking  with  Histograms   Outdated  Schema  Object  (SO)  Sta-s-cs   Missing  SO  Sta-s-cs   Fresh  SO  Sta-s-cs   New  Empty  Par--ons   Enkitec  (c)  2014   9  
  • 10. WHY  a  Plan  Flips?  (2)   •  Incomplete  set  of  CBO  Hints   –  Either  on  SQL  Text  or  SQL  Profile   •  Dropped,  Invalid,  Invisible  or  new  Indexes   •  Index  or  Table  rebuild   •  Two  or  more  Plans  with  similar  Cost   Enkitec  (c)  2014   10  
  • 11. WHY  a  Plan  Flips?  (3)   •  •  •  •  Database  Parameters  Changes   CBO  System  Sta-s-cs  Changes   Asynchronous  SO  Sta-s-cs  Gathering   Many  Others…   Enkitec  (c)  2014   11  
  • 12. How  to  Mi-gate  Plan  Flipping   •  Sound  CBO  Sta-s-cs   •  Default  CBO  Parameters   •  Regulate  Global  Changes   Enkitec  (c)  2014   12  
  • 13. Plan  Flexibility  Allies   •  •  •  •  •  •  CBO  Parameters   CBO  Sta-s-cs   Dynamic  Sampling   Cardinality  Feedback   Cursor  Sharing   Adap,ve  Cursor  Sharing  (ACS)   Enkitec  (c)  2014   13  
  • 14. Plan  Stability  Tools   •  •  •  •  CBO  Hints   Stored  Outlines   SQL  Profiles   SQL  Plan  Management  (SPM)   Enkitec  (c)  2014   14  
  • 15. Cursor  Sharing   •  Use  of  Bind  Variables  instead  of  Literals   –  AND  p.prod_category  LIKE  'Sooware%’   –  AND  p.prod_category  LIKE  :b5   •  Goal:  Reduce  Hard  Parsing   –  Improve  Scalability   •  Reduce  CPU  u-liza-on   •  Reduce  Shared  Memory  footprint   Enkitec  (c)  2014   15  
  • 16. Cursor  Sharing  Shortcomings   •  Flipping  Plans   –  Exacerbated  by  Histograms  on  Skewed  Data     –  AND  c.cust_marital_status  =  :b2   •  :b2  :=  ‘married’   •  :b2  :=  ‘widow’   –  Plan  is  computed  at  hard  parse   •  Plan  becomes  a  long  term  moving  target   Enkitec  (c)  2014   16  
  • 17. Adap-ve  Cursor  Sharing  (ACS)   •  11g+   •  Mul-ple  Op-mal  Plans  per  SQL   –  As  per  “Selec-vity”  of  Predicates   •  :b2  :=  ‘married’  (close  to  60%  maybe)   •  :b2  :=  ‘widow’  (this  one  is  more  selec-ve)   Enkitec  (c)  2014   17  
  • 18. ACS  Challenges   •  Minimize  Resources  Impact   –  Monitor  only  a  subset  of  SQL  Statements   –  Ac-vate  ACS  only  for  a  subset  of  the  monitored  SQL   –  Share  Execu-ons  Plans  through  a  “Selec-vity  Profile”   Bind  Aware   ACS   Bind  Sensi-ve   All  Statements   Enkitec  (c)  2014   18  
  • 19. Becoming  Bind  Sensi-ve   1.  SQL  has  Range  Predicates  on  Bind  Variables   –  AND  c.cust_year_of_birth  BETWEEN  :b3  AND  :b4   –  AND  p.prod_category  LIKE  :b5   2.  SQL  has  Equality  Predicates  on  Bind  Variables  and   Column  has  a  Histogram   –  AND  c.cust_marital_status  =  :b2   –  AND  TO_CHAR(s.-me_id,  'YYYY')  =  :b6   Enkitec  (c)  2014   19  
  • 20. Becoming  Bind  Aware   1.  Rows  Processed  change  substan-ally  between   Execu-ons   –  Between  a  few  rows  to  millions   2.  Rows  Processed  oscillate  significantly  between   Execu-ons   –  Between  a  few  rows  and  a  few  thousand   –  Between  a  few  thousand  and  millions   Enkitec  (c)  2014   20  
  • 21. ACS  Monitoring   •  V$SQL  (State)   –  is_shareable   –  is_bind_sensi-ve   –  is_bind_aware   •  V$SQL_CS_STATISTICS  (Rows  Processed)   •  V$SQL_CS_HISTOGRAM  (3  Buckets  S/M/L)   •  V$SQL_CS_SELECTIVITY  (Selec-vity  Profile)   Enkitec  (c)  2014   21  
  • 22. Rows  Processed   •  •  •  •  v$sql_cs_sta-s-cs.rows_processed   Updated  only  at  hard  parse   A  measure  of  amount  of  work  on  Execu-on  Plan   Three  sizes:  S/M/L   –  0:  Small     –  1:  Medium     –  2:  Large   Enkitec  (c)  2014   22  
  • 23. Rows  Processed   •  •  •  •  v$sql_cs_sta-s-cs.rows_processed   Updated  only  at  hard  parse   A  measure  of  amount  of  work  on  Execu-on  Plan   Three  sizes:  S/M/L   –  0:  Small  (less  than  1K  rows)   –  1:  Medium  (between  1k  and  1m  rows)   –  2:  Large  (more  than  1m  rows)   Enkitec  (c)  2014   23  
  • 24. ACS  Buckets   •  v$sql_cs_histogram.bucket_id   –  0:  Small   –  1:  Medium   –  2:  Large   •  v$sql_cs_histogram.count   –  Incremented  with  each  Execu-on  as  per   •  v$sql_cs_sta-s-cs.rows_processed   Enkitec  (c)  2014   24  
  • 25. Rows  Processed  and  ACS  Buckets   IF        v$sql_cs_statistics.rows_processed  <  1K  THEN              v$sql_cs_histogram.count(0)++   ELSIF  v$sql_cs_statistics.rows_processed  <  1M  THEN              v$sql_cs_histogram.count(1)++   ELSE                  v$sql_cs_histogram.count(2)++   END  IF         Enkitec  (c)  2014   25  
  • 26. Becoming  Bind  Aware   1.  Small  and  Large  buckets  have  a  value   –  bucket_id.count(0)  >  0  AND  bucket_id.count(2)  >  0   2.  Two  adjacent  buckets  have  same  non-­‐zero  value   –  bucket_id.count(0)  =  bucket_id.count(1)  >  0   –  bucket_id.count(1)  =  bucket_id.count(2)  >  0     Enkitec  (c)  2014   26  
  • 27. Rows  Processed  per  Execu-on   •  •  •  •  •  •  •  10(0)…  50(0)…  3,000,000(2)…  BA   30(0)…  3,000(1)…  BA   2,000,000(2)…  1(0)…  BA   0(0)…  10,000(1)…  BA   3,000(1)…  2,000(1)…  200(0)…  300(0)…  BA   10…  100…  500…  2,000…  3,000…  5,000…  BA   rows_processed(bucket_id)…  Bind  Aware(BA)   Enkitec  (c)  2014   27  
  • 28. WHY  becoming  BA  is  important?   •  Mul-ple  Op-mal  Plans  are  created  aoer  Cursor   becomes  Bind  Aware   Enkitec  (c)  2014   28  
  • 29. Sample  Query  (1)   SELECT  p.prod_subcategory_desc  subcatagory,                SUM(amount_sold)  amount_sold      FROM  sh.customers  c,                sh.products  p,                sh.sales  s    WHERE  c.cust_gender  =  'M'        AND  c.cust_marital_status  =  'single'        AND  c.cust_year_of_birth  BETWEEN  1913  AND  1990        AND  p.prod_category  LIKE  'Software%'        AND  TO_CHAR(s.time_id,  'YYYY')  =  '2001'        AND  s.cust_id  =  c.cust_id        AND  s.prod_id  =  p.prod_id    GROUP  BY                p.prod_subcategory_desc    ORDER  BY                p.prod_subcategory_desc;   Enkitec  (c)  2014   29  
  • 30. Sample  Query  (2)   •  Based  on  Sample  Schema  SH   –  With  CBO  Histograms  in  all  Columns   •  Not  a  requirement  for  this  ACS  test   •  •  •  •  3  Tables  with  Filter  Predicates   2  Joins   6  possible  Join  Orders   Several  possible  Execu-on  Plans   Enkitec  (c)  2014   30  
  • 31. Demo  1   •  5  Execu-ons  of  Sample  Query  using  Literals   –  Different  values  for  each  Execu-on   •  Sequence  1,  2,  3,  4  and  5   –  Each  Execu-on  performs  a  Hard  Parse   –  Each  Execu-on  computes  a  “new”  Plan   –  Each  seems  to  be  an  “Op-mal”  Plan   Enkitec  (c)  2014   31  
  • 32. Demo  2   •  5  Execu-ons  of  Sample  Query  using  Binds   –  Different  values  for  each  Execu-on   •  Sequence  1,  2,  3,  4  and  5   –  Each  Execu-on  performs  a  Hard  Parse   •  Forced  with  a  Cursor  Flush  before  the  Execu-on   –  Each  computes  a  “new”  Op-mal  Plan   •  Almost  same  as  “with  Literals”   Enkitec  (c)  2014   32  
  • 33. Demo  2  Results   Query   Rows  Processed   ACS  Bucket   Plan  Hash  Value   1   1,483,124   2   2048551027   2   1,272,154   2   3022804314   3   1,014,876   2   2326939410   4   716,168   1   2163719564   5   530   0   2163719564   Enkitec  (c)  2014   33  
  • 34. Demo  3   •  5  Execu-ons  of  Sample  Query  using  Binds   –  Different  values  for  each  Execu-on   •  Sequence  1,  2,  3,  4  and  5   –  No  Cursor  Flush  between  Execu-ons   –  First  Execu-on  computes  a  “new”  Op-mal  Plan   –  All  Execu-ons  use  same  Plan…   Enkitec  (c)  2014   34  
  • 35. Demo  3  Results   Query   Rows  Processed   ACS  Bucket   Op,mal  Plan   ACS  Aware   Executed   1   1,483,124   2   2048551027   N   2048551027   2   1,272,154   2   3022804314   N   2048551027   3   1,014,876   2   2326939410   N   2048551027   4   716,168   1   2163719564   N   2048551027   5   530   0   2163719564   N   2048551027   Enkitec  (c)  2014   35  
  • 36. Demo  4   •  5  Execu-ons  of  Sample  Query  using  Binds   –  Different  values  for  each  Execu-on   •  Sequence  5,  4,  3,  2  and  1   –  No  Cursor  Flush  between  Execu-ons   –  Cursor  becomes  Bind  Aware  aoer  2nd  Execu-on   –  All  Execu-ons  used  an  Op-mal  Plan   Enkitec  (c)  2014   36  
  • 37. Demo  4  Results   Query   Rows  Processed   ACS  Bucket   Op,mal  Plan   Bind  Aware   Executed   5   530   0   2163719564   N   2163719564   4   716,168   1   2163719564   N   2163719564   3   1,014,876   2   2326939410   Y   2326939410   2   1,272,154   2   3022804314   Y   3022804314   1   1,483,124   2   2048551027   Y   2048551027   Enkitec  (c)  2014   37  
  • 38. Demo  5   •  5  Execu-ons  of  Sample  Query  using  Binds   –  Different  values  for  each  Execu-on   •  Sequence  5,  1,  2,  3  and  4   –  No  Cursor  Flush  between  Execu-ons   –  Cursor  becomes  Bind  Aware  aoer  2nd  Execu-on   –  All  but  one  Execu-ons  used  an  Op-mal  Plan   Enkitec  (c)  2014   38  
  • 39. Demo  5  Results   Query   Rows  Processed   ACS  Bucket   Op,mal  Plan   Bind  Aware   Executed   5   530   0   2163719564   N   2163719564   1   1,483,124   2   2048551027   N   2163719564   2   1,272,154   2   3022804314   Y   3022804314   3   1,014,876   2   2326939410   Y   2326939410   4   716,168   1   2163719564   Y   2163719564   Enkitec  (c)  2014   39  
  • 40. Controlling  ACS  with  CBO  Hint   •  /*+  BIND_AWARE  */   –  Bypasses  the  monitoring  phase  of  a  Bind  Sensi-ve  SQL   •  /*+  NO_BIND_AWARE  */   –  Turns  off  ACS  for  given  SQL   Enkitec  (c)  2014   40  
  • 41. Controlling  ACS  with  SQL  Patch   •  SYS.DBMS_SQLDIAG_INTERNAL.I_CREATE_PATCH   –  sql_text   –  hint_text  =>  BIND_AWARE   •  Script  sqlpch.sql   Enkitec  (c)  2014   41  
  • 42. ACS  Plan  Selec-on   •  On  every  Execu-on  of  Bind  Aware  Cursor   –  Compute  Selec-vity  of  each  qualifying  Predicate   –  Search  Selec-vity  within  Range  of  values  on  ACS   Selec-vity  Profile   –  If  within  Range,  lookup  Child  Number  and  use  its  Plan   –  Else,  Hard  Parse  and  Execute  newly  computed  Plan   •  If  same  as  exis-ng  Plan,  then  update  Selec-vity  Profile   •  Else,  create  Selec-vity  Profile  for  new  Child  Number   Enkitec  (c)  2014   42  
  • 43. Selec-vity  Profile  (1)   •  v$sql_cs_selec-vity   –  predicate   –  range_id   •  low  and  high  (selec-vi-es)   –  child_number   Enkitec  (c)  2014   43  
  • 44. Selec-vity  Profile  (2)              CHILD  PREDICATE          RANGE_ID  LOW                HIGH   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐                      1  <=B4                                  0  0.860941      1.052262                      1  =B1                                    0  0.602369      0.736229                      1  =B2                                    0  0.455337      0.556523                      1  >=B3                                  0  0.182445      0.222988                      1  B5                                      0  0.306250      0.374306                      2  <=B4                                  0  0.892666      1.091036                      2  =B1                                    0  0.297574      0.363702                      2  =B2                                    0  0.455337      0.556523                      2  >=B3                                  0  0.077947      0.095268                      2  B5                                      0  0.306250      0.374306                      3  <=B4                                  0  0.836835      1.022798                      3  =B1                                    0  0.297574      0.363702                      3  =B2                                    0  0.002085      0.002548                      3  >=B3                                  0  0.221447      0.270657                      3  B5                                      0  0.306250      0.374306   Enkitec  (c)  2014   44  
  • 45. ACS  Summary   •  ACS  is  capable  of  producing  mul-ple  Op-mal   Execu-on  Plans  per  SQL   •  During  ramp-­‐up  sub  Op-mal  Plans  may  happen   •  ACS  Metadata  resides  in  Memory  (not  Persistent)   •  ACS  provides  desirable  Plan  Flexibility   •  ACS  does  not  address  the  Plan  Stability  concern   Enkitec  (c)  2014   45  
  • 46. SQL  Plan  Management   •  11g+   •  Mul-ple  Persistent  Op-mal  Execu-on  Plans  per   SQL   •  Only  “accepted”  and  “enabled”  Plans  are  Executed   •  New  Plans  are  acknowledged  but  not  Executed   •  Goal:  Plan  Stability  with  controlled  Flexibility     Enkitec  (c)  2014   46  
  • 47. SQL  Plan  Baseline   •  A  set  of  Plans  available  to  the  CBO  for  a  given  SQL   –  Iden-fied  by  SQL  Handle  and  Signature     •  Hash  func-on  on  SQL  Text   •  dbms_sqltune.sqltext_to_signature   –  View  dba_sql_plan_baselines   •  enabled  =  YES   •  accepted  =  YES   •  reproduced  =  YES   Enkitec  (c)  2014   47  
  • 48. Plan  History   •  Content  of  dba_sql_plan_baselines   •  Includes  SQL  Plan  Baseline     •  Includes  Pending  Plans   –  accepted  =  NO  and  last_verified  is  NULL   •  Includes  Rejected  Plans   –  accepted  =  NO  and  last_verified  is  not  NULL   •  Includes  Disabled  Plans   Enkitec  (c)  2014   48  
  • 49. Methods  to  Create  a  Plan  Baseline   1.  Capture   2.  Load   a.  Cursor  Cache  (CUR)   b.  SQL  Tuning  Set  (STS)   c.  Stored  Outline   3.  Migra-on   1.  Capture   2.  Load   a.  b.  c.  d.  e.  CUR   STS   AWR   SPA   TRC   3.  Migra-on   Enkitec  (c)  2014   49  
  • 50. Capturing  a  SQL  Plan  Baseline  (1)   •  Set  op-mizer_use_sql_plan_baselines  to  TRUE   (default)   •  Set  op-mizer_capture_sql_plan_baselines  to  TRUE   (default  is  FALSE)   –  Set  this  parameter  at  SESSION  level   •  Execute  SQL  2  -mes   •  Set  op-mizer_capture_sql_plan_baselines  to   FALSE   Enkitec  (c)  2014   50  
  • 51. Capturing  a  SQL  Plan  Baseline  (2)   Enkitec  (c)  2014   51  
  • 52. Loading  SQL  Plan  Baseline  from  Cache   •  dbms_spm.load_plans_from_cursor_cache   –  Inputs   •  sql_id   •  plan_hash_value  (opt)   –  Outputs   •  Number  of  Plans  loaded   Enkitec  (c)  2014   52  
  • 53. Demo  6   •  Load  Plans  for  Query  out  of  Demo  5   –  demo5.sql   –  load_plans.sql   •  Execute  Demo  5  again  and  review  Plan  History   –  demo5.sql   –  list_plans.sql   •  Execute  demo5.sql  twice  and  verify  results   Enkitec  (c)  2014   53  
  • 54. Demo  6  Results  (aoer  1st  demo5.sql)              CHILD    EXECUTIONS  BUFFER_GETS  PLAN_HASH_VALUE  SHAR  SENS  AWRE   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐                      0                      3                9090            3022804314  Y        Y        N                CHILD      BUCKET_ID              COUNT   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐                      0                      0                      0                      0                      1                      1                      0                      2                      2   Note   -­‐-­‐-­‐-­‐-­‐        -­‐  SQL  plan  baseline  SQL_PLAN_652hmt7yxthdwd624c0cd  used  for  this  statement     CREATED                                                PLAN_NAME                                            ENA  ACC  REP  FIX   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐  -­‐-­‐-­‐  -­‐-­‐-­‐  -­‐-­‐-­‐   28-­‐DEC-­‐13  02.03.43.000000  PM      SQL_PLAN_652hmt7yxthdw501f1424  YES  YES  YES  NO   28-­‐DEC-­‐13  02.03.43.000000  PM      SQL_PLAN_652hmt7yxthdwb6c39290  YES  YES  YES  NO   28-­‐DEC-­‐13  02.03.43.000000  PM      SQL_PLAN_652hmt7yxthdwd624c0cd  YES  YES  YES  NO   28-­‐DEC-­‐13  02.03.50.000000  PM      SQL_PLAN_652hmt7yxthdwc82a6b0c  YES  NO    YES  NO   Enkitec  (c)  2014   54  
  • 55. Demo  6  Results  (aoer  4rd  demo5.sql)              CHILD    EXECUTIONS  BUFFER_GETS  PLAN_HASH_VALUE  SHAR  SENS  AWRE   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐                      0                      2                4274            2163719564  N        Y        N                      1                      1                3030            3022804314  Y        Y        Y                      2                      1                3030            2326939410  Y        Y        Y                      3                      1                1587            2163719564  Y        Y        Y   Note   -­‐-­‐-­‐-­‐-­‐        -­‐  SQL  plan  baseline  SQL_PLAN_652hmt7yxthdwb6c39290  used  for  this  statement     CREATED                                                PLAN_NAME                                            ENA  ACC  REP  FIX   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐  -­‐-­‐-­‐  -­‐-­‐-­‐  -­‐-­‐-­‐   28-­‐DEC-­‐13  02.03.43.000000  PM      SQL_PLAN_652hmt7yxthdw501f1424  YES  YES  YES  NO   28-­‐DEC-­‐13  02.03.43.000000  PM      SQL_PLAN_652hmt7yxthdwb6c39290  YES  YES  YES  NO   28-­‐DEC-­‐13  02.03.43.000000  PM      SQL_PLAN_652hmt7yxthdwd624c0cd  YES  YES  YES  NO   28-­‐DEC-­‐13  02.03.50.000000  PM      SQL_PLAN_652hmt7yxthdwc82a6b0c  YES  NO    YES  NO   Enkitec  (c)  2014   55  
  • 56. Demo  7   •  Drop  SQL  Plan  Baseline   –  drop_plans.sql   •  Create  SQL  Patch  with  /*+  BIND_AWARE  */  Hint   –  sqlpch.sql  connected  as  SYS   •  Load  Plans  for  Query  out  of  Demo  5   –  demo5.sql   –  load_plans.sql   Enkitec  (c)  2014   56  
  • 57. Demo  7  Results              CHILD    EXECUTIONS  BUFFER_GETS  PLAN_HASH_VALUE  SHAR  SENS  AWRE   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐                      0                      1                3052            2163719564  N        Y        Y                      1                      1                3030            2048551027  Y        Y        Y                      2                      1                3030            3022804314  Y        Y        Y                      3                      1                3030            2326939410  Y        Y        Y                      4                      1                1587            2163719564  Y        Y        Y     CREATED                                                PLAN_NAME                                            ENA  ACC  REP  FIX   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐  -­‐-­‐-­‐  -­‐-­‐-­‐  -­‐-­‐-­‐   28-­‐DEC-­‐13  02.31.11.000000  PM      SQL_PLAN_652hmt7yxthdw501f1424  YES  YES  YES  NO   28-­‐DEC-­‐13  02.31.11.000000  PM      SQL_PLAN_652hmt7yxthdwb6c39290  YES  YES  YES  NO   28-­‐DEC-­‐13  02.31.11.000000  PM      SQL_PLAN_652hmt7yxthdwc82a6b0c  YES  YES  YES  NO   28-­‐DEC-­‐13  02.31.11.000000  PM      SQL_PLAN_652hmt7yxthdwd624c0cd  YES  YES  YES  NO       Enkitec  (c)  2014   57  
  • 58. Demo  8   •  Execute  queries  1-­‐5  and  observe  how  number  of   Execu-ons  increases  per  Child  Cursor   –  flush.sql   –  demo8.sql   –  demo8.sql   –  demo8.sql   Enkitec  (c)  2014   58  
  • 59. Demo  8  Results    CHILD    EXECUTIONS  BUFFER_GETS  PLAN_HASH_VALUE  SHAR  SENS  AWRE                                                                                                                                             -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐                                                                                                                                                      0                      1                1585            2163719564  N        Y        Y                                                                                                                                                            1                      1                3030            2048551027  Y        Y        Y                                                                                                                                                            2                      1                3030            3022804314  Y        Y        Y                                                                                                                                                            3                      1                3030            2326939410  Y        Y        Y                                                                                                                                                            4                      2                3172            2163719564  Y        Y        Y   Note   -­‐-­‐-­‐-­‐-­‐        -­‐  SQL  patch  "sqlpch_8u0n7w1jug5dg"  used  for  this  statement        -­‐  SQL  plan  baseline  SQL_PLAN_652hmt7yxthdwb6c39290  used  for  this  statement                CHILD    EXECUTIONS  BUFFER_GETS  PLAN_HASH_VALUE  SHAR  SENS  AWRE                                                                                                                                   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐                                                                                                                                                      0                      1                1585            2163719564  N        Y        Y                                                                                                                                                            1                      2                6060            2048551027  Y        Y        Y                                                                                                                                                            2                      2                6060            3022804314  Y        Y        Y                                                                                                                                                            3                      2                6060            2326939410  Y        Y        Y                                                                                                                                                            4                      4                6344            2163719564  Y        Y        Y     Enkitec  (c)  2014   59  
  • 60. Evolving  a  Plan   •  Evolving  a  Plan  means  “accep-ng”  it   –  Promo-ng  it  from  Plan  History  into  SQL  Plan  Baseline   •  dbms_spm.evolve_sql_plan_baseline   –  sql_handle  (opt)   –  plan_name  (opt)   –  verify  (default  YES)   –  commit  (default  YES)   Enkitec  (c)  2014   60  
  • 61. Demo  9   •  Drop  SQL  Plan  Baseline   –  drop_plans.sql   •  Capture  SQL  Plan  Baseline  with  1  accepted  Plan   –  demo9.sql   –  list_plans.sql   •  Evolve  all  Plans  on  Plan  History   –  evolve.sql   Enkitec  (c)  2014   61  
  • 62. FIXED  Flag   •  When  set  to  YES   –  Only  FIXED  Plans  are  considered  for  Plan  Selec-on   –  No  more  Plans  are  Captured  into  Plan  History   Enkitec  (c)  2014   62  
  • 63. Plan  Selec-on  (1)   •  At  hard  parse  when  SQL  Plan  Baseline  (SPB)  exists   1.  CBO  computes  an  “Op-mal”  Plan  (OP)   •  Adap-ve  Cursor  Sharing  is  used  if  applicable   2.  If  OP  exists  in  SPB  then  execute  this  OP   3.  If  OP  does  not  exist  in  SPB  then  store  it  in  Plan  History   a.  If  there  are  FIXED  Plans  in  SPB   i.  Re-­‐cost  all  FIXED  Plans  using  Binds  and  execute  cheapest   b.  If  there  are  no  FIXED  Plans  in  SPM   i.  Re-­‐cost  all  Plans  using  Binds  and  execute  cheapest   Enkitec  (c)  2014   63  
  • 64. Plan  Selec-on  (2)   Enkitec  (c)  2014   64  
  • 65. Demo  10   •  FIX  one  Plan  from  SQL  Plan  Baseline   –  alter_plans.sql   •  Verify  only  one  Plan  was  Executed   –  flush.sql   –  demo8.sql   –  demo8.sql   Enkitec  (c)  2014   65  
  • 66. SPM  Summary   •  SPM  provides  much  desired  Plan  Stability   –  Only  “approved”  Plans  are  allowed  to  Execute   •  ACS  can  generate  a  healthy  stock  of  Op-mal  Plans   –  You  can  restrict  them  to  work  under  SPM   •  Combining  ACS  and  SPM  you  can  obtain   –  Plan  Flexibility  and  Plan  Stability   Enkitec  (c)  2014   66  
  • 67. SPM/ACS  Suggested  Strategy   •  Use  dbms_applica-on_info.set_module  in  your   code  to  set  MODULE  and  ACTION   •  Use  dbms_spm.load_plans_from_cursor_cache   filtering  with  MODULE  or  ACTION   •  Use  sys.dbms_sqldiag_internal.i_create_patch  to   SQL  Patch  with  BIND_AWARE  the  SQL  on  Baselines     •  Use  dbms_spm.evolve_sql_plan_baseline  to  verify   and  evolve  periodically  good  performing  Plans   Enkitec  (c)  2014   67  
  • 68. Oracle  Pack  Licenses   •  DBMS_SPM   –  No  Oracle  Pack  License   •  DBMS_SQLTUNE   –  Oracle  Tuning  Pack   •  AWR   –  Oracle  Diagnos-cs  Pack   Enkitec  (c)  2014   68  
  • 69. References  (1)   •  Random  Slowdown  by  Jonathan  Lewis   –  h{p://jonathanlewis.wordpress.com/2013/12/23/ plan-­‐changes/   •  Using  SQL  Patch  to  add  hints  to  a  packaged   applica-on   –  h{ps://blogs.oracle.com/op-mizer/entry/ how_can_i_hint_a   Enkitec  (c)  2014   69  
  • 70. References  (2)   •  SQL  Plan  Management  SPM  Aware  Op-mizer   –  h{ps://blogs.oracle.com/op-mizer/entry/ sql_plan_management_part_2_of_4_spm_aware_opmizer   •  SQLTXPLAIN  MOS  215187.1   –  sqlt/utl/spm   Enkitec  (c)  2014   70  
  • 71. References  (3)   •  Oracle®  Database  PL/SQL  Packages  and  Types   Reference   –  11g  Release  2  (11.2)   –  Part  Number  E25788-­‐04   Enkitec  (c)  2014   71  
  • 72. Contact  Informa-on   •  carlos.sierra@enkitec.com   •  carlos-­‐sierra.net   •  @csierra_usa   Enkitec  (c)  2014   72