SlideShare una empresa de Scribd logo
1 de 31
1
References

Optimization

Types of
Optimization

Understanding
The Execution
Plan

Problem and
Solutions with
practical
examples

Query
Optimization
2
3
• RBO uses predefined set of precedence
rules(golden rules) to figure out the optimal
path
• These rules used to choose one index over
another index and when full table scan
• Oracle 9i has 20 “golden rules” for optimal
execution path
ALTER SESSION SET OPTIMIZER_MODE = RULE/CHOOSE;
4
5
6
Emp_Id

Ename

EAddr

Emp_Id

Emp_dept Emp_sal

7
Index1(A1,B,C); Table 1
Index2(A2,F,G); Table 2
Select *
From Table1,Table2
Where A1=1 and B=2 and
G=2 and F like ’%something’
and A1=A2

Two 1-Col Index: Table 1
Index1(A)
Index2(B);
One 2-Col Index: Table 2
Index3(E,F);
8
Rule-Based Optimizer Problems and Solutions

9
Problem 1: Incorrect Driving Table
SELECT COUNT(*) FROM acct a, trans b
WHERE b.cost_center = 'MASS'
AND a.acct_name = 'MGA'
AND a.acct_name = b.acct_name;
Response = 19.722 seconds

SELECT COUNT(*) FROM trans b, acct a
WHERE b.cost_center= 'MASS'
AND a.acct_name = 'MGA'
AND a.acct_name = b.acct_name;
Response = 1.904 seconds
10
Problem 2: Incorrect Driving Index

SELECT COUNT(*)
FROM trans
WHERE cost_center = 'MASS'
AND bmark_id = 9;
Response Time = 4.255 seconds

SELECT COUNT(*)
FROM trans
WHERE bmark_id = 9
AND cost_center = 'MASS';
Response Time = 1.044 seconds
11
Problem 3: Using the ORDER BY Index and not the WHERE Index

SELECT fod_flag, account_no
FROM account_master
WHERE (account_code like 'I%')
ORDER BY account_no;
Index_1 UNIQUE (ACCOUNT_NO)
Index_2 (ACCOUNT_CODE)

Index (ACCOUNT_CODE, ACCOUNT_NO)

12
ANALYZE & DBMS_STATS

ANALYZE

Collect statistics about tables, clusters
and indexes, and store those statistics
in the data dictionary

DBMS_STATS
RULE BASED

RULE BASED

If table not analyzed CBO apply
Rule Based Logic to select best path

13
• ANALYZE COMPUTE & ANALYZE ESTIMATE

• Table and it’s index
• Index dropped..?

• DBMS_STATS.GATHER_SCHEMA_STATS &
GATHER_TABLE_STATS : CASCADE=>TRUE

14
1. ANALYZE TABLE EMP ESTIMATE STATISTICS
SAMPLE 5 PERCENT FOR ALL INDEXED COLUMNS;
2. ANALYZE INDEX EMP_NDX1 ESTIMATE
STATISTICS SAMPLE 5 PERCENT FOR ALL INDEXED
COLUMNS;
3. ANALYZE TABLE EMP COMPUTE STATISTICS FOR
ALL INDEXED COLUMNS;
4. ANALYZE TABLE EMP DELETE STATISTICS;
15
• Check Syntax
• Object Privilege

Parse

Plans
• All possible
execution plans
listed

• Calculate cost
of each
execution plans

Cost
16
Cost-Based Optimizer Problems and Solutions

17
Problem 1: The Skewness Problem

SELECT acct_no, customer, product, trans_date, amt
FROM trans
WHERE status='O';
Response time = 16.308 seconds
> ANALYZE TABLE TRANS COMPUTE STATISTICS FOR ALL
INDEXED COLUMNS
Response time reduces to 0.259 seconds
18
Problem 2: Analyzing with Wrong Data

The cost-based optimizer requires accurate
information, including accurate data volumes, to have
any chance of creating efficient execution plans
otherwise performance will degrade a large scale

Example:
Before analyze the cardinality is 1000(10000/10) on
10000 rows
And now we insert the 10000 new rows with distinct
values so what will be the new cardinality?

19
Problem 4: Choosing an Inferior Index

where business_unit = :5
and ledger = :6
and fiscal_year = :7
and accounting_period = :8
and affiliate = :9
and statistics_code = :10
and project_id = :11
and account = :12
and currency_cd = :13
and deptid = :14
and product = :15
20
Problem 4: Choosing an Inferior Index

where business_unit = :5
and ledger = :6
and fiscal_year = :7
and accounting_period between 1 and 12
and affiliate = :9
and statistics_code = :10
and project_id = :11
and account = :12
and currency_cd = :13
and deptid = :14
and product = :15
21
Problem 4: Choosing an Inferior Index

business_unit
ledger
fiscal_year
affiliate
statistics_code
project_id
account
currency_cd
deptid
Product
accounting_period
22
SELECT prod_category, AVG(amount_sold)
FROM o_sales s, o_products p
WHERE p.prod_id = s.prod_id
GROUP BY prod_category;

GET SALES

GET
PRODUCTS

Apply Join

Apply
Group
BY(Sort)

Return
Result
Interpreting Execution plan

Level 3

GROUP BY

Level 2

JOIN

Level 1

O_SALES

O_PRODUCT
Understanding the Execution Plans
Join Order
Join
Method

Join Type
Access
Method
Partition
Pruning

Cardinality

Parallel
Execution
Cardinality
1. Estimate no of rows coming out of the operation
2. Complex formula used for this calculations
3. Incorrect Cardinality

Total Rows: 18
Different val: 3
Access Method
Table

Index

Join

Full Table
Scan

Index
Unique Scan

Hash Joins

Row ID

Index Range
Scan

Nested
Loops joins

Index Skip
Scan

Sort Merge
Joins

Full Index
Scan
Fast Full
Index Scan
Bitmap
Index
Hints can be placed in SQL to force optimizer to follow our desired
retrieval path rather then calculated by the optimizer
Select /* +RULE */
From emp , dept
Where…..
Select statement instructs the optimizer to use the rule based
optimizer rather than the cost based optimizer.
Delete /*+RULE*/ . . . . . . . .
Update /*+RULE*/ . . . . . . . .

29
1. Data Warehousing using Oracle
Dr. P.S.Deshpande

2. The oracle optimizer explain the explain plan
Oracle.com
3. Oracle SQL Tuning Pocket Reference
Mark Gurry

30
31

Más contenido relacionado

La actualidad más candente

Mapreduce total order sorting technique
Mapreduce total order sorting techniqueMapreduce total order sorting technique
Mapreduce total order sorting technique
Uday Vakalapudi
 

La actualidad más candente (20)

sCode optimization
sCode optimizationsCode optimization
sCode optimization
 
Amortized analysis
Amortized analysisAmortized analysis
Amortized analysis
 
Lesson 3.2 data types for memory location
Lesson 3.2 data types for memory locationLesson 3.2 data types for memory location
Lesson 3.2 data types for memory location
 
Lesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th stepLesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th step
 
Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 3.1 variables and constant
Lesson 3.1 variables and constant
 
Analysis algorithm
Analysis algorithmAnalysis algorithm
Analysis algorithm
 
Lesson 5 .1 selection structure
Lesson 5 .1 selection structureLesson 5 .1 selection structure
Lesson 5 .1 selection structure
 
Arm developement
Arm developementArm developement
Arm developement
 
Lesson 5.2 logical operators
Lesson 5.2 logical operatorsLesson 5.2 logical operators
Lesson 5.2 logical operators
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
 
Lesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving processLesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving process
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
 
Project
ProjectProject
Project
 
Memoization & HOF
Memoization & HOFMemoization & HOF
Memoization & HOF
 
Lesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving processLesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving process
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
 
Data Structure Assignment help , Data Structure Online tutors
Data Structure Assignment help , Data Structure Online tutorsData Structure Assignment help , Data Structure Online tutors
Data Structure Assignment help , Data Structure Online tutors
 
Mapreduce total order sorting technique
Mapreduce total order sorting techniqueMapreduce total order sorting technique
Mapreduce total order sorting technique
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Parallel Algorithms- Sorting and Graph
Parallel Algorithms- Sorting and GraphParallel Algorithms- Sorting and Graph
Parallel Algorithms- Sorting and Graph
 

Destacado (8)

U-SQL Query Execution and Performance Basics (SQLBits 2016)
U-SQL Query Execution and Performance Basics (SQLBits 2016)U-SQL Query Execution and Performance Basics (SQLBits 2016)
U-SQL Query Execution and Performance Basics (SQLBits 2016)
 
DB2 Performance Tuning Z/OS - email me please for more details
DB2 Performance Tuning Z/OS - email me please for more detailsDB2 Performance Tuning Z/OS - email me please for more details
DB2 Performance Tuning Z/OS - email me please for more details
 
SQL Server Profiler & Performance Monitor - SarabPreet Singh
SQL Server Profiler & Performance Monitor - SarabPreet SinghSQL Server Profiler & Performance Monitor - SarabPreet Singh
SQL Server Profiler & Performance Monitor - SarabPreet Singh
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statements
 
Query execution
Query executionQuery execution
Query execution
 
Sql injection
Sql injectionSql injection
Sql injection
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
14. Query Optimization in DBMS
14. Query Optimization in DBMS14. Query Optimization in DBMS
14. Query Optimization in DBMS
 

Similar a Query Optimization & How to interpret query execution plan

Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0
PMILebanonChapter
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
gilpinleeanna
 
Hybrid rule engines (rulesfest 2010)
Hybrid rule engines (rulesfest 2010)Hybrid rule engines (rulesfest 2010)
Hybrid rule engines (rulesfest 2010)
Geoffrey De Smet
 
Adaptive Query Optimization in 12c
Adaptive Query Optimization in 12cAdaptive Query Optimization in 12c
Adaptive Query Optimization in 12c
Anju Garg
 

Similar a Query Optimization & How to interpret query execution plan (20)

Part5 sql tune
Part5 sql tunePart5 sql tune
Part5 sql tune
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain Plan
 
Processes in Query Optimization in (ABMS) Advanced Database Management Systems
Processes in Query Optimization in (ABMS) Advanced Database Management Systems Processes in Query Optimization in (ABMS) Advanced Database Management Systems
Processes in Query Optimization in (ABMS) Advanced Database Management Systems
 
Presentation top tips for getting optimal sql execution
Presentation    top tips for getting optimal sql executionPresentation    top tips for getting optimal sql execution
Presentation top tips for getting optimal sql execution
 
PLSQL Practices
PLSQL PracticesPLSQL Practices
PLSQL Practices
 
Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0
 
Chapter 6-Scheduling in Industrial of Engineering
Chapter 6-Scheduling in Industrial of EngineeringChapter 6-Scheduling in Industrial of Engineering
Chapter 6-Scheduling in Industrial of Engineering
 
Explaining the explain_plan
Explaining the explain_planExplaining the explain_plan
Explaining the explain_plan
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
Ground Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planGround Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_plan
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
 
Hybrid rule engines (rulesfest 2010)
Hybrid rule engines (rulesfest 2010)Hybrid rule engines (rulesfest 2010)
Hybrid rule engines (rulesfest 2010)
 
Twp optimizer-with-oracledb-12c-1963236
Twp optimizer-with-oracledb-12c-1963236Twp optimizer-with-oracledb-12c-1963236
Twp optimizer-with-oracledb-12c-1963236
 
Data envelopment analysis
Data envelopment analysisData envelopment analysis
Data envelopment analysis
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptx
 
Adaptive Query Optimization in 12c
Adaptive Query Optimization in 12cAdaptive Query Optimization in 12c
Adaptive Query Optimization in 12c
 
Cpk problem solving_pcba smt machine
Cpk problem solving_pcba smt machineCpk problem solving_pcba smt machine
Cpk problem solving_pcba smt machine
 
CSC1100 - Chapter12 - Flow Charts
CSC1100 - Chapter12 - Flow ChartsCSC1100 - Chapter12 - Flow Charts
CSC1100 - Chapter12 - Flow Charts
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Último (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
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
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
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...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
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
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 

Query Optimization & How to interpret query execution plan

  • 1. 1
  • 2. References Optimization Types of Optimization Understanding The Execution Plan Problem and Solutions with practical examples Query Optimization 2
  • 3. 3
  • 4. • RBO uses predefined set of precedence rules(golden rules) to figure out the optimal path • These rules used to choose one index over another index and when full table scan • Oracle 9i has 20 “golden rules” for optimal execution path ALTER SESSION SET OPTIMIZER_MODE = RULE/CHOOSE; 4
  • 5. 5
  • 6. 6
  • 8. Index1(A1,B,C); Table 1 Index2(A2,F,G); Table 2 Select * From Table1,Table2 Where A1=1 and B=2 and G=2 and F like ’%something’ and A1=A2 Two 1-Col Index: Table 1 Index1(A) Index2(B); One 2-Col Index: Table 2 Index3(E,F); 8
  • 10. Problem 1: Incorrect Driving Table SELECT COUNT(*) FROM acct a, trans b WHERE b.cost_center = 'MASS' AND a.acct_name = 'MGA' AND a.acct_name = b.acct_name; Response = 19.722 seconds SELECT COUNT(*) FROM trans b, acct a WHERE b.cost_center= 'MASS' AND a.acct_name = 'MGA' AND a.acct_name = b.acct_name; Response = 1.904 seconds 10
  • 11. Problem 2: Incorrect Driving Index SELECT COUNT(*) FROM trans WHERE cost_center = 'MASS' AND bmark_id = 9; Response Time = 4.255 seconds SELECT COUNT(*) FROM trans WHERE bmark_id = 9 AND cost_center = 'MASS'; Response Time = 1.044 seconds 11
  • 12. Problem 3: Using the ORDER BY Index and not the WHERE Index SELECT fod_flag, account_no FROM account_master WHERE (account_code like 'I%') ORDER BY account_no; Index_1 UNIQUE (ACCOUNT_NO) Index_2 (ACCOUNT_CODE) Index (ACCOUNT_CODE, ACCOUNT_NO) 12
  • 13. ANALYZE & DBMS_STATS ANALYZE Collect statistics about tables, clusters and indexes, and store those statistics in the data dictionary DBMS_STATS RULE BASED RULE BASED If table not analyzed CBO apply Rule Based Logic to select best path 13
  • 14. • ANALYZE COMPUTE & ANALYZE ESTIMATE • Table and it’s index • Index dropped..? • DBMS_STATS.GATHER_SCHEMA_STATS & GATHER_TABLE_STATS : CASCADE=>TRUE 14
  • 15. 1. ANALYZE TABLE EMP ESTIMATE STATISTICS SAMPLE 5 PERCENT FOR ALL INDEXED COLUMNS; 2. ANALYZE INDEX EMP_NDX1 ESTIMATE STATISTICS SAMPLE 5 PERCENT FOR ALL INDEXED COLUMNS; 3. ANALYZE TABLE EMP COMPUTE STATISTICS FOR ALL INDEXED COLUMNS; 4. ANALYZE TABLE EMP DELETE STATISTICS; 15
  • 16. • Check Syntax • Object Privilege Parse Plans • All possible execution plans listed • Calculate cost of each execution plans Cost 16
  • 17. Cost-Based Optimizer Problems and Solutions 17
  • 18. Problem 1: The Skewness Problem SELECT acct_no, customer, product, trans_date, amt FROM trans WHERE status='O'; Response time = 16.308 seconds > ANALYZE TABLE TRANS COMPUTE STATISTICS FOR ALL INDEXED COLUMNS Response time reduces to 0.259 seconds 18
  • 19. Problem 2: Analyzing with Wrong Data The cost-based optimizer requires accurate information, including accurate data volumes, to have any chance of creating efficient execution plans otherwise performance will degrade a large scale Example: Before analyze the cardinality is 1000(10000/10) on 10000 rows And now we insert the 10000 new rows with distinct values so what will be the new cardinality? 19
  • 20. Problem 4: Choosing an Inferior Index where business_unit = :5 and ledger = :6 and fiscal_year = :7 and accounting_period = :8 and affiliate = :9 and statistics_code = :10 and project_id = :11 and account = :12 and currency_cd = :13 and deptid = :14 and product = :15 20
  • 21. Problem 4: Choosing an Inferior Index where business_unit = :5 and ledger = :6 and fiscal_year = :7 and accounting_period between 1 and 12 and affiliate = :9 and statistics_code = :10 and project_id = :11 and account = :12 and currency_cd = :13 and deptid = :14 and product = :15 21
  • 22. Problem 4: Choosing an Inferior Index business_unit ledger fiscal_year affiliate statistics_code project_id account currency_cd deptid Product accounting_period 22
  • 23.
  • 24. SELECT prod_category, AVG(amount_sold) FROM o_sales s, o_products p WHERE p.prod_id = s.prod_id GROUP BY prod_category; GET SALES GET PRODUCTS Apply Join Apply Group BY(Sort) Return Result
  • 25. Interpreting Execution plan Level 3 GROUP BY Level 2 JOIN Level 1 O_SALES O_PRODUCT
  • 26. Understanding the Execution Plans Join Order Join Method Join Type Access Method Partition Pruning Cardinality Parallel Execution
  • 27. Cardinality 1. Estimate no of rows coming out of the operation 2. Complex formula used for this calculations 3. Incorrect Cardinality Total Rows: 18 Different val: 3
  • 28. Access Method Table Index Join Full Table Scan Index Unique Scan Hash Joins Row ID Index Range Scan Nested Loops joins Index Skip Scan Sort Merge Joins Full Index Scan Fast Full Index Scan Bitmap Index
  • 29. Hints can be placed in SQL to force optimizer to follow our desired retrieval path rather then calculated by the optimizer Select /* +RULE */ From emp , dept Where….. Select statement instructs the optimizer to use the rule based optimizer rather than the cost based optimizer. Delete /*+RULE*/ . . . . . . . . Update /*+RULE*/ . . . . . . . . 29
  • 30. 1. Data Warehousing using Oracle Dr. P.S.Deshpande 2. The oracle optimizer explain the explain plan Oracle.com 3. Oracle SQL Tuning Pocket Reference Mark Gurry 30
  • 31. 31

Notas del editor

  1. The driving table is read once and for each row in the driving table, the inner table is processed once. 
  2. When index on same no of columns and not all columns are match then rightmost table index is used
  3. ANALYZE & DBMS_STATS functions collect statistics about tables, clusters, and indexes, and store those statistics in the data dictionary.
  4. COMPUTE: ALL ROWS(Small table), ESTIMATE: SAMPLE ROWS(Large)DBMS_STATS.GATHER_SCHEMA_STATS and GATHER_TABLE_STATS analyze only tables by default, not their indexes
  5. Parameters should be considered for differentiating the good and bad execution plan
  6. Oracle uses histograms for the good cardinality prediction
  7. Index Unique Scan : Only one row will be returned by unique indexIndex Range Scan : =,<,>,LIKE (NON UNIQUE INDEX)Order BY clause has all the columns present in the index and order same as index