Using the SQLAccess Advisor to Recommend Materialized Views and Indexes
Using the SQLAccess Advisor to Recommend Materialized
Views and Indexes
This tutorial describes how to use the SQL Access Advisor
to obtain materialized view and index recommendations to optimize performance.
Approximately 30 minutes
This tutorial covers the following topics:
Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.)
Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.
The SQL Access Advisor provides a number of procedures that
can be called to help decide which materialized views and indexes to create
and drop. It makes this decision by using either a hypothetical workload, which
it bases on your schema, or an actual workload that can be provided by the user
from Oracle Trace or from the contents of the SQL cache.
Workloads may also be filtered according to different criteria,
such as use only queries that contain these tables or queries that have a priority
within this range.
Back to Topic List
Before starting this tutorial, you should:
Back to Topic List
To prepare the environment for using the SQL Access Advisor,
you perform the following steps. (Materialized views and indexes can be present
when the advisor is run, but for the purposes of this example, they are removed
so that you can see what the advisor will recommend. You must also set up the
cache so that the SQL Access Advisor can generate some recommendations.)
| 1. |
Invoke SQL*Plus as follows:
Select Start > Programs > Oracle - OraDb10g_home1 > Application Development > SQL Plus. Enter /nolog for the User Name and click OK.
Connect as sysdba:
connect / as sysdba
|
| 2. |
Now you must create the cache. Execute the following
command:
@c:\wkdir\advisor_cache_setup
The advisor_cache_setup.sql
script contains the following:
alter system flush shared_pool; grant advisor to sh;
connect sh/sh; SELECT c.cust_last_name, sum(s.amount_sold) AS dollars, sum(s.quantity_sold) as quantity FROM sales s , customers c, products p WHERE c.cust_id = s.cust_id AND s.prod_id = p.prod_id AND c.cust_state_province IN ('Dublin','Galway') GROUP BY c.cust_last_name;
SELECT c.cust_id, SUM(amount_sold) AS dollar_sales FROM sales s, customers c WHERE s.cust_id= c.cust_id GROUP BY c.cust_id;
select sum(unit_cost) from costs group by prod_id;

|
Back to Topic List
You use the SQL Cache you just set up to obtain some recommendations
from the SQLAccess Advisor. Perform the following steps:
| 1. |
Open your browser and invoke Enterprise Manager Database Control by entering the following URL:
http://<your host name>:1158/em
Enter sys/oracle as SYSDBA
and click Login.

|
| 2. |
Scroll to the bottom of the Home
page and click Advisor Central in the Related Links section.

|
| 3. |
Click the SQL Access Advisor link.

|
| 4. |
Select Use Default Options and click Continue.

|
| 5. |
Make sure Current and Recent SQL Activity is
selected and then click Filter Options.

|
| 6. |
Scroll down. Under Filter Options, select Filter
Workload Based on these Options. In the Users section, select Include only SQL statements executed by these users and enter SH
in the Users field. Scroll up to the top of the page.

|
| 7. |
Click Next.

|
| 8. |
Select Both Indexes and Materialized
Views in the Recommendation Types section and click Next.

|
| 9. |
Enter the task name OBE<any name > under Advisor Task Information. Make sure that Standard is selected for the Schedule Type in the Scheduling Options section. Click Next.

|
| 10. |
Click Submit.

|
Back to Topic List
Now, you can look at the results and implement them if you
want. Perform the following steps:
| 1. |
Make sure that your job OBE<any name> is selected in the Results section, and click View
Result.
Note:
If you do not see the SQL Access Advisor Task you created, click Refresh. If you receive the message "No recommendations were generated because the workload was empty", you may need to restart this tutorial. There may be a timing issue depending on the memory of the machine you are using.

|
| 2. |
To see a summary of the recommendations, click Show Recommendation Action Counts.

|
| 3. |
To see the type of recommendations, click Show Statement Counts.

|
| 4. |
To see the types of statements in the workload, click Recommendations.

|
| 5. |
Click 1 in the ID column to see the recommendation details.

|
| 6. |
On this page you can customize the Object Name, Schema, and Tablespace to implement the recommendations. Scroll down and change the Schema Name for the Create Materialized View to SH and click OK.

|
| 7. |
To see the SQL Script that will be executed when you
schedule the implementation, select recommendation ID 1 and click Show SQL.

|
| 8. |
Scroll down to the bottom and you will see the statements
to create the materialized view with the change you just made. Click Done.

|
| 9. |
Click SQL Statements.

|
| 10. |
You see the SQL statements that will be improved by these recommendations. Scroll up.

|
| 11. |
Click Details.

|
| 12. |
You see the details of workload, task options and journal entries. Click Recommendations.

|
| 13. |
To implement the recommendations, click Schedule
Implementation.

|
| 14. |
Enter OBEIMPL<any name > for
the job name and click Submit.

|
| 15. |
The job has been successfully created. Click the Scheduler Job link.

|
| 16. |
Review the summary information and scroll to the bottom to check the status.

|
| 17. |
Click OK.

|
| 18. |
Click the Database Instance link to return to the Administration page.

|
| 19. |
Click Materialized Views in the Schema section.

|
| 20. |
Enter SH in the Schema field and click Go.

|
| 21. |
Note that the newly created materialized view appears
on the list. Click the Database Instance link to return to the Administration page.

|
Back to Topic List
In this tutorial, you learned how to:
 |
Use the SQL cache to get recommendations |
 |
Review and implement the recommendations |
Back to Topic List
Place
the cursor on this icon to hide all screenshots.
|