Presentation is loading. Please wait.

Presentation is loading. Please wait.

13 Copyright © 2005, Oracle. All rights reserved. Using the SQL Access Advisor.

Similar presentations


Presentation on theme: "13 Copyright © 2005, Oracle. All rights reserved. Using the SQL Access Advisor."— Presentation transcript:

1 13 Copyright © 2005, Oracle. All rights reserved. Using the SQL Access Advisor

2 13-2 Copyright © 2005, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Use the SQL Access Advisor to optimize your entire workload Use the Enterprise Manager SQL Access Advisor Wizard Use the DBMS_ADVISOR procedures

3 13-3 Copyright © 2005, Oracle. All rights reserved. What Does the SQL Access Advisor Do? Recommends the proper set of materialized views, materialized view logs, and indexes for a given workload Recommends bitmap, function-based, and B-tree indexes Recommends how to optimize materialized views so that they can be fast refreshable and take advantage of general query rewrite

4 13-4 Copyright © 2005, Oracle. All rights reserved. SQL Access Advisor: Overview Workload SQL Access Advisor Solution Component of optimizer Provides implementation script No expertise required DBA What indexes and materialized views do I need to optimize my entire workload?

5 13-5 Copyright © 2005, Oracle. All rights reserved. Full Notes Page

6 13-6 Copyright © 2005, Oracle. All rights reserved. SQL Access Advisor: Usage Model IndexesMaterialized views Materialized view logs SQL Access Advisor User-defined Hypothetical SQL cache Filter options STS Workload

7 13-7 Copyright © 2005, Oracle. All rights reserved. Possible Recommendations RecommendationComprehensiveLimited Add new index on table or materialized view.YES Drop an unused index.YESNO Modify an existing index by changing the index type. YESNO Modify an existing index by adding columns at the end. YES Add a new materialized view.YES Drop an unused materialized view.YESNO Add a new materialized view log.YES Modify an existing materialized view log to add new columns or clauses. YES

8 13-8 Copyright © 2005, Oracle. All rights reserved. Using the SQL Access Advisor Invoke the SQL Access Advisor Wizard in Enterprise Manager. Use procedures in the DBMS_ADVISOR package.

9 13-9 Copyright © 2005, Oracle. All rights reserved. SQL Access Advisor Repository Contains all information needed and generated by the SQL Access Advisor Part of the database dictionary

10 13-10 Copyright © 2005, Oracle. All rights reserved. Privileges Needed to Use the SQL Access Advisor ADVISOR system privilege SELECT privileges on tables targeted for materialized view analysis

11 13-11 Copyright © 2005, Oracle. All rights reserved. Invoking the SQL Access Advisor Wizard

12 13-12 Copyright © 2005, Oracle. All rights reserved. SQLAccessAdvOptions.gif Setting Initial Options

13 13-13 Copyright © 2005, Oracle. All rights reserved. Specifying the Workload Source

14 13-14 Copyright © 2005, Oracle. All rights reserved. Specifying Recommendation Options

15 13-15 Copyright © 2005, Oracle. All rights reserved. Specifying Recommendation Options

16 13-16 Copyright © 2005, Oracle. All rights reserved. Full Notes Page

17 13-17 Copyright © 2005, Oracle. All rights reserved. Viewing Results

18 13-18 Copyright © 2005, Oracle. All rights reserved. Reviewing Recommendations

19 13-19 Copyright © 2005, Oracle. All rights reserved. Using the DBMS_ADVISOR Package 1.Create a task and define parameters. 2.Define the workload. 3.Generate the recommendations. 4.View and implement the recommendations.

20 13-20 Copyright © 2005, Oracle. All rights reserved. SQL Access Advisor Procedure Flow SQLWkld object SQLAccess task CREATE_TASK DELETE_TASK UPDATE_TASK… CREATE_SQLWKLD DELETE_SQLWKLD QUICK_TUNE SET_TASK_PARAMETER SET_SQLWKLD_PARAMETER RESET_TASK RESET_SQLWKLD IMPORT_SQLWKLD… ADD_SQLWKLD_STAT… DELETE_SQLWKLD_STAT… UPDATE_SQLWKLD_STAT… ADD_SQLWKLD_REF DELETE_SQLWKLD_REF EXECUTE_TASK INTERRUPT / CANCEL_TASK MARK_RECOMMENDATION UPDATE_REC_ATTRIBUTES GET_TASK_REPORT Create/manage tasks and data. Gather and manage workload. Prepare tasks. Prepare and analyze data. Scripts

21 13-21 Copyright © 2005, Oracle. All rights reserved. Creating a Task Define parameters for the task using DBMS_ADVISOR.SET_TASK_PARAMETER. Create a task using DBMS_ADVISOR.CREATE_TASK. VARIABLE task_id NUMBER; VARIABLE task_name VARCHAR2(255); EXECUTE :task_name := 'MYTASK'; EXECUTE DBMS_ADVISOR.CREATE_TASK ('SQL Access Advisor', :task_id, :task_name);

22 13-22 Copyright © 2005, Oracle. All rights reserved. Setting SQL Access Advisor Parameters Set parameters using the DBMS_ADVISOR procedures: – SET_TASK_PARAMETER – SET_SQLWKLD_PARAMETER Types of parameters: –Workload filtering parameters –Task configuration parameters –Schema attributes parameters

23 13-23 Copyright © 2005, Oracle. All rights reserved. Using Templates Created by: –Setting the template attribute when creating the task –Using the UPDATE_TASK_ATTRIBUTE procedure Specified when using CREATE_TASK : VARIABLE template_id NUMBER; VARIABLE template_name VARCHAR2(255); EXECUTE :template_name := 'MY_TEMPLATE'; EXECUTE DBMS_ADVISOR.CREATE_TASK ('SQL Access Advisor',:template_id, - :template_name, is_template => 'TRUE');

24 13-24 Copyright © 2005, Oracle. All rights reserved. Setting Template Parameters Use DBMS_ADVISOR.SET_TASK_PARAMETER to set template parameters: EXECUTE DBMS_ADVISOR.SET_TASK_PARAMETER ( - :template_name,'INDEX_NAME_TEMPLATE', - 'SH_IDX$$_ '); EXECUTE DBMS_ADVISOR.SET_TASK_PARAMETER ( - :template_name, 'MVIEW_NAME_TEMPLATE', - 'SH_MV$$_ ');

25 13-25 Copyright © 2005, Oracle. All rights reserved. Using a Template to Create a Task Specify the template when using DBMS_ADVISOR.CREATE_TASK : VARIABLE task_id NUMBER; VARIABLE task_name VARCHAR2(255); EXECUTE :task_name := 'MYTASK'; EXECUTE DBMS_ADVISOR.CREATE_TASK ('SQL Access Advisor', :task_id, - :task_name, template=>'MY_TEMPLATE');

26 13-26 Copyright © 2005, Oracle. All rights reserved. Defining the Workload Created using DBMS_ADVISOR.CREATE_SQLWKLD Linked to a task using DBMS_ADVISOR.ADD_SQLWKLD_REF

27 13-27 Copyright © 2005, Oracle. All rights reserved. Defining Workload Contents SQL Tuning Sets User-defined workloads SQL cache workloads Hypothetical workloads Oracle Database 9 i Summary Advisor workloads

28 13-28 Copyright © 2005, Oracle. All rights reserved. Importing a SQL Tuning Set VARIABLE sqlsetname VARCHAR2(30); VARIABLE workload_name VARCHAR2(30); VARIABLE saved_stmts NUMBER; VARIABLE failed_stmts NUMBER; EXECUTE :sqlsetname := 'MY_STS_WORKLOAD'; EXECUTE :workload_name := 'MY_WORKLOAD'; EXECUTE DBMS_ADVISOR.CREATE_SQLWKLD (:workload_name); EXECUTE DBMS_ADVISOR.IMPORT_SQLWKLD_STS (:workload_name, - :sqlsetname, 'NEW', 1, :saved_stmts, :failed_stmts);

29 13-29 Copyright © 2005, Oracle. All rights reserved. Loading User-Defined Workloads VARIABLE saved_stmts NUMBER; VARIABLE failed_stmts NUMBER; EXECUTE DBMS_ADVISOR.IMPORT_SQLWKLD_USER( - 'MYWORKLOAD', 'NEW', 'SH', 'USER_WORKLOAD', :saved_stmts, :failed_stmts);

30 13-30 Copyright © 2005, Oracle. All rights reserved. Loading SQL Cache Workloads VARIABLE saved_stmts NUMBER; VARIABLE failed_stmts NUMBER; EXECUTE DBMS_ADVISOR.IMPORT_SQLWKLD_SQLCACHE (- 'MYWORKLOAD', 'APPEND', 2, :saved_stmts, :failed_stmts);

31 13-31 Copyright © 2005, Oracle. All rights reserved. Using Hypothetical Workloads VARIABLE workload_name VARCHAR2(255); VARIABLE saved_stmts NUMBER; VARIABLE failed_stmts NUMBER; EXECUTE :workload_name := 'SCHEMA_WKLD'; EXECUTE DBMS_ADVISOR.CREATE_SQLWKLD(:workload_name ); EXECUTE DBMS_ADVISOR.SET_SQLWKLD_PARAMETER (:workload_name, - VALID_TABLE_LIST, 'SH'); EXECUTE DBMS_ADVISOR.IMPORT_SQLWKLD_SCHEMA ( - :workload_name, 'NEW', 2, :saved_stmts, :failed_stmts);

32 13-32 Copyright © 2005, Oracle. All rights reserved. Adding SQL Statements to a Workload VARIABLE sql_text VARCHAR2(400); EXECUTE :sql_text := 'SELECT AVG(amount_sold) FROM sales'; EXECUTE DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT ( - 'MYWORKLOAD', 'MONTHLY', 'ROLLUP', priority=>1, executions=>10, - username => 'SH', sql_text => :sql_text);

33 13-33 Copyright © 2005, Oracle. All rights reserved. Removing Workloads EXECUTE DBMS_ADVISOR.DELETE_SQLWKLD ('MYWORKLOAD');

34 13-34 Copyright © 2005, Oracle. All rights reserved. Linking the Workload to a Task EXECUTE DBMS_ADVISOR.ADD_SQLWKLD_REF ('MYTASK', 'MYWORKLOAD');

35 13-35 Copyright © 2005, Oracle. All rights reserved. Generating Recommendations Generate recommendations by using DBMS_ADVISOR.EXECUTE_TASK. Recommendations are stored in the SQL Access Advisor Repository.

36 13-36 Copyright © 2005, Oracle. All rights reserved. Viewing and Implementing Recommendations Use catalog views: DBA/USER_ADVISOR_RECOMMENDATIONS Generate a script by using: DBMS_ADVISOR.GET_TASK_SCRIPT

37 13-37 Copyright © 2005, Oracle. All rights reserved. SQL Access Advisor Actions CREATE|DROP|RETAIN MATERIALIZED VIEW CREATE|ALTER|RETAIN MATERIALIZED VIEW LOG CREATE|DROP|RETAIN INDEX GATHER STATS

38 13-38 Copyright © 2005, Oracle. All rights reserved. Generating SQL Scripts Generate a CLOB containing the script for the recommendations: Save the Advisor script CLOB to a file: EXECUTE DBMS_ADVISOR.CREATE_FILE (DBMS_ADVISOR.GET_TASK_SCRIPT('MYTASK'), - 'ADVISOR_RESULTS', 'advscript.sql'); CREATE DIRECTORY ADVISOR_RESULTS AS '/mydir'; GRANT READ ON DIRECTORY ADVISOR_RESULTS TO PUBLIC; GRANT WRITE ON DIRECTORY ADVISOR_RESULTS TO PUBLIC;

39 13-39 Copyright © 2005, Oracle. All rights reserved. Performing a Quick Tune VARIABLE task_name VARCHAR2(255); VARIABLE sql_stmt VARCHAR2(4000); EXECUTE :sql_stmt := 'SELECT COUNT(*) FROM customers WHERE cust_state_province=''CA'''; EXECUTE :task_name := 'MY_QUICKTUNE_TASK'; EXECUTE DBMS_ADVISOR.QUICK_TUNE (DBMS_ADVISOR.SQLACCESS_ADVISOR, - :task_name, :sql_stmt); Tune a single SQL statement by using the QUICK_TUNE procedure:

40 13-40 Copyright © 2005, Oracle. All rights reserved. Tuning Materialized Views for Fast Refresh and Query Rewrite DBMS_MVIEW.EXPLAIN_MVIEW procedure: Advises whether a materialized view is fast refreshable or eligible for general query rewrite DBMS_MVIEW.EXPLAIN_REWRITE procedure: Advises whether query rewrite will occur DBMS_ADVISOR.TUNE_MVIEW procedure: Advises how to optimize your CREATE MATERIALIZED VIEW statement

41 13-41 Copyright © 2005, Oracle. All rights reserved. Using DBMS_ADVISOR.TUNE_MVIEW TUNE_MVIEW takes two input parameters: TASK_NAME : A user-provided task identifier used to access the output results MV_CREATE_STMT : A complete CREATE MATERIALIZED VIEW statement DBMS_ADVISOR.TUNE_MVIEW ( task_name IN OUT VARCHAR2, mv_create_stmt IN [CLOB | VARCHAR2])

42 13-42 Copyright © 2005, Oracle. All rights reserved. TUNE_MVIEW Output Results Implementation: For implementing materialized views and required components Undo: For dropping materialized views and rewrite equivalences

43 13-43 Copyright © 2005, Oracle. All rights reserved. Implementation Process Output CREATE MATERIALIZED VIEW LOG statements ALTER MATERIALIZED VIEW LOG FORCE statements One or more CREATE MATERIALIZED VIEW statements BUILD_SAFE_REWRITE_EQUIVALENCE statement

44 13-44 Copyright © 2005, Oracle. All rights reserved. Undo Process Output DROP MATERIALIZED VIEW statements DROP_REWRITE_EQUIVALENCE statement

45 13-45 Copyright © 2005, Oracle. All rights reserved. Accessing TUNE_MVIEW Output Results Script generation using the DBMS_ADVISOR.GET_TASK_SCRIPT function and the DBMS_ADVISOR.CREATE_FILE procedure USER_TUNE_MVIEW or DBA_TUNE_MVIEW views

46 13-46 Copyright © 2005, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Use the SQL Access Advisor to optimize your entire workload Use the Enterprise Manager SQL Access Advisor Wizard Use the DBMS_ADVISOR procedures

47 13-47 Copyright © 2005, Oracle. All rights reserved. Practice 13: Overview This practice covers using the SQL Access Advisor to tune a series of ad hoc queries.

48 13-48 Copyright © 2005, Oracle. All rights reserved.


Download ppt "13 Copyright © 2005, Oracle. All rights reserved. Using the SQL Access Advisor."

Similar presentations


Ads by Google