SlideShare a Scribd company logo
1 of 28
Oracle	
  Query	
  Optimizer	
  
Hyderabad	
  –	
  30th	
  May	
  2015	
  
About	
  me…	
  
Vivek	
  Sharma,	
  
Blog	
  url	
  :	
  h3p://viveklsharma.wordpress.com	
  
Email	
  :	
  vlsharma@hotmail.com	
  
A	
  Regular	
  Speaker	
  for	
  AIOUG	
  	
  
Speaker	
  of	
  the	
  Year	
  –	
  Sangam	
  2012	
  
•  Cursors	
  
•  SelecMvity	
  
•  Cardinality	
  
Key	
  Concepts…	
  
•  Cursors	
  
•  SelecMvity	
  
•  Cardinality	
  
Key	
  Concepts…	
  
Client	
  /	
  
Applica-on	
  
Handle	
  
Server	
  Process	
  
	
  Memory	
  
Private	
  SQL	
  Area	
  
SGA	
  
Library	
  Cache	
  
Shared	
  SQL	
  Area	
  
Syntax	
  /	
  Seman-cs	
  Checks	
  
Sharable	
  Parent	
  
Cursor	
  Available	
  ?	
  
Execute	
  
Store	
  Parent	
  Cursor	
  in	
  
Library	
  Cache	
  
Query	
  Transforma-on	
  /	
  
Execu-on	
  Plans	
  
Store	
  child	
  Cursor	
  in	
  Library	
  
Cache	
  
Sharable	
  Child	
  
Cursor	
  Available	
  ?	
  
N	
  
N	
  
Y	
  
Y	
  
Life	
  4me	
  of	
  a	
  Cursor…	
  
Syntax	
  /	
  Seman-cs	
  Checks	
  
Sharable	
  Parent	
  
Cursor	
  Available	
  ?	
  
Execute	
  
Store	
  Parent	
  Cursor	
  in	
  
Library	
  Cache	
  
Query	
  Transforma-on	
  /	
  
Execu-on	
  Plans	
  
Store	
  child	
  Cursor	
  in	
  Library	
  
Cache	
  
Sharable	
  Child	
  
Cursor	
  Available	
  ?	
  
N	
  
N	
  
Y	
  
Y	
  
Life	
  4me	
  of	
  a	
  Cursor…	
  
•  Cursors	
  
•  SelecMvity	
  
•  Cardinality	
  
Key	
  Concepts…	
  
ü  Value	
  between	
  0	
  and	
  1	
  
ü  Represents	
  FracMon	
  or	
  %age	
  of	
  rows	
  filtered	
  
ü  Drives	
  the	
  Access	
  Path	
  
ü  With	
  no-­‐histograms,	
  it	
  is	
  Density	
  or	
  1/Num_DisMnct	
  
ü  Close	
  to	
  0	
  –	
  Low	
  /	
  	
  Close	
  to	
  1	
  -­‐	
  High	
  
•  Cursors	
  
•  SelecMvity	
  
•  Cardinality	
  
Key	
  Concepts…	
  
ü  Number	
  of	
  rows	
  returned	
  by	
  an	
  OperaMon	
  
ü  Drives	
  Access	
  Order	
  
ü  SelecMvity	
  *	
  Num_Rows	
  
Introduc4on	
  to	
  Query	
  Op4mizer…	
  
SQL	
  
Query	
  
OpMmizer	
  
Object	
  StaMsMcs	
  
System	
  StaMsMcs	
  
Database	
  Design	
  
Fixed	
  Plans	
  
ExecuMon	
  Environment	
  
Bind	
  Variables	
  
Dynamic	
  Sampling	
  
Cardinality	
  Feedback	
  
ExecuMon	
  
Plan	
  
Object	
  Sta4s4cs…	
  
•  Table	
  StaMsMcs	
  	
  
o  num_rows	
  
o  Blocks	
  
•  Index	
  StaMsMcs	
  	
  
o  blevel	
  
o  leaf_blocks	
  
o  clustering_factor	
  	
  
•  Column	
  StaMsMcs	
  	
  
o  num_disMnct	
  
o  num_nulls	
  
o  density	
  (1/num_disMnct)	
  
o  low_value	
  
o  high_value	
  
•  ParMMon	
  Level	
  StaMsMcs	
  
o  Single	
  ParMMon	
  Scan	
  
•  Global	
  StaMsMcs	
  (Table	
  Level)	
  
o  All	
  or	
  MulMple	
  ParMMons	
  Scan	
  
•  Histograms	
  
o  Frequency	
  Based	
  
o  Height	
  Balanced	
  
o  Top	
  Frequency	
  
o  Hybrid	
  
With	
  Frequency	
  1/(2*num_rows)	
  
Object	
  Sta4s4cs	
  (Cardinality	
  -­‐	
  No	
  Nulls)…	
  
Statistics Values
Num_rows 1000
Num_distinct 10 (low 1 and high 10)
Blocks 39
Predicate ORG_ID 1
Density (org_id) 0.1 (No Nulls)
SQL> select id, name from aioug where org_id = 1;
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------
Plan hash value: 1667281916
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 100 | 1800 | 12 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| AIOUG | 100 | 1800 | 12 (0)| 00:00:01 |
---------------------------------------------------------------------------
Statistics Values
Num_rows 1000
Num_distinct 10 (low 1 and high 10)
Blocks 39
Density (org_id) 0.1 (No Nulls)
Base Selectivity 0.1 * ((1000-0)/1000) = 0.1
Cardinality 0.1 * 1000 = 100
Object	
  Sta4s4cs	
  (Cardinality	
  -­‐	
  No	
  Nulls)…	
  
Object	
  Sta4s4cs	
  (Cardinality	
  Few	
  Nulls)…	
  
Statistics Values
Num_rows 1000
Num_distinct 10 (low 1 and high 10)
Blocks 39
Predicate ORG_ID_N 1
Density (org_id_n) 0.1 (100 Nulls)
SQL> select id, name from aioug where org_id_n = 1;
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------
Plan hash value: 1667281916
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 90 | 1620 | 12 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| AIOUG | 90 | 1620 | 12 (0)| 00:00:01 |
---------------------------------------------------------------------------
Object	
  Sta4s4cs	
  (Cardinality	
  Few	
  Nulls)…	
  
Statistics Values
Num_rows 1000
Num_distinct 10 (low 1 and high 10)
Blocks 39
Density (org_id_n) 0.1 (100 Nulls)
Base Selectivity 0.1 * ((1000-100)/1000) = 0.09
Cardinality 0.09 * 1000 = 90
Out	
  of	
  Bound	
  (Cardinality	
  -­‐	
  No	
  Nulls)…	
  
Statistics Values
Num_rows 1000
Num_distinct 10 (low 1 and high 10)
Blocks 39
Predicate ORG_ID 14
Density (org_id) 0.1 (No Nulls)
SQL> select id, name from aioug where org_id = 14;
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------
Plan hash value: 1667281916
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 56 | 1008 | 11 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| AIOUG | 56 | 1008 | 11 (0)| 00:00:01 |
---------------------------------------------------------------------------
Statistics Values
Num_rows 1000
Num_distinct 10 (low 1 and high 10)
Blocks 39
Density (org_id) 0.1 (No Nulls)
Base Selectivity 0.1 * ((1000-0)/1000) = 0.1
Required Value (org_id) 14
Out of Bound Factor ((14-10)/(10-1)) = 0.44444
Cardinality (0.1 * 1000) –
(0.1*1000*0.4444) = 56
Out	
  of	
  Bound	
  (Cardinality	
  -­‐	
  No	
  Nulls)…	
  
•  utl_raw.cast_to_*	
  	
  
•  dbms_stats.convert_raw_value	
  
Low	
  &	
  High	
  Value	
  (Deciphering)…	
  
select column_name, low_value, high_value from dba_tab_columns
where owner='SCOTT' and table_name='AIOUG' order by 1;
COLUMN_NAME LOW_VALUE HIGH_VALUE
-------------------- ----------------------- -----------------------
ID C102 C20B
NAME 41477349586C68677566 7A7073484A505A44544F
ORG_ID C102 C10B
ORG_ID_N C102 C10B
Object	
  Sta4s4cs…	
  
•  Table	
  StaMsMcs	
  	
  
o  num_rows	
  
o  Blocks	
  
•  Index	
  StaMsMcs	
  	
  
o  blevel	
  
o  leaf_blocks	
  
o  clustering_factor	
  	
  
•  Column	
  StaMsMcs	
  	
  
o  num_disMnct	
  
o  num_nulls	
  
o  density	
  (1/num_disMnct)	
  
o  low_value	
  
o  high_value	
  
•  ParMMon	
  Level	
  StaMsMcs	
  
o  Single	
  ParMMon	
  Scan	
  
•  Global	
  StaMsMcs	
  (Table	
  Level)	
  
o  All	
  or	
  MulMple	
  ParMMons	
  Scan	
  
•  Histograms	
  
o  Frequency	
  Based	
  
o  Height	
  Based	
  
o  Top	
  Frequency	
  
o  Hybrid	
  (12c)	
  
With	
  Frequency	
  1/(2*num_rows)	
  
Index	
  Sta4s4cs	
  (low	
  Clustering	
  Factor)…	
  
Statistics
Indexed Column ORG_ID ORG_ID_M
Num_rows 1000 1000
Blevel 1 1
Leaf_Blocks 2 2
Clustering_Factor 34 337
SQL> select id, name from aioug where org_id = 1;
Plan hash value: 1442557996
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)|
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 100 | 5 (0)|
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| AIOUG | 100 | 5 (0)|
| 2 | INDEX RANGE SCAN | AIOUG_ORG_ID_IDX | 100 | 1 (0)|
-------------------------------------------------------------------------------------
Index	
  Sta4s4cs	
  (High	
  Clustering	
  Factor)…	
  
SQL> select id, name from aioug where org_id_m = 1;
Plan hash value: 1667281916
--------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)|
--------------------------------------------------------
| 0 | SELECT STATEMENT | | 100 | 12 (9)|
| 1 | TABLE ACCESS FULL| AIOUG | 100 | 12 (9)|
--------------------------------------------------------
Statistics
Indexed Column ORG_ID ORG_ID_M
Num_rows 1000 1000
Blevel 1 1
Leaf_Blocks 2 2
Clustering_Factor 34 337
Cost = blevel
+ ceil(leaf_blocks * index_selectivity)
+ ceil(clustering_factor * table_selectivity)
Cost	
  of	
  an	
  Index	
  Scan	
  
Cost	
  of	
  a	
  Table	
  Scan	
  via	
  Index	
  
CalculaMon	
  of	
  CF	
  (10	
  Row	
  3	
  Block	
  Table	
  with	
  an	
  Index)	
  
Index Entry Table Block CF
A 1 1
A 1 1
A 2 2
B 3 3
B 1 4
C 3 5
C 2 6
C 2 6
D 1 7
D 3 8
Good	
  :	
  Near	
  to	
  Table.blocks	
  
Bad	
  :	
  Near	
  to	
  Table.num_rows	
  
Index	
  Sta4s4cs	
  (Clustering	
  Factor)…	
  
•  SREADTIM	
  	
  
•  MREADTIM	
  
•  MBRC	
  
•  CPUSPEED	
  
•  IOSEEKTIM	
  
•  IOTRFSPEED	
  
•  CPUSPEEDNW	
  
System	
  Sta4s4cs…	
  
Workload	
  StaMsMcs	
  
NoWorkload	
  StaMsMcs	
  
System	
  Sta4s4cs	
  (workload)…	
  
select pname, pval1
from sys.aux_stats$;
PNAME PVAL1
-------------------- ----------
SREADTIM 2
MREADTIM 5
CPUSPEED 500
MBRC 10
MAXTHR
SLAVETHR
Cost	
  =	
  IO_Cost	
  +	
  CPU	
  Cost	
  
IO_Cost	
  =	
  ceil(#Blks/MBRC	
  *	
  Mread-m/Sread-m)	
  
CPU	
  Cost	
  =	
  ceil(CPUSpeed	
  /	
  (CPUCycles	
  *	
  Sread-m)	
  
+	
  _tablescan_cost_plus_one	
  
System	
  Sta4s4cs	
  (workload)…	
  
Statistics Values
Blocks 39
MBRC 10
Mreadtim / Sreadtim 5 / 2
SQL> select id, name from aioug where org_id = 1;
SQL> select operation, io_cost, cpu_cost, cost from plan_table
2 where operation='TABLE ACCESS';
OPERATION IO_COST CPU_COST COST
------------------------------ ---------- ---------- ----------
TABLE ACCESS 11 501736 12
SQL> select ceil(39/10*5/2), 1 "_table_scan_cost_plus_one" from dual;
CEIL(39/10*5/2) _table_scan_cost_plus_one
--------------- -------------------------
10 1
System	
  Sta4s4cs	
  (noworkload)…	
  
select pname, pval1
from sys.aux_stats$;
PNAME PVAL1
-------------------- ----------
CPUSPEEDNW 2992.27468
IOSEEKTIM 10
IOTFRSPEED 4096
Cost	
  =	
  IO_Cost	
  +	
  CPU	
  Cost	
  
IO_Cost	
  =	
  ceil(#Blks/MBRC	
  *	
  Mread-m/Sread-m)	
  
CPU	
  Cost	
  =	
  ceil(CPUSpeed	
  /	
  (CPUCycles	
  *	
  Sread-m)	
  
+	
  _tablescan_cost_plus_one	
  
MBRC	
  =	
  db_file_mul-block_read_count	
  or	
  8	
  
Sread-m	
  =	
  IOSeek-m	
  +	
  db_block_size	
  /	
  IOTrfspeed	
  
Mread-m	
  =	
  IOSeek-m	
  +	
  dfmrc	
  or	
  8	
  *	
  db_block_size/IOTrfspeed	
  
System	
  Sta4s4cs	
  (noworkload)…	
  
Statistics Values
Blocks 39
Db_file_multiblock_read_count Non-default (=8)
Sreadtim 10 + (8192/4096) = 12
Mreadtim 10 + (8 * 8192/4096) = 26
SQL> select id, name from aioug where org_id = 1;
SQL> select operation, io_cost, cpu_cost, cost from plan_table
2 where operation='TABLE ACCESS';
OPERATION IO_COST CPU_COST COST
------------------------------ ---------- ---------- ----------
TABLE ACCESS 12 501736 12
SQL> select ceil(39/8*26/12), 1 "_table_scan_cost_plus_one" from dual
CEIL(39/8*26/12) _table_scan_cost_plus_one
---------------- -------------------------
11 1
•  Extended	
  StaMsMcs	
  –	
  Dependant	
  Columns	
  	
  
•  Histograms	
  –	
  Wherever	
  required	
  
•  FuncMons	
  on	
  Indexed	
  /	
  Non-­‐Indexed	
  Columns	
  
•  Deadly	
  Defaults	
  
•  Dynamic	
  Samplings	
  /	
  Cardinality	
  Feedback	
  
•  10053	
  
–  OpMmizer	
  Workings	
  
–  Using	
  Prorated	
  Density	
  (Out	
  of	
  Bound)	
  	
  
Cri4cal	
  to	
  know	
  about…	
  
THANK	
  YOU	
  

More Related Content

What's hot

Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
Yogiji Creations
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance Tuning
OracleTrainings
 
Less18 moving data
Less18 moving dataLess18 moving data
Less18 moving data
Imran Ali
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 

What's hot (20)

Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
 
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
Top 10 tips for Oracle performance (Updated April 2015)
Top 10 tips for Oracle performance (Updated April 2015)Top 10 tips for Oracle performance (Updated April 2015)
Top 10 tips for Oracle performance (Updated April 2015)
 
Aioug ha day oct2015 goldengate- High Availability Day 2015
Aioug ha day oct2015 goldengate- High Availability Day 2015Aioug ha day oct2015 goldengate- High Availability Day 2015
Aioug ha day oct2015 goldengate- High Availability Day 2015
 
Adaptive Query Optimization
Adaptive Query OptimizationAdaptive Query Optimization
Adaptive Query Optimization
 
MySQL Optimizer Cost Model
MySQL Optimizer Cost ModelMySQL Optimizer Cost Model
MySQL Optimizer Cost Model
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance Tuning
 
AWR and ASH Deep Dive
AWR and ASH Deep DiveAWR and ASH Deep Dive
AWR and ASH Deep Dive
 
Database Performance Tuning
Database Performance Tuning Database Performance Tuning
Database Performance Tuning
 
Less18 moving data
Less18 moving dataLess18 moving data
Less18 moving data
 
DBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should KnowDBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should Know
 
Is SQLcl the Next Generation of SQL*Plus?
Is SQLcl the Next Generation of SQL*Plus?Is SQLcl the Next Generation of SQL*Plus?
Is SQLcl the Next Generation of SQL*Plus?
 
Best Practices – Extreme Performance with Data Warehousing on Oracle Database
Best Practices – Extreme Performance with Data Warehousing on Oracle DatabaseBest Practices – Extreme Performance with Data Warehousing on Oracle Database
Best Practices – Extreme Performance with Data Warehousing on Oracle Database
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
 
Proactive performance monitoring with adaptive thresholds
Proactive performance monitoring with adaptive thresholdsProactive performance monitoring with adaptive thresholds
Proactive performance monitoring with adaptive thresholds
 
Oracle Database 12c New Features for Developers and DBAs - OTN TOUR LA 2015
Oracle Database 12c  New Features for Developers and DBAs - OTN TOUR LA 2015Oracle Database 12c  New Features for Developers and DBAs - OTN TOUR LA 2015
Oracle Database 12c New Features for Developers and DBAs - OTN TOUR LA 2015
 
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
 
Porting Oracle Applications to PostgreSQL
Porting Oracle Applications to PostgreSQLPorting Oracle Applications to PostgreSQL
Porting Oracle Applications to PostgreSQL
 
What's new in Oracle Trace File Analyzer version 12.2.1.1.0
What's new in Oracle Trace File Analyzer version 12.2.1.1.0What's new in Oracle Trace File Analyzer version 12.2.1.1.0
What's new in Oracle Trace File Analyzer version 12.2.1.1.0
 

Viewers also liked

090327 02
090327 02090327 02
090327 02
knagai
 
HadiDiVitoMarfiaNavoneCampanellaRiboniChap
HadiDiVitoMarfiaNavoneCampanellaRiboniChapHadiDiVitoMarfiaNavoneCampanellaRiboniChap
HadiDiVitoMarfiaNavoneCampanellaRiboniChap
Loubna Abdel Hadi
 
Winter/Spring 09 Portfolio
Winter/Spring 09 PortfolioWinter/Spring 09 Portfolio
Winter/Spring 09 Portfolio
ommacreative
 
Aba effective instruction modules
Aba effective instruction modulesAba effective instruction modules
Aba effective instruction modules
hajiagha
 

Viewers also liked (20)

Yard Sale Flyer
Yard Sale FlyerYard Sale Flyer
Yard Sale Flyer
 
090327 02
090327 02090327 02
090327 02
 
HadiDiVitoMarfiaNavoneCampanellaRiboniChap
HadiDiVitoMarfiaNavoneCampanellaRiboniChapHadiDiVitoMarfiaNavoneCampanellaRiboniChap
HadiDiVitoMarfiaNavoneCampanellaRiboniChap
 
Deborah Y. Strauss, D.V.M: Inspirational Quotes From Inspirational Artists
Deborah Y. Strauss, D.V.M: Inspirational Quotes From Inspirational Artists Deborah Y. Strauss, D.V.M: Inspirational Quotes From Inspirational Artists
Deborah Y. Strauss, D.V.M: Inspirational Quotes From Inspirational Artists
 
Evento stage it-v1
Evento stage it-v1Evento stage it-v1
Evento stage it-v1
 
Winter/Spring 09 Portfolio
Winter/Spring 09 PortfolioWinter/Spring 09 Portfolio
Winter/Spring 09 Portfolio
 
Horse SA presentation
Horse SA presentationHorse SA presentation
Horse SA presentation
 
Aba effective instruction modules
Aba effective instruction modulesAba effective instruction modules
Aba effective instruction modules
 
spamzombieppt
spamzombiepptspamzombieppt
spamzombieppt
 
Deborah Y. Strauss Presents: Fine Art Nature Photography
Deborah Y. Strauss Presents: Fine Art Nature PhotographyDeborah Y. Strauss Presents: Fine Art Nature Photography
Deborah Y. Strauss Presents: Fine Art Nature Photography
 
Freemium Summit East - Google Apps
Freemium Summit East - Google AppsFreemium Summit East - Google Apps
Freemium Summit East - Google Apps
 
Прекрасная половина Одноклассников: как соцсеть работает с женской аудиторией
Прекрасная половина Одноклассников: как соцсеть работает с женской аудиториейПрекрасная половина Одноклассников: как соцсеть работает с женской аудиторией
Прекрасная половина Одноклассников: как соцсеть работает с женской аудиторией
 
Managing Fatigue
Managing FatigueManaging Fatigue
Managing Fatigue
 
Boots hair care promotions
Boots hair care promotionsBoots hair care promotions
Boots hair care promotions
 
Implementing cloud applications redefine your dimension
Implementing cloud applications   redefine your dimensionImplementing cloud applications   redefine your dimension
Implementing cloud applications redefine your dimension
 
Casual Connect Keynote - Creating a Bull Market: How to Manage a Successful V...
Casual Connect Keynote - Creating a Bull Market: How to Manage a Successful V...Casual Connect Keynote - Creating a Bull Market: How to Manage a Successful V...
Casual Connect Keynote - Creating a Bull Market: How to Manage a Successful V...
 
Oracle analytics cloud overview feb 2017
Oracle analytics cloud overview   feb 2017Oracle analytics cloud overview   feb 2017
Oracle analytics cloud overview feb 2017
 
veshaal-singh-ebs-oracle cloud(iaas+paas)
veshaal-singh-ebs-oracle cloud(iaas+paas)veshaal-singh-ebs-oracle cloud(iaas+paas)
veshaal-singh-ebs-oracle cloud(iaas+paas)
 
Dg broker & client connectivity - High Availability Day 2015
Dg broker & client connectivity -  High Availability Day 2015Dg broker & client connectivity -  High Availability Day 2015
Dg broker & client connectivity - High Availability Day 2015
 
Getting optimal performance from oracle e business suite
Getting optimal performance from oracle e business suiteGetting optimal performance from oracle e business suite
Getting optimal performance from oracle e business suite
 

Similar to Query optimizer vivek sharma

Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdfDatabase & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
InSync2011
 
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
maclean liu
 
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfNOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
cookie1969
 

Similar to Query optimizer vivek sharma (20)

A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013
 
Histograms in 12c era
Histograms in 12c eraHistograms in 12c era
Histograms in 12c era
 
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdfDatabase & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
 
Oracle 12c SPM
Oracle 12c SPMOracle 12c SPM
Oracle 12c SPM
 
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
【Maclean liu技术分享】拨开oracle cbo优化器迷雾,探究histogram直方图之秘 0321
 
Histograms : Pre-12c and Now
Histograms : Pre-12c and NowHistograms : Pre-12c and Now
Histograms : Pre-12c and Now
 
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfNOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
 
Do You Know The 11g Plan?
Do You Know The 11g Plan?Do You Know The 11g Plan?
Do You Know The 11g Plan?
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notations
 
Query Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksQuery Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New Tricks
 
Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explained
 
SFDC Advanced Apex
SFDC Advanced Apex SFDC Advanced Apex
SFDC Advanced Apex
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentation
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON?
 
Cost Based Oracle
Cost Based OracleCost Based Oracle
Cost Based Oracle
 
Riyaj: why optimizer_hates_my_sql_2010
Riyaj: why optimizer_hates_my_sql_2010Riyaj: why optimizer_hates_my_sql_2010
Riyaj: why optimizer_hates_my_sql_2010
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introduction
 

More from aioughydchapter

More from aioughydchapter (13)

Leverage integration cloud_service_for_ebs_
Leverage integration cloud_service_for_ebs_Leverage integration cloud_service_for_ebs_
Leverage integration cloud_service_for_ebs_
 
Oracle IaaS Overview - AIOUG Hyderabad Chapter
Oracle IaaS Overview - AIOUG Hyderabad ChapterOracle IaaS Overview - AIOUG Hyderabad Chapter
Oracle IaaS Overview - AIOUG Hyderabad Chapter
 
Role of DBAs in CLOUD ERA - AIOUG Hyd Chapter - Oracle Cloud Day
Role of DBAs in CLOUD ERA - AIOUG Hyd Chapter - Oracle Cloud DayRole of DBAs in CLOUD ERA - AIOUG Hyd Chapter - Oracle Cloud Day
Role of DBAs in CLOUD ERA - AIOUG Hyd Chapter - Oracle Cloud Day
 
Oracle Cloud Day(IaaS, PaaS,SaaS) - AIOUG Hyd Chapter
Oracle Cloud Day(IaaS, PaaS,SaaS) - AIOUG Hyd ChapterOracle Cloud Day(IaaS, PaaS,SaaS) - AIOUG Hyd Chapter
Oracle Cloud Day(IaaS, PaaS,SaaS) - AIOUG Hyd Chapter
 
Oracle rac cachefusion - High Availability Day 2015
Oracle rac cachefusion - High Availability Day 2015Oracle rac cachefusion - High Availability Day 2015
Oracle rac cachefusion - High Availability Day 2015
 
Aman sharma hyd_12crac High Availability Day 2015
Aman sharma hyd_12crac High Availability Day 2015Aman sharma hyd_12crac High Availability Day 2015
Aman sharma hyd_12crac High Availability Day 2015
 
Dmz aa aioug
Dmz aa aiougDmz aa aioug
Dmz aa aioug
 
Editioning use in ebs
Editioning use in  ebsEditioning use in  ebs
Editioning use in ebs
 
Ebs upgrade-to-12.2 technical-upgrade_best_practices
Ebs upgrade-to-12.2 technical-upgrade_best_practicesEbs upgrade-to-12.2 technical-upgrade_best_practices
Ebs upgrade-to-12.2 technical-upgrade_best_practices
 
Ebs12.2 online patching
Ebs12.2 online patching Ebs12.2 online patching
Ebs12.2 online patching
 
Indexes overview
Indexes overviewIndexes overview
Indexes overview
 
AWR & ASH Analysis
AWR & ASH AnalysisAWR & ASH Analysis
AWR & ASH Analysis
 
Performance tuning intro
Performance tuning introPerformance tuning intro
Performance tuning intro
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 

Query optimizer vivek sharma

  • 1. Oracle  Query  Optimizer   Hyderabad  –  30th  May  2015  
  • 2. About  me…   Vivek  Sharma,   Blog  url  :  h3p://viveklsharma.wordpress.com   Email  :  vlsharma@hotmail.com   A  Regular  Speaker  for  AIOUG     Speaker  of  the  Year  –  Sangam  2012  
  • 3. •  Cursors   •  SelecMvity   •  Cardinality   Key  Concepts…  
  • 4. •  Cursors   •  SelecMvity   •  Cardinality   Key  Concepts…   Client  /   Applica-on   Handle   Server  Process    Memory   Private  SQL  Area   SGA   Library  Cache   Shared  SQL  Area  
  • 5. Syntax  /  Seman-cs  Checks   Sharable  Parent   Cursor  Available  ?   Execute   Store  Parent  Cursor  in   Library  Cache   Query  Transforma-on  /   Execu-on  Plans   Store  child  Cursor  in  Library   Cache   Sharable  Child   Cursor  Available  ?   N   N   Y   Y   Life  4me  of  a  Cursor…  
  • 6. Syntax  /  Seman-cs  Checks   Sharable  Parent   Cursor  Available  ?   Execute   Store  Parent  Cursor  in   Library  Cache   Query  Transforma-on  /   Execu-on  Plans   Store  child  Cursor  in  Library   Cache   Sharable  Child   Cursor  Available  ?   N   N   Y   Y   Life  4me  of  a  Cursor…  
  • 7. •  Cursors   •  SelecMvity   •  Cardinality   Key  Concepts…   ü  Value  between  0  and  1   ü  Represents  FracMon  or  %age  of  rows  filtered   ü  Drives  the  Access  Path   ü  With  no-­‐histograms,  it  is  Density  or  1/Num_DisMnct   ü  Close  to  0  –  Low  /    Close  to  1  -­‐  High  
  • 8. •  Cursors   •  SelecMvity   •  Cardinality   Key  Concepts…   ü  Number  of  rows  returned  by  an  OperaMon   ü  Drives  Access  Order   ü  SelecMvity  *  Num_Rows  
  • 9. Introduc4on  to  Query  Op4mizer…   SQL   Query   OpMmizer   Object  StaMsMcs   System  StaMsMcs   Database  Design   Fixed  Plans   ExecuMon  Environment   Bind  Variables   Dynamic  Sampling   Cardinality  Feedback   ExecuMon   Plan  
  • 10. Object  Sta4s4cs…   •  Table  StaMsMcs     o  num_rows   o  Blocks   •  Index  StaMsMcs     o  blevel   o  leaf_blocks   o  clustering_factor     •  Column  StaMsMcs     o  num_disMnct   o  num_nulls   o  density  (1/num_disMnct)   o  low_value   o  high_value   •  ParMMon  Level  StaMsMcs   o  Single  ParMMon  Scan   •  Global  StaMsMcs  (Table  Level)   o  All  or  MulMple  ParMMons  Scan   •  Histograms   o  Frequency  Based   o  Height  Balanced   o  Top  Frequency   o  Hybrid   With  Frequency  1/(2*num_rows)  
  • 11. Object  Sta4s4cs  (Cardinality  -­‐  No  Nulls)…   Statistics Values Num_rows 1000 Num_distinct 10 (low 1 and high 10) Blocks 39 Predicate ORG_ID 1 Density (org_id) 0.1 (No Nulls) SQL> select id, name from aioug where org_id = 1; PLAN_TABLE_OUTPUT -------------------------------------------------------------------------- Plan hash value: 1667281916 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 100 | 1800 | 12 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| AIOUG | 100 | 1800 | 12 (0)| 00:00:01 | ---------------------------------------------------------------------------
  • 12. Statistics Values Num_rows 1000 Num_distinct 10 (low 1 and high 10) Blocks 39 Density (org_id) 0.1 (No Nulls) Base Selectivity 0.1 * ((1000-0)/1000) = 0.1 Cardinality 0.1 * 1000 = 100 Object  Sta4s4cs  (Cardinality  -­‐  No  Nulls)…  
  • 13. Object  Sta4s4cs  (Cardinality  Few  Nulls)…   Statistics Values Num_rows 1000 Num_distinct 10 (low 1 and high 10) Blocks 39 Predicate ORG_ID_N 1 Density (org_id_n) 0.1 (100 Nulls) SQL> select id, name from aioug where org_id_n = 1; PLAN_TABLE_OUTPUT -------------------------------------------------------------------------- Plan hash value: 1667281916 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 90 | 1620 | 12 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| AIOUG | 90 | 1620 | 12 (0)| 00:00:01 | ---------------------------------------------------------------------------
  • 14. Object  Sta4s4cs  (Cardinality  Few  Nulls)…   Statistics Values Num_rows 1000 Num_distinct 10 (low 1 and high 10) Blocks 39 Density (org_id_n) 0.1 (100 Nulls) Base Selectivity 0.1 * ((1000-100)/1000) = 0.09 Cardinality 0.09 * 1000 = 90
  • 15. Out  of  Bound  (Cardinality  -­‐  No  Nulls)…   Statistics Values Num_rows 1000 Num_distinct 10 (low 1 and high 10) Blocks 39 Predicate ORG_ID 14 Density (org_id) 0.1 (No Nulls) SQL> select id, name from aioug where org_id = 14; PLAN_TABLE_OUTPUT -------------------------------------------------------------------------- Plan hash value: 1667281916 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 56 | 1008 | 11 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| AIOUG | 56 | 1008 | 11 (0)| 00:00:01 | ---------------------------------------------------------------------------
  • 16. Statistics Values Num_rows 1000 Num_distinct 10 (low 1 and high 10) Blocks 39 Density (org_id) 0.1 (No Nulls) Base Selectivity 0.1 * ((1000-0)/1000) = 0.1 Required Value (org_id) 14 Out of Bound Factor ((14-10)/(10-1)) = 0.44444 Cardinality (0.1 * 1000) – (0.1*1000*0.4444) = 56 Out  of  Bound  (Cardinality  -­‐  No  Nulls)…  
  • 17. •  utl_raw.cast_to_*     •  dbms_stats.convert_raw_value   Low  &  High  Value  (Deciphering)…   select column_name, low_value, high_value from dba_tab_columns where owner='SCOTT' and table_name='AIOUG' order by 1; COLUMN_NAME LOW_VALUE HIGH_VALUE -------------------- ----------------------- ----------------------- ID C102 C20B NAME 41477349586C68677566 7A7073484A505A44544F ORG_ID C102 C10B ORG_ID_N C102 C10B
  • 18. Object  Sta4s4cs…   •  Table  StaMsMcs     o  num_rows   o  Blocks   •  Index  StaMsMcs     o  blevel   o  leaf_blocks   o  clustering_factor     •  Column  StaMsMcs     o  num_disMnct   o  num_nulls   o  density  (1/num_disMnct)   o  low_value   o  high_value   •  ParMMon  Level  StaMsMcs   o  Single  ParMMon  Scan   •  Global  StaMsMcs  (Table  Level)   o  All  or  MulMple  ParMMons  Scan   •  Histograms   o  Frequency  Based   o  Height  Based   o  Top  Frequency   o  Hybrid  (12c)   With  Frequency  1/(2*num_rows)  
  • 19. Index  Sta4s4cs  (low  Clustering  Factor)…   Statistics Indexed Column ORG_ID ORG_ID_M Num_rows 1000 1000 Blevel 1 1 Leaf_Blocks 2 2 Clustering_Factor 34 337 SQL> select id, name from aioug where org_id = 1; Plan hash value: 1442557996 ------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Cost (%CPU)| ------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 100 | 5 (0)| | 1 | TABLE ACCESS BY INDEX ROWID BATCHED| AIOUG | 100 | 5 (0)| | 2 | INDEX RANGE SCAN | AIOUG_ORG_ID_IDX | 100 | 1 (0)| -------------------------------------------------------------------------------------
  • 20. Index  Sta4s4cs  (High  Clustering  Factor)…   SQL> select id, name from aioug where org_id_m = 1; Plan hash value: 1667281916 -------------------------------------------------------- | Id | Operation | Name | Rows | Cost (%CPU)| -------------------------------------------------------- | 0 | SELECT STATEMENT | | 100 | 12 (9)| | 1 | TABLE ACCESS FULL| AIOUG | 100 | 12 (9)| -------------------------------------------------------- Statistics Indexed Column ORG_ID ORG_ID_M Num_rows 1000 1000 Blevel 1 1 Leaf_Blocks 2 2 Clustering_Factor 34 337
  • 21. Cost = blevel + ceil(leaf_blocks * index_selectivity) + ceil(clustering_factor * table_selectivity) Cost  of  an  Index  Scan   Cost  of  a  Table  Scan  via  Index   CalculaMon  of  CF  (10  Row  3  Block  Table  with  an  Index)   Index Entry Table Block CF A 1 1 A 1 1 A 2 2 B 3 3 B 1 4 C 3 5 C 2 6 C 2 6 D 1 7 D 3 8 Good  :  Near  to  Table.blocks   Bad  :  Near  to  Table.num_rows   Index  Sta4s4cs  (Clustering  Factor)…  
  • 22. •  SREADTIM     •  MREADTIM   •  MBRC   •  CPUSPEED   •  IOSEEKTIM   •  IOTRFSPEED   •  CPUSPEEDNW   System  Sta4s4cs…   Workload  StaMsMcs   NoWorkload  StaMsMcs  
  • 23. System  Sta4s4cs  (workload)…   select pname, pval1 from sys.aux_stats$; PNAME PVAL1 -------------------- ---------- SREADTIM 2 MREADTIM 5 CPUSPEED 500 MBRC 10 MAXTHR SLAVETHR Cost  =  IO_Cost  +  CPU  Cost   IO_Cost  =  ceil(#Blks/MBRC  *  Mread-m/Sread-m)   CPU  Cost  =  ceil(CPUSpeed  /  (CPUCycles  *  Sread-m)   +  _tablescan_cost_plus_one  
  • 24. System  Sta4s4cs  (workload)…   Statistics Values Blocks 39 MBRC 10 Mreadtim / Sreadtim 5 / 2 SQL> select id, name from aioug where org_id = 1; SQL> select operation, io_cost, cpu_cost, cost from plan_table 2 where operation='TABLE ACCESS'; OPERATION IO_COST CPU_COST COST ------------------------------ ---------- ---------- ---------- TABLE ACCESS 11 501736 12 SQL> select ceil(39/10*5/2), 1 "_table_scan_cost_plus_one" from dual; CEIL(39/10*5/2) _table_scan_cost_plus_one --------------- ------------------------- 10 1
  • 25. System  Sta4s4cs  (noworkload)…   select pname, pval1 from sys.aux_stats$; PNAME PVAL1 -------------------- ---------- CPUSPEEDNW 2992.27468 IOSEEKTIM 10 IOTFRSPEED 4096 Cost  =  IO_Cost  +  CPU  Cost   IO_Cost  =  ceil(#Blks/MBRC  *  Mread-m/Sread-m)   CPU  Cost  =  ceil(CPUSpeed  /  (CPUCycles  *  Sread-m)   +  _tablescan_cost_plus_one   MBRC  =  db_file_mul-block_read_count  or  8   Sread-m  =  IOSeek-m  +  db_block_size  /  IOTrfspeed   Mread-m  =  IOSeek-m  +  dfmrc  or  8  *  db_block_size/IOTrfspeed  
  • 26. System  Sta4s4cs  (noworkload)…   Statistics Values Blocks 39 Db_file_multiblock_read_count Non-default (=8) Sreadtim 10 + (8192/4096) = 12 Mreadtim 10 + (8 * 8192/4096) = 26 SQL> select id, name from aioug where org_id = 1; SQL> select operation, io_cost, cpu_cost, cost from plan_table 2 where operation='TABLE ACCESS'; OPERATION IO_COST CPU_COST COST ------------------------------ ---------- ---------- ---------- TABLE ACCESS 12 501736 12 SQL> select ceil(39/8*26/12), 1 "_table_scan_cost_plus_one" from dual CEIL(39/8*26/12) _table_scan_cost_plus_one ---------------- ------------------------- 11 1
  • 27. •  Extended  StaMsMcs  –  Dependant  Columns     •  Histograms  –  Wherever  required   •  FuncMons  on  Indexed  /  Non-­‐Indexed  Columns   •  Deadly  Defaults   •  Dynamic  Samplings  /  Cardinality  Feedback   •  10053   –  OpMmizer  Workings   –  Using  Prorated  Density  (Out  of  Bound)     Cri4cal  to  know  about…