`

SQL Access Advisor的使用

 
阅读更多

环境:

OS:Red Hat Linux As 5

DB:10.2.0.4

SQL Access Advisor是伴随着10G出现的一个优化工具,提供对表分区,物化视图,索引,物化视图日志优化建议.下边通过对单个SQL的执行,查看Oracle给出的建议.

1.建表并生成测试数据

SQL> connect scott/scott
Connected.
SQL> drop table tb_test;
SQL> create table tb_test(id number not null,name varchar2(30));
Table created.
SQL> create index idx_tb_test on tb_test(id);
Index created.
SQL> declare
begin
  for i in 1 .. 100000 loop
    insert into tb_test values (i, 'test');
    commit;
  end loop;
end;

2.分析表

connect / as sysdba

begin
  dbms_stats.gather_table_stats(ownname => 'SCOTT', tabname => 'TB_TEST',cascade => true);
end;


3.使用dbms_advisor.quick_tune生成优化建议

connect / as sysdba

declare
  l_task_name VARCHAR2(255);
  l_sql_stmt  VARCHAR2(4000);
begin
  l_sql_stmt  := 'select /*+ full(t) */ * from scott.tb_test t where t.id = :1';
  l_task_name := 'MY_FULL_ACCESS_TEST';
  DBMS_ADVISOR.QUICK_TUNE(DBMS_ADVISOR.SQLACCESS_ADVISOR,
                          l_task_name,
                          l_sql_stmt);
  exception when others then dbms_output.put_line(sqlerrm);                    
end;

我们这里造一个走全表扫描的索引,很明显走索引才是正确的,这里的目的主要是看oracle会给出什么样的建议.

 

4.查看优化建议

SQL> set serveroutput on;
SQL> set long 999999999;
SQL> begin
       show_recm('MY_FULL_ACCESS_TEST');
     end;

=========================================
Task_name = MY_FULL_ACCESS_TEST
Action ID: 1
Command : RETAIN INDEX
Attr1 (name)      : "SCOTT"."IDX_TB_TEST_N1"
Attr2 (tablespace):
Attr3             : "SCOTT"."TB_TEST"
Attr4             : BTREE
Attr5             :
----------------------------------------
=========END RECOMMENDATIONS============

PL/SQL procedure successfully completed.

从以上输出可以看出oracle给出的建议是走索引.

show_recm过程如下:

CREATE OR REPLACE PROCEDURE show_recm (in_task_name IN VARCHAR2) IS
CURSOR curs IS
  SELECT DISTINCT action_id, command, attr1, attr2, attr3, attr4
  FROM dba_advisor_actions
  WHERE task_name = in_task_name
  ORDER BY action_id;
  v_action        number;
  v_command     VARCHAR2(32);
  v_attr1       VARCHAR2(4000);
  v_attr2       VARCHAR2(4000);
  v_attr3       VARCHAR2(4000);
  v_attr4       VARCHAR2(4000);
  v_attr5       VARCHAR2(4000);
BEGIN
  OPEN curs;
  DBMS_OUTPUT.PUT_LINE('=========================================');
  DBMS_OUTPUT.PUT_LINE('Task_name = ' || in_task_name);
  LOOP
     FETCH curs INTO
       v_action, v_command, v_attr1, v_attr2, v_attr3, v_attr4 ;
   EXIT when curs%NOTFOUND;
   DBMS_OUTPUT.PUT_LINE('Action ID: ' || v_action);
   DBMS_OUTPUT.PUT_LINE('Command : ' || v_command);
   DBMS_OUTPUT.PUT_LINE('Attr1 (name)      : ' || SUBSTR(v_attr1,1,30));
   DBMS_OUTPUT.PUT_LINE('Attr2 (tablespace): ' || SUBSTR(v_attr2,1,30));
   DBMS_OUTPUT.PUT_LINE('Attr3             : ' || SUBSTR(v_attr3,1,30));
   DBMS_OUTPUT.PUT_LINE('Attr4             : ' || v_attr4);
   DBMS_OUTPUT.PUT_LINE('Attr5             : ' || v_attr5);
   DBMS_OUTPUT.PUT_LINE('----------------------------------------');
   END LOOP;
   CLOSE curs;
   DBMS_OUTPUT.PUT_LINE('=========END RECOMMENDATIONS============');
END show_recm;

-- The End --

 

参考至:http://blog.chinaunix.net/uid-77311-id-3233477.html

如有错误,欢迎指正

邮箱:czmcj@163.com

分享到:
评论

相关推荐

    oracle 10g ocp 043解析(185题).

    SQL Access Advisor E. Automatic Database Diagnostic Monitor(ADDM) Answer: A 你发现你的数据高速缓存区(Database Buffer Cache)不够用了,可以使用 Memory Advisor 来确定其大小,自动数据库诊断监视器 ...

    oracle 11g overview

    SQL Access Advisor 获得关于基于表(而不仅仅是数据)的实际使用的最佳表设计的建议。 PL/SQL:高效的编码 在不同的事件处触发几次的触发器以及迫使相同类型的触发器排队的能力是一些新增亮点。 RMAN 探究 Data ...

    Expert.Oracle.Indexing.and.Access.Paths.2nd.epub

    Speed up the execution of important database queries by making good choices about which indexes to create. Choose correct index types for ... SQL Tuning Advisor Chapter 10. In Memory Column Store

    Expert.Oracle.Indexing.and.Access.Paths

    Speed up the execution of important database queries by making good choices about which indexes to create. Choose correct index types ...Chapter 9: SQL Tuning Advisor Chapter 10: In-Memory Column Store

    OCPOCA认证考试指南全册:Oracle Database 11g(1Z0-051,1Z0-052,1Z0-053)--详细书签版(第2/2部分)

    10.1 描述和使用SQL中的字符、数字和日期函数 348 10.1.1 定义函数 348 10.1.2 函数类型 348 10.1.3 使用大小写转换函数 349 10.1.4 使用字符操作函数 350 10.1.5 使用数字函数 353 10.1.6 使用日期 355 ...

    OCPOCA认证考试指南全册:Oracle Database 11g(1Z0-051,1Z0-052,1Z0-053)--详细书签版(第1/2部分)

    10.1 描述和使用SQL中的字符、数字和日期函数 348 10.1.1 定义函数 348 10.1.2 函数类型 348 10.1.3 使用大小写转换函数 349 10.1.4 使用字符操作函数 350 10.1.5 使用数字函数 353 10.1.6 使用日期 355 ...

    Prentice Hall - DB2 Version 8 The Official Guide.chm

    Coverage includes: <br>Simplifying management with the Configuration Advisor, HealthCenter, and Memory Visualizer <br>Integrating the enterprise via Federated Web Services and the DB2 enhanced...

    Spring中文帮助文档

    12.5.2. 使用 SqlMapClientTemplate 和 SqlMapClientDaoSupport 12.5.3. 基于原生的iBATIS API的DAO实现 12.6. JPA 12.6.1. 在Spring环境中建立JPA 12.6.2. JpaTemplate 和 JpaDaoSupport 12.6.3. 基于原生的...

    Spring API

    1.1.1. 使用场景 2. Spring 2.0和 2.5的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 新的bean作用域 2.2.2. 更简单的XML配置 2.2.3. 可扩展的XML编写 2.2.4. Annotation(注解)驱动配置 2.2.5. 在...

    Password Recovery Bundle 2014 Enterprise Edition 3.2-密码找回|重置工具

    - MS Access Password Recovery - Unlock Microsoft Office Access XP / 2003 / 2000 / 97 / 95 database. - SQL Server Password Recovery - Reset forgotten SQL Server login password for SQL Server 2000 / ...

    spring-framework-reference4.1.4

    Not Using Commons Logging ................................................................... 12 Using SLF4J ..............................................................................................

    spring-framework-reference-4.1.2

    Not Using Commons Logging ................................................................... 12 Using SLF4J ..............................................................................................

Global site tag (gtag.js) - Google Analytics