Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 8 Execution Plan Management. 2 Overview of Execution Plan Management Review techniques to – override optimizer – Improve optimizer’s decisions.

Similar presentations


Presentation on theme: "1 Chapter 8 Execution Plan Management. 2 Overview of Execution Plan Management Review techniques to – override optimizer – Improve optimizer’s decisions."— Presentation transcript:

1 1 Chapter 8 Execution Plan Management

2 2 Overview of Execution Plan Management Review techniques to – override optimizer – Improve optimizer’s decisions Techniques discussed in this chapter are: – Hints – Stored Outlines – Creating Profiles – Utilizing baselines

3 3 Hints Instructions to guide optimizer Optimizer obliges even if inefficient Done within SELECT or DML statement Example: SELECT /+* FULL(customers) */ * FROM customers WHERE cust_year_of_birth = 1976 AND cust_gender = ‘F’ AND cust_marital_status = ‘single’;

4 4 Hints (cont.) Done to request particular access path – Request a full table scan – Request the use of an index – Request a particular type of join – Request the optimizer_mode for the query – Request parallelism – See common hints on pp. 212-213 Multiple hints can be used in one statement

5 5 More Hint Examples Requesting an index SELECT /+* index(e emp_manager_ix) */ employee_id, first_name, last_name FROM employees e WHERE manager_id = 100 AND department_id = 90; Requesting join order & type of join SELECT /+* ORDERED USE_HASH(e) */ * FROM departments d JOIN employees e USING (department_id); See pp. 214-215 for more examples

6 6 Errors in Hints Errors in hints generate no error Hints with errors are simply ignored Use of aliases in hint must match what is specified in SQL Validate use of hint using – DBMS_XPLAN – Autotrace – TKPROF

7 7 Stored Outlines Ensure that specific execution plan is used regardless of statistics Also known as “Plan Stability Advantages – Prevents runtime optimizer “bad execution plans” – Better than locking statistics / relevant only to given SQL – “Locks” execution plan and thus seen performance on SQL – Can be public or private Disadvantages – Does not take advantage of more current statistics – Will be deprecated in future release (see Baselines) – Public vs. private outline configuration a bit confusing

8 8 Stored Outlines (cont.) Example of candidate SQL statement – Performs well for clients – Does full-table scan – Has secondary index on cust_year_of_birth – Based on statistics, optimizer may decide to use index at any time (any run of the statement) – Regardless of what optimizer “thinks”, you want to lock the performance of this statement SELECT MAX(cust_income_level) FROM customers WHERE cust_year_of_birth >1985;

9 9 Stored Outlines (cont.) Example of outline to satisfy previous requirement – Create the outline CREATE OUTLINE customer_yob_qry FOR CATEGORY outlines 2 ON SELECT MAX(cust_income_level) FROM customers WHERE cust_year_of_birth >1985; – Enable the outline ALTER SESSION SET use_stored_outlines=outlines2; – Validate use of outline Via DBMS_XPLAN Autotrace

10 10 Stored Outlines (cont.) Hacking an outline to temporarily modify an execution plan (e.g. – you want to add a hint) – Use a private outline on top of a public outline CREATE PRIVATE OUTLINE original_oln FROM cust_yob_otln; CREATE PRIVATE OUTLINE hinted_oln ON SELECT /*+ INDEX(customers) */ MIN(cust_income_level) FROM customers WHERE cust_year_of_birth > 1985; ALTER SESSION SET use_private_outlines=TRUE; – See global temporary table OL$HINTS to see optimizer results for each private outline to analyze results

11 11 SQL Tuning Sets A group of SQL statements processed as group – Use with currently cached SQL – From SQL from Automatic Workload Repository – From a manual workload Processed by Oracle Tuning & Plan Management Create Tuning Sets – Manually using DBMS_SQLTUNE package – Via Enterprise Manager Need Tuning Pack license See SQL Tuning Advisor & SQL Access Advisor

12 12 SQL Profiles Contrast between Profiles and Outlines – Outline focuses on stability – Profiles focus on flexibility Associated with SQL Tuning Advisor – Known as a “offline optimizer” Advantages of SQL Tuning Advisor – Can spend more time optimizing SQL – Can partially run SQL before deciding on plan – Can create a profile for future use – Can be shared between logically similar statements

13 13 SQL Baselines Supplements SQL Profiles Will eventually replace stored outlines Provides mechanism to ensure plan improvement Offers flexibility and stability – Ensures a plan will not be degraded by inferior plan Create via DBMS_SPM package Can be viewed via DBA_SQL_PLAN_BASELINES

14 14 SQL Baselines (cont.) Controlled via parameters – OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES – OPTIMIZER_USE_SQL_PLAN_BASELINES Evolving a baseline over time – Optimizer lets humans decide on a proposed change – Subsequent superior plans are: stored as “unaccepted” in DBA_SQL_PLAN_BASELINES view not used until “verified” – Verification manual via EVOLVE_SQL_PLAN_BASELINE procedure Baselines can be configured in Enterprise Manager


Download ppt "1 Chapter 8 Execution Plan Management. 2 Overview of Execution Plan Management Review techniques to – override optimizer – Improve optimizer’s decisions."

Similar presentations


Ads by Google