暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 19C 为Optimizer Statistics Advisor任务生成报告

原创 Asher.HU 2021-02-04
1294


DBMS_STATS.REPORT_ADVISOR_TASK函数为Optimizer Statistics Advisor任务生成报告。

该报告包含以下部分:
  • 一般信息

    本节介绍任务名称,执行名称,创建日期和修改日期。

  • 摘要

    本节总结了调查结果和调查结果所违反的规则。

  • 发现

    每个发现部分均列出了相关规则和发现。如果顾问有建议,则描述该建议。在某些情况下,推荐也有理由。

自动的Optimizer Statistics Advisor任务的名称为AUTO_STATS_ADVISOR_TASK如果您遵循自动化的工作流程,则只需要查询自动生成的报告。

先决条件

要使用此DBMS_STATS.REPORT_ADVISOR_TASK功能生成报告,必须满足以下先决条件:

  • 要执行此子程序,您必须具有ADVISOR特权。
  • 您必须是任务的所有者。

注意:

该子程序使用调用者的权限执行。

执行此任务的结果取决于执行用户的特权:

  • SYSTEM 水平

    只有同时具有ANALYZE ANYANALYZE ANY DICTIONARY特权的用户才能在系统级规则上执行此任务。

  • 操作水平

    结果取决于以下特权:

    • 同时具有ANALYZE ANYANALYZE ANY DICTIONARY特权的用户可以执行所有统计信息操作的任务。
    • 与用户的ANALYZE ANY特权,但没有ANALYZE ANY DICTIONARY权限的用户可以执行此任务相关的任何除统计模式操作SYS
    • 与用户的ANALYZE ANY DICTIONARY特权,但没有ANALYZE ANY权限的用户可以执行此任务相关自己的架构和统计业务SYS架构。
    • ANALYZE ANY没有ANALYZE ANY DICTIONARY特权又没有特权的用户只能对与自己的架构有关的统计信息操作执行此操作。
  • 对象级别

    用户可以对具有统计信息收集特权的任何对象执行此任务。


生成Optimizer Statistics Advisor报告:

  1. 在SQL * Plus中,以具有ADVISOR特权的用户身份登录数据库
  2. 查询DBMS_STATS.REPORT_ADVISOR_TASK功能输出。

    使用以下查询,其中占位符具有以下定义:

    • tname 是任务的名称。
    • exec 是执行的名称。
    • type是输出的类型:TEXTHTML,或XML
    • sect是该报告的部分:SUMMARYFINDINGSERRORS,和ALL
    • lvl是报告的格式:BASICTYPICALALL,或SHOW_HIDDEN
    SET LINESIZE 3000
    SET LONG 500000
    SET PAGESIZE 0
    SET LONGCHUNKSIZE 100000
    
    SELECT DBMS_STATS.REPORT_ADVISOR_TASK('tname', 'exec', 'type', 'sect', 'lvl') AS REPORT
    FROM   DUAL;

    例如,要打印的报告AUTO_STATS_ADVISOR_TASK,请使用以下查询:

    SELECT DBMS_STATS.REPORT_ADVISOR_TASK('AUTO_STATS_ADVISOR_TASK',NULL,'TEXT','ALL','ALL') AS REPORT 
    FROM   DUAL;

    以下样本报告显示了四个发现:

    GENERAL INFORMATION
    -------------------------------------------------------------------------------
     Task Name	 : AUTO_STATS_ADVISOR_TASK
     Execution Name  : EXEC_136	
     Created	 : 09-05-16 02:52:34 
     Last Modified	 : 09-05-16 12:31:24 
    -------------------------------------------------------------------------------
    SUMMARY
    -------------------------------------------------------------------------------
     For execution EXEC_136 of task AUTO_STATS_ADVISOR_TASK, the Statistics Advisor
     has 4 findings. The findings are related to the following rules: 
     AVOIDSETPROCEDURES, USEDEFAULTPARAMS, USEGATHERSCHEMASTATS, NOTUSEINCREMENTAL. 
    Please refer to the finding section for detailed information.
    
    -------------------------------------------------------------------------------
    FINDINGS
    -------------------------------------------------------------------------------
     Rule Name:	    AvoidSetProcedures
     Rule Description:  Avoid Set Statistics Procedures				
     Finding:  There are 5 SET_[COLUMN|INDEX|TABLE|SYSTEM]_STATS procedures being	
               used for statistics gathering.
     Recommendation:  Do not use SET_[COLUMN|INDEX|TABLE|SYSTEM]_STATS procedures.
                      Gather statistics instead of setting them.			
     Rationale:  SET_[COLUMN|INDEX|TABLE|SYSTEM]_STATS will cause bad plans due to
                 wrong or inconsistent statistics.				   
    ----------------------------------------------------
     Rule Name:	    UseDefaultParams						
     Rule Description:  Use Default Parameters in Statistics Collection Procedures  
     Finding:  There are 367 statistics operations using nondefault parameters.	
     Recommendation:  Use default parameters for statistics operations.		
     Example:
    
     -- Gathering statistics for 'SH' schema using all default parameter values:	
     BEGIN dbms_stats.gather_schema_stats('SH'); END;				
     Rationale:  Using default parameter values for statistics gathering operations 
                 is more efficient.	
    ----------------------------------------------------
     Rule Name:	    UseGatherSchemaStats					
     Rule Description:  Use gather_schema_stats procedure
     Finding:  There are 318 uses of GATHER_TABLE_STATS.
     Recommendation:  Use GATHER_SCHEMA_STATS instead of GATHER_TABLE_STATS.	
     Example:
    
     -- Gather statistics for 'SH' schema:						
     BEGIN dbms_stats.gather_schema_stats('SH'); END;				
     Rationale:  GATHER_SCHEMA_STATS has more options available, including checking 
                 for staleness and gathering statistics concurrently. Also it is
                 more maintainable for new tables added to the schema. If you only
                 want to gather statistics for certain tables in the schema, specify
                 them in the obj_filter_list parameter of GATHER_SCHEMA_STATS.						
    ----------------------------------------------------
     Rule Name:	    NotUseIncremental
    
     Rule Description:  Statistics should not be maintained incrementally when it is not							
     Finding:  Incremental option has been turned on for 10 tables, which will not benefit 
               from using the incremental option.
     Schema:
     SH
     Objects:
     CAL_MONTH_SALES_MV    
     CAL_MONTH_SALES_MV    
     CHANNELS
     COUNTRIES   
     CUSTOMERS    
     DIMENSION_EXCEPTIONS    
     FWEEK_PSCAT_SALES_MV    
     FWEEK_PSCAT_SALES_MV    
     PRODUCTS    
     PROMOTIONS    
     SUPPLEMENTARY_DEMOGRAPHICS 
     TIMES
    
     Recommendation:  Do not use the incremental option for statistics gathering on these objects.						
     Example:									
     --
     Turn off the incremental option for 'SH.SALES':     
     dbms_stats.set_table_prefs('SH', 'SALES', 'INCREMENTAL', 'FALSE');		
     Rationale:  The overhead of using the incremental option on these tables
                 outweighs the benefit of using the incremental option.  
    

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论