Академический Документы
Профессиональный Документы
Культура Документы
What to expect
Explanation of common mistakes that cause sub-optimal execution plans and how to avoid them The assumption is that all statistics are accurate and the cause of the sub-optimal plan lies elsewhere
Agenda
Using the right tools Functions, friends or foes? Data type dilemmas ANSI versus Oracle syntax Influencing the execution plan without adding hints
Customers2 table has b-tree index on zipcode There is a histogram on the zipcode column due to data skew
Why is there a TO_NUMBER function on the bind variable n after it was defined as a number?
11
12
Agenda
Data type dilemmas ANSI versus Oracle syntax Influencing the execution plan without adding hints
13
14
15
Why is an equality predicate being evaluated as a filter and not an access predicate? Could it have something to do with the TO_CHAR function
16 Copyright 2011, Oracle and/or its affiliates. All rights reserved.
But literal value is a character string 139 Better to apply inverse function on other side of predicate
17 Copyright 2011, Oracle and/or its affiliates. All rights reserved.
18
Sales table is partitioned on the time_id column Sales table has quarterly partitions for historical data
19 Copyright 2011, Oracle and/or its affiliates. All rights reserved.
20
INTERNAL_FUNCTION typically means a data type conversion has occurred Predicate is TO_CHAR(s.time_id,YYYYMMDD) Optimizer has no idea how function will effect the values in the time_id column Optimizer cant determine which partitions will be accessed now
21
22
23
Agenda
Using the right tools Functions, friends or foes? Data type dilemmas ANSI versus Oracle syntax Influencing the execution plan without adding hints
24
So why is our access predicate applied as a filter? What does INTERNAL_FUNCTION mean?
26
27
29
Query calculate total amount sold that was return same day
SELECT sum(amount_sold) FROM sh.sales s, sh.sales_returns sr WHERE s.time_id = sr.time_id AND sr.time_id=31-DEC-01;
Sales table is range partitioned on time_id Sales table has 7 years of data in quarterly partitions
30 Copyright 2011, Oracle and/or its affiliates. All rights reserved.
Getting transitive predicate but Internal_function on partitioned column prevents pruning Function needed because the join columns have different data types
31 Copyright 2011, Oracle and/or its affiliates. All rights reserved.
KEY means dynamic pruning at execution time AP means And Pruning, caused by bloom filter Now get transitive predicate without data type conversion hence pruning
32 Copyright 2011, Oracle and/or its affiliates. All rights reserved.
Agenda
Using the right tools Functions, friends or foes? Data type dilemmas ANSI versus Oracle syntax Influencing the execution plan without adding hints
33
34
35
Why does the predicate section of the Oracle Syntax plan look so different from the Ansi SQL version?
36
37
SELECT e.empno FROM emp e WHERE (d.loc = 'NEW YORK' or e.ename like 'S%') AND d.deptno = e.deptno;
38
40
Agenda
Using the right tools Functions, friends or foes? Data type dilemmas ANSI versus Oracle syntax Influencing the execution plan without adding hints
41
42
43
44
45
46
47
48
49
51
Summary
Choose your plan displaying tool wisely
They dont all show the correct plan and can effect other sessions
Data types
If INTERNAL_FUNCTION appears in the predicate section check data types used in where clause predicates and across joins
Q&A
53
Oracle Optimizer: Prevent Suboptimal " Execution Plans" " Hands-on-Lab! Oracle Optimizer: Best Practices for Managing Optimizer Statistics"
Maria Colgan"
Senior Principal Member of Technical Staff" Oracle"
Maria Colgan"
Senior Principal Member of Technical Staff" Oracle"
Oracle Database Optimizer: Tips for " Preventing Suboptimal Execution Plans"
Maria Colgan"
Senior Principal Member of Technical Staff" Oracle"
Mohamed Zait"
Architect" Oracle"
54
55