SlideShare a Scribd company logo
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

More Related Content

What's hot

sCode optimization
sCode optimizationsCode optimization
sCode optimization
Satyamevjayte Haxor
 
Amortized analysis
Amortized analysisAmortized analysis
Amortized analysis
Dr Shashikant Athawale
 
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
MLG College of Learning, Inc
 
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
MLG College of Learning, Inc
 
Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 3.1 variables and constant
Lesson 3.1 variables and constant
MLG College of Learning, Inc
 
Analysis algorithm
Analysis algorithmAnalysis algorithm
Analysis algorithm
renukarenuka9
 
Lesson 5 .1 selection structure
Lesson 5 .1 selection structureLesson 5 .1 selection structure
Lesson 5 .1 selection structure
MLG College of Learning, Inc
 
Arm developement
Arm developementArm developement
Arm developement
hirokiht
 
Lesson 5.2 logical operators
Lesson 5.2 logical operatorsLesson 5.2 logical operators
Lesson 5.2 logical operators
MLG College of Learning, Inc
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
Karthik Vivek
 
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
MLG College of Learning, Inc
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
Karthik Vivek
 
Project
ProjectProject
Memoization & HOF
Memoization & HOFMemoization & HOF
Memoization & HOF
Surendra Shukla
 
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
MLG College of Learning, Inc
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
Ankit Pandey
 
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
john mayer
 
Mapreduce total order sorting technique
Mapreduce total order sorting techniqueMapreduce total order sorting technique
Mapreduce total order sorting technique
Uday Vakalapudi
 
Algorithm
AlgorithmAlgorithm
Parallel Algorithms- Sorting and Graph
Parallel Algorithms- Sorting and GraphParallel Algorithms- Sorting and Graph
Parallel Algorithms- Sorting and Graph
Dr Shashikant Athawale
 

What's hot (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
 

Viewers also liked

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)
Michael Rys
 
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
Manikandan Suresh
 
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
Rishu Mehra
 
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
xKinAnx
 
Query execution
Query executionQuery execution
Query execution
Digvijay Singh
 
Sql injection
Sql injectionSql injection
Sql injection
Pallavi Biswas
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
Venkatesh Iyer
 
14. Query Optimization in DBMS
14. Query Optimization in DBMS14. Query Optimization in DBMS
14. Query Optimization in DBMS
koolkampus
 

Viewers also liked (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 to Query Optimization & How to interpret query execution plan

Part5 sql tune
Part5 sql tunePart5 sql tune
Part5 sql tune
Maria Colgan
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
Olav Sandstå
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain Plan
Maria Colgan
 
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
gamemaker762
 
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
xKinAnx
 
PLSQL Practices
PLSQL PracticesPLSQL Practices
PLSQL Practices
Quang Minh Đoàn
 
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
 
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
FaizAzmy2
 
Explaining the explain_plan
Explaining the explain_planExplaining the explain_plan
Explaining the explain_plan
arief12H
 
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
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
Nirav Shah
 
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
Maria Colgan
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
Olav Sandstå
 
Hybrid rule engines (rulesfest 2010)
Hybrid rule engines (rulesfest 2010)Hybrid rule engines (rulesfest 2010)
Hybrid rule engines (rulesfest 2010)
Geoffrey De Smet
 
Twp optimizer-with-oracledb-12c-1963236
Twp optimizer-with-oracledb-12c-1963236Twp optimizer-with-oracledb-12c-1963236
Twp optimizer-with-oracledb-12c-1963236
Santosh Kumar
 
Data envelopment analysis
Data envelopment analysisData envelopment analysis
Data envelopment analysis
Prashant Chouhan
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptx
TadiwaMawere
 
Adaptive Query Optimization in 12c
Adaptive Query Optimization in 12cAdaptive Query Optimization in 12c
Adaptive Query Optimization in 12c
Anju Garg
 
Cpk problem solving_pcba smt machine
Cpk problem solving_pcba smt machineCpk problem solving_pcba smt machine
Cpk problem solving_pcba smt machine
Shenzhen Southern Machinery Sales And Service Co., Ltd
 
CSC1100 - Chapter12 - Flow Charts
CSC1100 - Chapter12 - Flow ChartsCSC1100 - Chapter12 - Flow Charts
CSC1100 - Chapter12 - Flow Charts
Yhal Htet Aung
 

Similar to 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
 

Recently uploaded

CIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdfCIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdf
blueshagoo1
 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
Prof. Dr. K. Adisesha
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
Kalna College
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ShwetaGawande8
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Quiz Club IIT Kanpur
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
Kalna College
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
RandolphRadicy
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science
Kalna College
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
TechSoup
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
EduSkills OECD
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
Nguyen Thanh Tu Collection
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
indexPub
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
Celine George
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Celine George
 

Recently uploaded (20)

CIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdfCIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdf
 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
 

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

Editor's Notes

  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