SlideShare a Scribd company logo
1 of 27
Master Product Manager
Oracle Database
February 2020
Maria Colgan
Understanding the Oracle Optimizer
@SQLMaria
Part 1
Safe harbor statement
The following is intended to outline our general product direction. It is intended for information purposes
only, and may not be incorporated into any contract. It is not a commitment to deliver any material,
code, or functionality, and should not be relied upon in making purchasing decisions.
The development, release, timing, and pricing of any features or functionality described for Oracle’s
products may change and remains at the sole discretion of Oracle Corporation.
2
Confidential – © 2020 Oracle
3
5
4
3
2
1
SQL Tuning
Harnessing the Power of Optimizer Hints
Explain the Explain Plan
Best Practices for Managing Optimizer Statistics
Understanding the Oracle Optimizer
Agenda
4
How the
Oracle
Optimizer
Operates
5
1979 – 1991
RIP
“ In the beginning
there were rules …”
6
• Rule Based Optimizer (RBO) is a heuristic based Optimizer
- Uses a ranked list of access paths (rules)
- 17 possible access paths
- Lower ranked access paths assumed to operate more efficiently
• Plans chosen based on access paths available and their rank
- If multiple access paths exist, path with the lowest rank is chosen
• Only very simple physical optimizations done automatically
- OR Expansion: multiple OR predicates rewritten as UNION ALL
Oracle Version 6 and earlier
Rule Based Optimizer
SELECT count(*)
FROM emp
WHERE ename || ’’ = ‘SMITH’;
• Only way to influence RBO was
to change the SQL text
• Concatenating an empty string
to the column prevents the
index from being used
Famous tricks to work around RBO
Got an index access but want a full table scan
Dawn of a new era:
“ .. there is cost ..
“
1992
• Database features become more and more complex
• Partitioning
• Parallel execution
• No easy way to extend Rule Based Optimizer to accommodate so
many additional access paths
• Having only one plan per statement regardless of the objects size or
structure was no longer the best approach
Oracle 7 - dawn of a new era
Cost Based Optimizer
Optimizer must evolve to become cost based
• Initial design based on IBM research paper
• Access Path Selection in a Relational Database Management System (1979)
• Approach outlined in the paper was
• Multiple execution plans are generated for a statement
• Estimated cost is computed for each plan
• Optimizer selects the plan with the lowest estimated cost
Oracle 7 - dawn of a new era
Cost Based Optimizer
Understanding how the Optimizer works
Query Transformation
Rewrite query text to allow it to be processed
more efficiently
Plan Generator
Multiple plans are generated for
each SQL, using different access
paths and join types. Each plan is
costed and plan with the lowest
cost is used.
Cost Estimator
Cost is an estimate of the amount of
CPU and the number of disk I/Os,
used to perform an operation
Optimizer
Statistics
Schema definitions
• Translates statements into semantically equivalent SQL that can be processed more
efficiently
• Initial transformations were heuristic based
• Applied to SQL statements based on their structural properties only
• Predominately cost based now
• Transformations include
• Subquery Unnesting
• View Merging
• OR Expansion
• Star transformation
OptimizerTransformations
Subquery Unnesting
*Compares the cost of the best plan with and without the transformation
SELECT C.cust_last_name, C.country_id
FROM customers C
WHERE EXISTS(SELECT 1
FROM sales S
WHERE C.cust_id=S.cust_id
AND S.quantity_sold > 1000);
• A correlated subquery is one that
refers to a column from a table
outside the subquery
• In this case C.cust_id is
referenced in the subquery
• Without subquery unnesting the
correlated subquery must be
evaluated for each row in the
Customers tables
After theTransformation
Subquery Unnesting
*Compares the cost of the best plan with and without the transformation
• Transformation rewrites the
EXISTS subquery to an ANY
subquery
• ANY subquery is no longer
correlated
• ANY subquery returns a set of
CUST_IDs if any match the
predicate will return true
SELECT C.cust_last_name, C.country_id
FROM customers C
WHERE C.cust_id = ANY(SELECT S.cust_id
FROM sales S
WHERE S.quantity_sold > 1000);
After theTransformation
Subquery Unnesting
*Compares the cost of the best plan with and without the transformation
• Transformation allows subquery to
be evaluated as a SEMI join
• Subquery returns a set of
CUST_IDs those
CUST_IDs are joined to the
customers table via a
SEMI Hash Join
• Complex view merging
refers to the merging of
group by and distinct views
• Allows the optimizer to
consider additional join
orders and access paths
• Group-by/distinct
operations can be delayed
until after the joins have
been evaluated
ComplexView Merging
CREATE View cust_prod_totals_v as
SELECT SUM(s.quantity_sold) total, s.cust_id, s.prod_id
FROM sales s
GROUP BY s.cust_id, s.prod_id;
SELECT c.cust_id, c.cust_first_name, c.cust_last_name
FROM customers c,
cust_prod_totals_v v,
products p
WHERE c.country_id = 'US'
AND c.cust_id =v.cust_id
AND v.total > 100
AND v.prod_id = p.prod_id
AND p.prod_name = 'T3 Faux Fur-Trimmed Sweater';
• After transformation
GROUP BY operation
occurs after SALES is joined
to CUSTOMERS and
PRODUCTS
• Number of rows in GROUP
BY greatly reduced after
join
• May not always be best to
delay the GROUP BY or
DISTINCT operation
After theTransformation
ComplexView Merging
SELECT c.cust_id, c.cust_first_name, c.cust_last_name
FROM customers c,
products p,
sales s
WHERE c.country_id = 'US'
AND c.cust_id =s.cust_id
AND s.prod_id = p.prod_id
AND p.prod_name = 'T3 Faux Fur-Trimmed Sweater’
GROUP BY s.cust_id, s.prod_id, s.cust_id, s.prod_id,
p.rowid, c.rowid, c.cust_last_name,
c.cust_first_name, c.cust_id
HAVING SUM(s.quantity_sold) > 100
;
• Without the transformation Optimizer
treats OR predicate as a single unit
• Can’t use index on either column
• Or Expansion transforms queries that
contain OR predicates into the form of
a UNION ALL query of two or more
branches
OR Expansion
SELECT *
FROM products p
WHERE prod_category ='Photo'
OR prod_subcategory ='Camera Media';
• The transformation adds an
LNNVL() function to the second
branch in order to avoid duplicates
being generated across branches
• The LNNVL function returns TRUE, if
the predicate evaluates to FALSE or if
the predicate involved is NULL;
otherwise it will return FALSE
• lnnvl(true) is FALSE,
lnnvl(false||null) is TRUE
After theTransformation
OR Expansion
SELECT *
FROM products p
WHERE prod_subcategory ='Camera Media’
UNION ALL
SELECT *
FROM products p
WHERE prod_category ='Photo’
AND lnnvl(prod_subcategory =
'Camera Media')
;
Transformation allows an index access to be considered for each branch of the UNIONALL
OR Expansion
• Cost-based* transformation designed
to execute star queries more
efficiently
• Relies on bitmap indexes on foreign
key columns to access rows in the fact
table
• Controlled by parameter
STAR_TRANSFORMATION_ENABLED
StarTransformation
Sales
Fact
Table
Products
Dimension
Time
Dimension
Geography
Dimension
Suppliers
Dimension
Customers
Dimension
Star Schema - one or more large fact table
and many smaller dimension tables
*Compares the cost of the best plan with and without the transformation
• Traditionally a star query only defines
predicates on the dimension tables
• No efficient way to access rows in the
fact table
• By rewriting the query new access
paths become available on the fact
table
StarTransformation
*Compares the cost of the best plan with and without the transformation
SELECT c.cust_city, t.cal_quarter_desc,
SUM(s.amount_sold) sales_amt
FROM sales s, times t, customers c,
channels ch
WHERE s.time_id = t.time_id
AND s.cust_id = c.cust_id
AND s.channel_id = ch.channel_id
AND c.cust_state_province = 'CA'
AND ch.channel_desc = 'Internet'
AND t.calendar_quarter_desc IN ('2019-
04', '2020-01')
GROUP BY c.cust_city, t.cal_quarter_desc;
• Converts original query to
include 3 sub-queries on the
fact
After theTransformation
StarTransformation
SELECT c.cust_city, t.cal_quarter_desc,
SUM(s.amount_sold) sales_amt
FROM sales s, times t, customers c,
channels ch
WHERE s.time_id = t.time_id
AND s.cust_id = c.cust_id
AND s.channel_id = ch.channel_id
AND c.cust_state_province = 'CA'
AND ch.channel_desc = 'Internet'
AND t.calendar_quarter_desc IN ('2019-04', '2020-01’)
AND s.time_id IN (SELECT time_id
FROM times
WHERE cal_quarter_desc
IN('2019-01’,’2020-01’))
AND s.cust_id IN (SELECT cust_id
FROM customers
WHERE cust_state_province='CA’)
AND s.channel_id IN (SELECT channel_id
FROM channels
WHERE channel_desc = 'Internet')
GROUP BY c.cust_city, t.cal_quarter_desc;
--------------------------------------------------------------
| Id | Operation | Name |
--------------------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | HASH GROUP BY | |
|* 2 | HASH JOIN | |
|* 3 | TABLE ACCESS FULL | CUSTOMERS |
|* 4 | HASH JOIN | |
|* 5 | TABLE ACCESS FULL | TIMES |
| 6 | VIEW | VW_ST_B1772830|
| 7 | NESTED LOOPS | |
| 8 | PARTITION RANGE SUBQUERY | |
| 9 | BITMAP CONVERSION TO ROWIDS | |
| 10 | BITMAP AND | |
| 11 | BITMAP MERGE | |
| 12 | BITMAP KEY ITERATION | |
| 13 | BUFFER SORT | |
|* 14 | TABLE ACCESS FULL | CHANNELS |
|* 15 | BITMAP INDEX RANGE SCAN | SALES_CHANNEL_BIX|
| 16 | BITMAP MERGE | |
| 17 | BITMAP KEY ITERATION | |
| 18 | BUFFER SORT | |
|* 19 | TABLE ACCESS FULL | TIMES |
|* 20 | BITMAP INDEX RANGE SCAN | SALES_TIME_BIX |
| 21 | BITMAP MERGE | |
| 22 | BITMAP KEY ITERATION | |
| 23 | BUFFER SORT | |
|* 24 | TABLE ACCESS FULL | CUSTOMERS |
|* 25 | BITMAP INDEX RANGE SCAN | SALES_CUST_BIX |
| 26 | TABLE ACCESS BY USER ROWID | SALES |
--------------------------------------------------------------
After theTransformation
StarTransformation
• Converts original query to include 3
sub-queries on the fact
• Fact table accessed first via bitmap
index and then joins out to dimension
tables
• Result of sub-queries may be saved in
temp tables
Understanding how the Optimizer works
Query Transformation
Rewrite query text to allow it to be processed
more efficiently
Plan Generator
Multiple plans are generated for
each SQL, using different access
paths and join types. Each plan is
costed and plan with the lowest
cost is used.
Cost Estimator
Cost is an estimate of the amount of
CPU and the number of disk I/Os,
used to perform an operation
Optimizer
Statistics
Schema definitions
Understanding how the Optimizer works
Query Transformation
Rewrite query text to allow it to be processed
more efficiently
Plan Generator
Multiple plans are generated for
each SQL, using different access
paths and join types. Each plan is
costed and plan with the lowest
cost is used.
Cost Estimator
Cost is an estimate of the amount of
CPU and the number of disk I/Os,
used to perform an operation
Optimizer
Statistics
Schema definitions
Go to PART 2 – Best Practices for Managing Optimizer Statistics
27
Related Information
• White paper on Cost-Based Query
Transformation in Oracle
http://dl.acm.org/citation.cfm?id=1164215
Join the Conversation
https://twitter.com/SQLMaria
https://blogs.oracle.com/optimizer/
https://sqlmaria.com
https://www.facebook.com/SQLMaria

More Related Content

What's hot

Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by exampleMauro Pagano
 
Part2 Best Practices for Managing Optimizer Statistics
Part2 Best Practices for Managing Optimizer StatisticsPart2 Best Practices for Managing Optimizer Statistics
Part2 Best Practices for Managing Optimizer StatisticsMaria Colgan
 
Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Carlos Sierra
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuningSimon Huang
 
Oracle Database performance tuning using oratop
Oracle Database performance tuning using oratopOracle Database performance tuning using oratop
Oracle Database performance tuning using oratopSandesh Rao
 
Oracle Database Performance Tuning Concept
Oracle Database Performance Tuning ConceptOracle Database Performance Tuning Concept
Oracle Database Performance Tuning ConceptChien Chung Shen
 
Oracle AHF Insights 23c - Deeper Diagnostic Insights for your Oracle Database...
Oracle AHF Insights 23c - Deeper Diagnostic Insights for your Oracle Database...Oracle AHF Insights 23c - Deeper Diagnostic Insights for your Oracle Database...
Oracle AHF Insights 23c - Deeper Diagnostic Insights for your Oracle Database...Sandesh Rao
 
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTroubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTanel Poder
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0Norvald Ryeng
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuningGuy Harrison
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsJohn Beresniewicz
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsZohar Elkayam
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slidesMohamed Farouk
 
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
 
Open Source 101 2022 - MySQL Indexes and Histograms
Open Source 101 2022 - MySQL Indexes and HistogramsOpen Source 101 2022 - MySQL Indexes and Histograms
Open Source 101 2022 - MySQL Indexes and HistogramsFrederic Descamps
 
Migration to Oracle Multitenant
Migration to Oracle MultitenantMigration to Oracle Multitenant
Migration to Oracle MultitenantJitendra Singh
 
OOUG: Oracle transaction locking
OOUG: Oracle transaction lockingOOUG: Oracle transaction locking
OOUG: Oracle transaction lockingKyle Hailey
 

What's hot (20)

Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by example
 
Part2 Best Practices for Managing Optimizer Statistics
Part2 Best Practices for Managing Optimizer StatisticsPart2 Best Practices for Managing Optimizer Statistics
Part2 Best Practices for Managing Optimizer Statistics
 
Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
 
Oracle Database performance tuning using oratop
Oracle Database performance tuning using oratopOracle Database performance tuning using oratop
Oracle Database performance tuning using oratop
 
Oracle Database Performance Tuning Concept
Oracle Database Performance Tuning ConceptOracle Database Performance Tuning Concept
Oracle Database Performance Tuning Concept
 
Oracle AHF Insights 23c - Deeper Diagnostic Insights for your Oracle Database...
Oracle AHF Insights 23c - Deeper Diagnostic Insights for your Oracle Database...Oracle AHF Insights 23c - Deeper Diagnostic Insights for your Oracle Database...
Oracle AHF Insights 23c - Deeper Diagnostic Insights for your Oracle Database...
 
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTroubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuning
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
 
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...
 
SQLd360
SQLd360SQLd360
SQLd360
 
Open Source 101 2022 - MySQL Indexes and Histograms
Open Source 101 2022 - MySQL Indexes and HistogramsOpen Source 101 2022 - MySQL Indexes and Histograms
Open Source 101 2022 - MySQL Indexes and Histograms
 
AWR and ASH Deep Dive
AWR and ASH Deep DiveAWR and ASH Deep Dive
AWR and ASH Deep Dive
 
Migration to Oracle Multitenant
Migration to Oracle MultitenantMigration to Oracle Multitenant
Migration to Oracle Multitenant
 
OOUG: Oracle transaction locking
OOUG: Oracle transaction lockingOOUG: Oracle transaction locking
OOUG: Oracle transaction locking
 

Similar to Part1 of SQL Tuning Workshop - Understanding the Optimizer

Understanding DB2 Optimizer
Understanding DB2 OptimizerUnderstanding DB2 Optimizer
Understanding DB2 Optimizerterraborealis
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ICarlos Oliveira
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
A Deep Dive into HPCM for Planning and Essbase Professionals
A Deep Dive into HPCM for Planning and Essbase ProfessionalsA Deep Dive into HPCM for Planning and Essbase Professionals
A Deep Dive into HPCM for Planning and Essbase ProfessionalsAlithya
 
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 statementsxKinAnx
 
A Deep Dive into HPCM for Planning and Essbase Professionals
A Deep Dive into HPCM for Planning and Essbase ProfessionalsA Deep Dive into HPCM for Planning and Essbase Professionals
A Deep Dive into HPCM for Planning and Essbase ProfessionalsAlithya
 
QQ And Advance Query
QQ And Advance QueryQQ And Advance Query
QQ And Advance QueryKai Liu
 
Presentation v mware roi tco calculator
Presentation   v mware roi tco calculatorPresentation   v mware roi tco calculator
Presentation v mware roi tco calculatorsolarisyourep
 
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.pdfcookie1969
 
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
 
Ps training mannual ( configuration )
Ps training mannual ( configuration )Ps training mannual ( configuration )
Ps training mannual ( configuration )Soumya De
 
Revolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn PipelinesRevolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn PipelinesPhilip Goddard
 
Software archiecture lecture08
Software archiecture   lecture08Software archiecture   lecture08
Software archiecture lecture08Luktalja
 
Apex and Virtual Private Database
Apex and Virtual Private DatabaseApex and Virtual Private Database
Apex and Virtual Private DatabaseJeffrey Kemp
 
Simplifying the Complexity of Salesforce CPQ: Tips & Best Practices
Simplifying the Complexity of Salesforce CPQ: Tips & Best PracticesSimplifying the Complexity of Salesforce CPQ: Tips & Best Practices
Simplifying the Complexity of Salesforce CPQ: Tips & Best Practicespanayaofficial
 
Modernizing SQL Server the Right Way
Modernizing SQL Server the Right WayModernizing SQL Server the Right Way
Modernizing SQL Server the Right WayJuan Fabian
 
My Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cMy Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cNelson Calero
 

Similar to Part1 of SQL Tuning Workshop - Understanding the Optimizer (20)

Understanding DB2 Optimizer
Understanding DB2 OptimizerUnderstanding DB2 Optimizer
Understanding DB2 Optimizer
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
A Deep Dive into HPCM for Planning and Essbase Professionals
A Deep Dive into HPCM for Planning and Essbase ProfessionalsA Deep Dive into HPCM for Planning and Essbase Professionals
A Deep Dive into HPCM for Planning and Essbase Professionals
 
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
 
A Deep Dive into HPCM for Planning and Essbase Professionals
A Deep Dive into HPCM for Planning and Essbase ProfessionalsA Deep Dive into HPCM for Planning and Essbase Professionals
A Deep Dive into HPCM for Planning and Essbase Professionals
 
QQ And Advance Query
QQ And Advance QueryQQ And Advance Query
QQ And Advance Query
 
Oracle query optimizer
Oracle query optimizerOracle query optimizer
Oracle query optimizer
 
Presentation v mware roi tco calculator
Presentation   v mware roi tco calculatorPresentation   v mware roi tco calculator
Presentation v mware roi tco calculator
 
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
 
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
 
Ps training mannual ( configuration )
Ps training mannual ( configuration )Ps training mannual ( configuration )
Ps training mannual ( configuration )
 
Revolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn PipelinesRevolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
 
Conversion Detail
Conversion DetailConversion Detail
Conversion Detail
 
Software archiecture lecture08
Software archiecture   lecture08Software archiecture   lecture08
Software archiecture lecture08
 
Apex and Virtual Private Database
Apex and Virtual Private DatabaseApex and Virtual Private Database
Apex and Virtual Private Database
 
Simplifying the Complexity of Salesforce CPQ: Tips & Best Practices
Simplifying the Complexity of Salesforce CPQ: Tips & Best PracticesSimplifying the Complexity of Salesforce CPQ: Tips & Best Practices
Simplifying the Complexity of Salesforce CPQ: Tips & Best Practices
 
Modernizing SQL Server the Right Way
Modernizing SQL Server the Right WayModernizing SQL Server the Right Way
Modernizing SQL Server the Right Way
 
My Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cMy Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12c
 
Oracle APEX
Oracle APEXOracle APEX
Oracle APEX
 

More from Maria Colgan

Part4 Influencing Execution Plans with Optimizer Hints
Part4 Influencing Execution Plans with Optimizer HintsPart4 Influencing Execution Plans with Optimizer Hints
Part4 Influencing Execution Plans with Optimizer HintsMaria Colgan
 
Ground Breakers Romania: Oracle Autonomous Database
Ground Breakers Romania: Oracle Autonomous DatabaseGround Breakers Romania: Oracle Autonomous Database
Ground Breakers Romania: Oracle Autonomous DatabaseMaria Colgan
 
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_planMaria Colgan
 
What to Expect From Oracle database 19c
What to Expect From Oracle database 19cWhat to Expect From Oracle database 19c
What to Expect From Oracle database 19cMaria Colgan
 
The Changing Role of a DBA in an Autonomous World
The Changing Role of a DBA in an Autonomous WorldThe Changing Role of a DBA in an Autonomous World
The Changing Role of a DBA in an Autonomous WorldMaria Colgan
 
Oracle Database in-Memory Overivew
Oracle Database in-Memory OverivewOracle Database in-Memory Overivew
Oracle Database in-Memory OverivewMaria Colgan
 
Useful PL/SQL Supplied Packages
Useful PL/SQL Supplied PackagesUseful PL/SQL Supplied Packages
Useful PL/SQL Supplied PackagesMaria Colgan
 
JSON and the Oracle Database
JSON and the Oracle DatabaseJSON and the Oracle Database
JSON and the Oracle DatabaseMaria Colgan
 
Five Tips to Get the Most Out of Your Indexing
Five Tips to Get the Most Out of Your IndexingFive Tips to Get the Most Out of Your Indexing
Five Tips to Get the Most Out of Your IndexingMaria Colgan
 
Harnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer HintsHarnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer HintsMaria Colgan
 
Oracle optimizer bootcamp
Oracle optimizer bootcampOracle optimizer bootcamp
Oracle optimizer bootcampMaria Colgan
 
What_to_expect_from_oracle_database_12c
What_to_expect_from_oracle_database_12cWhat_to_expect_from_oracle_database_12c
What_to_expect_from_oracle_database_12cMaria Colgan
 
Oracle database 12c_and_DevOps
Oracle database 12c_and_DevOpsOracle database 12c_and_DevOps
Oracle database 12c_and_DevOpsMaria Colgan
 

More from Maria Colgan (13)

Part4 Influencing Execution Plans with Optimizer Hints
Part4 Influencing Execution Plans with Optimizer HintsPart4 Influencing Execution Plans with Optimizer Hints
Part4 Influencing Execution Plans with Optimizer Hints
 
Ground Breakers Romania: Oracle Autonomous Database
Ground Breakers Romania: Oracle Autonomous DatabaseGround Breakers Romania: Oracle Autonomous Database
Ground Breakers Romania: Oracle Autonomous Database
 
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
 
What to Expect From Oracle database 19c
What to Expect From Oracle database 19cWhat to Expect From Oracle database 19c
What to Expect From Oracle database 19c
 
The Changing Role of a DBA in an Autonomous World
The Changing Role of a DBA in an Autonomous WorldThe Changing Role of a DBA in an Autonomous World
The Changing Role of a DBA in an Autonomous World
 
Oracle Database in-Memory Overivew
Oracle Database in-Memory OverivewOracle Database in-Memory Overivew
Oracle Database in-Memory Overivew
 
Useful PL/SQL Supplied Packages
Useful PL/SQL Supplied PackagesUseful PL/SQL Supplied Packages
Useful PL/SQL Supplied Packages
 
JSON and the Oracle Database
JSON and the Oracle DatabaseJSON and the Oracle Database
JSON and the Oracle Database
 
Five Tips to Get the Most Out of Your Indexing
Five Tips to Get the Most Out of Your IndexingFive Tips to Get the Most Out of Your Indexing
Five Tips to Get the Most Out of Your Indexing
 
Harnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer HintsHarnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer Hints
 
Oracle optimizer bootcamp
Oracle optimizer bootcampOracle optimizer bootcamp
Oracle optimizer bootcamp
 
What_to_expect_from_oracle_database_12c
What_to_expect_from_oracle_database_12cWhat_to_expect_from_oracle_database_12c
What_to_expect_from_oracle_database_12c
 
Oracle database 12c_and_DevOps
Oracle database 12c_and_DevOpsOracle database 12c_and_DevOps
Oracle database 12c_and_DevOps
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Part1 of SQL Tuning Workshop - Understanding the Optimizer

  • 1. Master Product Manager Oracle Database February 2020 Maria Colgan Understanding the Oracle Optimizer @SQLMaria Part 1
  • 2. Safe harbor statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation. 2 Confidential – © 2020 Oracle
  • 3. 3 5 4 3 2 1 SQL Tuning Harnessing the Power of Optimizer Hints Explain the Explain Plan Best Practices for Managing Optimizer Statistics Understanding the Oracle Optimizer Agenda
  • 5. 5 1979 – 1991 RIP “ In the beginning there were rules …”
  • 6. 6 • Rule Based Optimizer (RBO) is a heuristic based Optimizer - Uses a ranked list of access paths (rules) - 17 possible access paths - Lower ranked access paths assumed to operate more efficiently • Plans chosen based on access paths available and their rank - If multiple access paths exist, path with the lowest rank is chosen • Only very simple physical optimizations done automatically - OR Expansion: multiple OR predicates rewritten as UNION ALL Oracle Version 6 and earlier Rule Based Optimizer
  • 7. SELECT count(*) FROM emp WHERE ename || ’’ = ‘SMITH’; • Only way to influence RBO was to change the SQL text • Concatenating an empty string to the column prevents the index from being used Famous tricks to work around RBO Got an index access but want a full table scan
  • 8. Dawn of a new era: “ .. there is cost .. “ 1992
  • 9. • Database features become more and more complex • Partitioning • Parallel execution • No easy way to extend Rule Based Optimizer to accommodate so many additional access paths • Having only one plan per statement regardless of the objects size or structure was no longer the best approach Oracle 7 - dawn of a new era Cost Based Optimizer Optimizer must evolve to become cost based
  • 10. • Initial design based on IBM research paper • Access Path Selection in a Relational Database Management System (1979) • Approach outlined in the paper was • Multiple execution plans are generated for a statement • Estimated cost is computed for each plan • Optimizer selects the plan with the lowest estimated cost Oracle 7 - dawn of a new era Cost Based Optimizer
  • 11. Understanding how the Optimizer works Query Transformation Rewrite query text to allow it to be processed more efficiently Plan Generator Multiple plans are generated for each SQL, using different access paths and join types. Each plan is costed and plan with the lowest cost is used. Cost Estimator Cost is an estimate of the amount of CPU and the number of disk I/Os, used to perform an operation Optimizer Statistics Schema definitions
  • 12. • Translates statements into semantically equivalent SQL that can be processed more efficiently • Initial transformations were heuristic based • Applied to SQL statements based on their structural properties only • Predominately cost based now • Transformations include • Subquery Unnesting • View Merging • OR Expansion • Star transformation OptimizerTransformations
  • 13. Subquery Unnesting *Compares the cost of the best plan with and without the transformation SELECT C.cust_last_name, C.country_id FROM customers C WHERE EXISTS(SELECT 1 FROM sales S WHERE C.cust_id=S.cust_id AND S.quantity_sold > 1000); • A correlated subquery is one that refers to a column from a table outside the subquery • In this case C.cust_id is referenced in the subquery • Without subquery unnesting the correlated subquery must be evaluated for each row in the Customers tables
  • 14. After theTransformation Subquery Unnesting *Compares the cost of the best plan with and without the transformation • Transformation rewrites the EXISTS subquery to an ANY subquery • ANY subquery is no longer correlated • ANY subquery returns a set of CUST_IDs if any match the predicate will return true SELECT C.cust_last_name, C.country_id FROM customers C WHERE C.cust_id = ANY(SELECT S.cust_id FROM sales S WHERE S.quantity_sold > 1000);
  • 15. After theTransformation Subquery Unnesting *Compares the cost of the best plan with and without the transformation • Transformation allows subquery to be evaluated as a SEMI join • Subquery returns a set of CUST_IDs those CUST_IDs are joined to the customers table via a SEMI Hash Join
  • 16. • Complex view merging refers to the merging of group by and distinct views • Allows the optimizer to consider additional join orders and access paths • Group-by/distinct operations can be delayed until after the joins have been evaluated ComplexView Merging CREATE View cust_prod_totals_v as SELECT SUM(s.quantity_sold) total, s.cust_id, s.prod_id FROM sales s GROUP BY s.cust_id, s.prod_id; SELECT c.cust_id, c.cust_first_name, c.cust_last_name FROM customers c, cust_prod_totals_v v, products p WHERE c.country_id = 'US' AND c.cust_id =v.cust_id AND v.total > 100 AND v.prod_id = p.prod_id AND p.prod_name = 'T3 Faux Fur-Trimmed Sweater';
  • 17. • After transformation GROUP BY operation occurs after SALES is joined to CUSTOMERS and PRODUCTS • Number of rows in GROUP BY greatly reduced after join • May not always be best to delay the GROUP BY or DISTINCT operation After theTransformation ComplexView Merging SELECT c.cust_id, c.cust_first_name, c.cust_last_name FROM customers c, products p, sales s WHERE c.country_id = 'US' AND c.cust_id =s.cust_id AND s.prod_id = p.prod_id AND p.prod_name = 'T3 Faux Fur-Trimmed Sweater’ GROUP BY s.cust_id, s.prod_id, s.cust_id, s.prod_id, p.rowid, c.rowid, c.cust_last_name, c.cust_first_name, c.cust_id HAVING SUM(s.quantity_sold) > 100 ;
  • 18. • Without the transformation Optimizer treats OR predicate as a single unit • Can’t use index on either column • Or Expansion transforms queries that contain OR predicates into the form of a UNION ALL query of two or more branches OR Expansion SELECT * FROM products p WHERE prod_category ='Photo' OR prod_subcategory ='Camera Media';
  • 19. • The transformation adds an LNNVL() function to the second branch in order to avoid duplicates being generated across branches • The LNNVL function returns TRUE, if the predicate evaluates to FALSE or if the predicate involved is NULL; otherwise it will return FALSE • lnnvl(true) is FALSE, lnnvl(false||null) is TRUE After theTransformation OR Expansion SELECT * FROM products p WHERE prod_subcategory ='Camera Media’ UNION ALL SELECT * FROM products p WHERE prod_category ='Photo’ AND lnnvl(prod_subcategory = 'Camera Media') ;
  • 20. Transformation allows an index access to be considered for each branch of the UNIONALL OR Expansion
  • 21. • Cost-based* transformation designed to execute star queries more efficiently • Relies on bitmap indexes on foreign key columns to access rows in the fact table • Controlled by parameter STAR_TRANSFORMATION_ENABLED StarTransformation Sales Fact Table Products Dimension Time Dimension Geography Dimension Suppliers Dimension Customers Dimension Star Schema - one or more large fact table and many smaller dimension tables *Compares the cost of the best plan with and without the transformation
  • 22. • Traditionally a star query only defines predicates on the dimension tables • No efficient way to access rows in the fact table • By rewriting the query new access paths become available on the fact table StarTransformation *Compares the cost of the best plan with and without the transformation SELECT c.cust_city, t.cal_quarter_desc, SUM(s.amount_sold) sales_amt FROM sales s, times t, customers c, channels ch WHERE s.time_id = t.time_id AND s.cust_id = c.cust_id AND s.channel_id = ch.channel_id AND c.cust_state_province = 'CA' AND ch.channel_desc = 'Internet' AND t.calendar_quarter_desc IN ('2019- 04', '2020-01') GROUP BY c.cust_city, t.cal_quarter_desc;
  • 23. • Converts original query to include 3 sub-queries on the fact After theTransformation StarTransformation SELECT c.cust_city, t.cal_quarter_desc, SUM(s.amount_sold) sales_amt FROM sales s, times t, customers c, channels ch WHERE s.time_id = t.time_id AND s.cust_id = c.cust_id AND s.channel_id = ch.channel_id AND c.cust_state_province = 'CA' AND ch.channel_desc = 'Internet' AND t.calendar_quarter_desc IN ('2019-04', '2020-01’) AND s.time_id IN (SELECT time_id FROM times WHERE cal_quarter_desc IN('2019-01’,’2020-01’)) AND s.cust_id IN (SELECT cust_id FROM customers WHERE cust_state_province='CA’) AND s.channel_id IN (SELECT channel_id FROM channels WHERE channel_desc = 'Internet') GROUP BY c.cust_city, t.cal_quarter_desc;
  • 24. -------------------------------------------------------------- | Id | Operation | Name | -------------------------------------------------------------- | 0 | SELECT STATEMENT | | | 1 | HASH GROUP BY | | |* 2 | HASH JOIN | | |* 3 | TABLE ACCESS FULL | CUSTOMERS | |* 4 | HASH JOIN | | |* 5 | TABLE ACCESS FULL | TIMES | | 6 | VIEW | VW_ST_B1772830| | 7 | NESTED LOOPS | | | 8 | PARTITION RANGE SUBQUERY | | | 9 | BITMAP CONVERSION TO ROWIDS | | | 10 | BITMAP AND | | | 11 | BITMAP MERGE | | | 12 | BITMAP KEY ITERATION | | | 13 | BUFFER SORT | | |* 14 | TABLE ACCESS FULL | CHANNELS | |* 15 | BITMAP INDEX RANGE SCAN | SALES_CHANNEL_BIX| | 16 | BITMAP MERGE | | | 17 | BITMAP KEY ITERATION | | | 18 | BUFFER SORT | | |* 19 | TABLE ACCESS FULL | TIMES | |* 20 | BITMAP INDEX RANGE SCAN | SALES_TIME_BIX | | 21 | BITMAP MERGE | | | 22 | BITMAP KEY ITERATION | | | 23 | BUFFER SORT | | |* 24 | TABLE ACCESS FULL | CUSTOMERS | |* 25 | BITMAP INDEX RANGE SCAN | SALES_CUST_BIX | | 26 | TABLE ACCESS BY USER ROWID | SALES | -------------------------------------------------------------- After theTransformation StarTransformation • Converts original query to include 3 sub-queries on the fact • Fact table accessed first via bitmap index and then joins out to dimension tables • Result of sub-queries may be saved in temp tables
  • 25. Understanding how the Optimizer works Query Transformation Rewrite query text to allow it to be processed more efficiently Plan Generator Multiple plans are generated for each SQL, using different access paths and join types. Each plan is costed and plan with the lowest cost is used. Cost Estimator Cost is an estimate of the amount of CPU and the number of disk I/Os, used to perform an operation Optimizer Statistics Schema definitions
  • 26. Understanding how the Optimizer works Query Transformation Rewrite query text to allow it to be processed more efficiently Plan Generator Multiple plans are generated for each SQL, using different access paths and join types. Each plan is costed and plan with the lowest cost is used. Cost Estimator Cost is an estimate of the amount of CPU and the number of disk I/Os, used to perform an operation Optimizer Statistics Schema definitions Go to PART 2 – Best Practices for Managing Optimizer Statistics
  • 27. 27 Related Information • White paper on Cost-Based Query Transformation in Oracle http://dl.acm.org/citation.cfm?id=1164215 Join the Conversation https://twitter.com/SQLMaria https://blogs.oracle.com/optimizer/ https://sqlmaria.com https://www.facebook.com/SQLMaria