2.1.1.2_10 Oracle数据字典 142-42 SYS.DBMS_STATS.gather_index_stats

目录

  • 一、Summary of GATHER_INDEX_STATS Procedure
  • 二、GATHER_INDEX_STATS Procedure
  • 三、Constants 常量
  • 四、GATHER_INDEX_STATS
    • 4.1 Syntax 语法
    • 4.2 执行存储过程
    • 4.3 Parameters 参数
    • 4.4 Exceptions 异常
    • 4.5 Usage Notes 使用方式


相关链接

  • 【官】142-42 DBMS_STATS.GATHER_INDEX_STATS
  • 1.Excel目录
  • 2.如何找到Oralce存储过程——官方文档
  • 3. Oracle执行计划之2_统计信息(Statistic)
    • 3.1 Oralce 收集统计信息方式1_SYS.DBMS_STATS
      • 3.1.1 Oracle SYS.DBMS_STATS存储过程整理
      • 3.1.2 Oracle SYS.DBMS_STATS 传入参数整理
    • 3.2. Oralce收集统计信息方式2_Analyze
  • 4. 142-10 SYS.DBMS_STATS.delete_column_stats
  • 5. 142-12 SYS.DBMS_STATS.delete_database_stats
  • 6. 142-15 SYS.DBMS_STATS.delete_index_stats
  • 7. 142-18 SYS.DBMS_STATS.delete_schema_stats
  • 8. 142-21 SYS.DBMS_STATS.delete_table_stats
  • 9. 142-39 SYS.DBMS_STATS.gather_database_stats
  • 10. 142-42 SYS.DBMS_STATS.gather_index_stats(本文)
  • 11. 142-43 SYS.DBMS_STATS.gather_schema_stats
  • 12. 142-45 SYS.DBMS_STATS.gather_table_stats
  • 13. 142-87 SYS.DBMS_STATS.set_column_stats
  • 14. 142-90 SYS.DBMS_STATS.set_index_stats
  • 15. 142-95 SYS.DBMS_STATS.set_table_stats

一、Summary of GATHER_INDEX_STATS Procedure

Gathers index statistics
收集索引统计信息


二、GATHER_INDEX_STATS Procedure

This procedure gathers index statistics. It attempts to parallelize as much of the work as possible. Restrictions are described in the individual parameters. This operation will not parallelize with certain types of indexes, including cluster indexes, domain indexes, and bitmap join indexes. The granularity and no_invalidate arguments are not relevant to these types of indexes.
此过程收集索引统计信息。
此操作不会与某些类型的索引并行,包括集群索引、域索引和位图连接索引。
granularity 和 no_invalidate 参数与这些类型索引无关。


三、Constants 常量

The DBMS_STATS package uses the constants shown in Table 142-1:
Table 142-1 DBMS_STATS Constants

Name
名称
Type
类型
Value
Description
描述
AUTO_CASCADE BOOLEAN NULL Lets Oracle decide whether to collect statistics for indexes or not
让Oracle决定是否收集索引的统计信息
AUTO_DEGREE NUMBER 32768 Lets Oracle select the degree of parallelism based on size of the object, number of CPUs and initialization parameters. For definition of default parallel degree, see “Degree of Parallelism” in Oracle Database VLDB and Partitioning Guide.
让Oracle根据对象的大小、cpu的数量和初始化参数选择并行度。有关默认并行度的定义,请参阅Oracle数据库VLDB和分区指南中的"并行度"。
AUTO_INVALIDATE BOOLEAN NULL Lets Oracle decide when to invalidate dependent cursors
让Oracle决定何时使依赖游标失效
AUTO_SIMPLESIZE NUMBER 0 Indicates that auto-sample size algorithms should be used
表示自动样本大小应该使用的算法

四、GATHER_INDEX_STATS

4.1 Syntax 语法

参数有default值:可以不传参,使用默认值
参数无default值:必须传参才可调用

DBMS_STATS.GATHER_INDEX_STATS (
   ownname          VARCHAR2, 
   indname          VARCHAR2, 
   partname         VARCHAR2 DEFAULT NULL,
   estimate_percent NUMBER   DEFAULT to_estimate_percent_type 
                                                (GET_PARAM('ESTIMATE_PERCENT')),
   stattab          VARCHAR2 DEFAULT NULL, 
   statid           VARCHAR2 DEFAULT NULL,
   statown          VARCHAR2 DEFAULT NULL,
   degree           NUMBER   DEFAULT to_degree_type(get_param('DEGREE')),
   granularity      VARCHAR2 DEFAULT GET_PARAM('GRANULARITY'),
   no_invalidate    BOOLEAN  DEFAULT to_no_invalidate_type 
                                               (GET_PARAM('NO_INVALIDATE')),
   force            BOOLEAN DEFAULT FALSE);

4.2 执行存储过程

1.如果是命令窗口就用exec 存储过程名,举个例子:

EXEC  procedure;--procedure是存储过程名

2.如果是PL/SQL窗口就用 begin 存储过程名 end; 举个例子:

begin
  procedure;--procedure是存储过程名
end;

3.如果是程序中调用就用 call 存储过程名 ,举个例子:

hibernateDao.excuteSqlUpdate("{Call proc_stuInfo()}");//存储过程proc_stuInfo
  • plsql测试语句
declare
  -- Boolean parameters are translated from/to integers: 
  -- 0/1/null <--> false/true/null 
  no_invalidate boolean := sys.diutil.int_to_bool(:no_invalidate);
  force boolean := sys.diutil.int_to_bool(:force);
begin
  -- Call the procedure
  sys.dbms_stats.gather_index_stats(ownname => :ownname,
                                    indname => :indname,
                                    partname => :partname,
                                    estimate_percent => :estimate_percent,
                                    stattab => :stattab,
                                    statid => :statid,
                                    statown => :statown,
                                    degree => :degree,
                                    granularity => :granularity,
                                    no_invalidate => no_invalidate,
                                    force => force);
end;

4.3 Parameters 参数

Table 142-42 GATHER_INDEX_STATS Procedure Parameters

Ser
序号
Parameter
参数名称
Type
类型
Default IN / OUT Note
参数说明
Range
取值范围
1 ownname VARCHAR2 IN Schema of index to analyze
要分析的案名
[Any Schema]
2 indname VARCHAR2 IN Name of the index
索引名
[Any Index]
3 partname VARCHAR2 Y IN Name of partition
索引分区名称
NULL default
[Any index partition]
4 estimate_percent NUMBER Y IN Percentage of rows to estimate (NULL means compute). The valid range is [0.000001,100]. Use the constant DBMS_STATS.AUTO_SAMPLE_SIZE to have Oracle determine the appropriate sample size for good statistics. This is the default.The default value can be changed using the SET_DATABASE_PREFS Procedure, SET_GLOBAL_PREFS Procedure, SET_SCHEMA_PREFS Procedure and SET_TABLE_PREFS Procedure.
这个参数是一个百分比值,它告诉分析包需要使用表中数据的多大比例来做分析。
理论上来讲,采样的数据越多,得到的信息就越接近于实际,CBO做出的执行计划就越优化,但是,采样越多,消耗的系统资源必然越多。 对系统的影响也越大。 所以对于这个值的设置,要根据业务情况来。 如果数据的直方图分布比较均匀,就可以使用默认值:AUTO_SAMPLE_SIZE,即让Oracle 自己来判断采样的比例。有时,特别是对于批量加载的表,我们可以预估表中的数据量,可以人工地设置一个合理的值。 一般,对于一个有1000万数据的表分区,可以把这个参数设置为0.000001。
DBMS_STATS.
AUTO_SAMPLE_SIZE
default
  默认值(取Oracle常量)。由oracle决定最佳取采样值,默认值可通过左侧介绍的四个存储过程进行修改。统计数据质量越好,CBO做出的决定越好。
NULL
  全部分析,不采样。
5 stattab VARCHAR2 Y IN User statistics table identifier describing where to save the current statistics
存储统计信息的目标表名。指定从哪个统计表(stattab)中删除统计信息,如果stattab为NULL,则从字典中删除统计信息。
NULLdefault
  如果指定参数为NULL,统计信息将直接更新到数据字典。
[Any Stattab]
  指定要存储统计信息的表。
6 statid VARCHAR2 Y IN Identifier (optional) to associate with these statistics within stattab
statid表明stattab这个数据集的主键,可以理解为stattab的一个分区。
NULLdefault
  不指定分区。
[Any Statid]
  指定要存储统计信息的表的分区。
7 statown VARCHAR2 Y IN Schema containing stattab (if different than ownname)
statown表明stattab在哪个方案下,如果statown=ownname,则可以不指定此参数。
NULLdefault
[Any Schema]
  指定要存储统计信息的方案。
8 degree NUMBER Y IN Degree of parallelism. The default for degree is NULL. The default value can be changed using the SET_DATABASE_PREFS Procedure, SET_GLOBAL_PREFS Procedure, SET_SCHEMA_PREFS Procedure and SET_TABLE_PREFS Procedure. NULL means use the table default value specified by the DEGREE clause in the CREATE TABLE or ALTER TABLE statement. Use the constant DBMS_STATS.DEFAULT_DEGREE to specify the default value based on the initialization parameters. The AUTO_DEGREE value determines the degree of parallelism automatically. This is between 1 (serial execution) and DEFAULT_DEGREE (the system default value based on number of CPUs and initialization parameters) according to the size of the object. When using DEGREE=>NULL, DEGREE=>n, or DEGREE=>DBMS_STATS.DEFAULT_DEGREE, the current implementation of DBMS_STATS may use serial execution if the size of the object does not warrant parallel execution.
决定并行度(线程数),默认值为NULL
√ 根据业务情况选择,业务闲时可设置为-1
√ 一般来说,degree值越大执行越快,如果服务器主机只有一个CPU,并行进程可能会争用CPU,从而导致实际性能可能会下降。
√ degree一般不超过10就可以了,过大会导致任务卡死,根据实际情况选择
DBMS_STATS.
DEFAULT_DEGREE
default
  此值为默认值(取Oracle常量)。由oracle决定并行度,默认值可通过左侧介绍的四个存储过程进行修改。
  根据对象的大小,degree值介于1(串行)和DEFAULT_DEGREE(基于CPU数量和初始化参数系统默认值)之间。
NULL
  表示使用CREATE table或ALTER table语句中的DEGREE子句指定的表并行度默认值。《Oracle并行处理》
正整数
  容忍范围内,值越大运行时间越短。但值过大会抢占数据库资源,甚至任务卡死,根据实际情况选择。
9 granularity
《granularity的实验》
《range分区以及子分区》
VARCHAR2 Y IN Granularity of statistics to collect (only pertinent if the table is partitioned).
- ALL : Gathers all (subpartition, partition, and global) statistics
- AUTO :Determines the granularity based on the partitioning type. This is the default value.
- DEFAULT :Gathers global and partition-level statistics. This option is obsolete, and while currently supported, it is included in the documentation for legacy reasons only. You should use the ‘GLOBAL AND PARTITION’ for this functionality. Note that the default value is now ‘AUTO’.
- GLOBAL :Gathers global statistics
- GLOBAL AND PARTITION : Gathers the global and partition level statistics. No subpartition level statistics are gathered even if it is a composite partitioned object.
- PARTITION :Gathers partition-level statistics
- SUBPARTITION :Gathers subpartition-level statistics
决定统计数据的粒度,表分区时此参数才有效,默认值为AUTO
√ 理想情况下,对表的全局,分区,子分区都做分析,这样才能得到最充足的数据;
√ 通常来讲需要分区的表数据量较大,如果每增加一个分区都需要做一次全局分析的话,会消耗极大的系统资源;但是如果只对新加入的分区进行分析而不做全局分析,Oracle 在全局范围内的信息就会不准确,导致CBO 生成错误的执行计划
ALL
  收集统计数据范围有:全局级别(global),分区级别(partition),子分区级别(subpartition)
AUTOdefault
  根据分区类型确定粒度。这是默认值。
DEFAULT
  收集全局级别(global)和分区级别(partition)的统计信息。这个选项已经过时了,虽然目前受到支持,但仅由于遗留原因才将其包含在文档中。您应该使用GLOBAL AND PARTITION来实现此功能。注意,默认值现在是AUTO
GLOBAL
  收集全局级别(global)统计数据。
GLOBAL AND PARTITION
  收集全局级别(global)和分区级别(partition)的统计信息。即使是复合分区对象,也不会收集子分区级别(subpartition)的统计信息。
PARTITION
  收集分区级别(partition)的统计信息。
SUBPARTITION
  收集子分区级别(subpartition)的统计信息。
10 no_invalidate BOOLEAN Y IN Does not invalidate the dependent cursors if set to TRUE. The procedure invalidates the dependent cursors immediately if set to FALSE. Use DBMS_STATS.AUTO_INVALIDATE. to have Oracle decide when to invalidate dependent cursors. This is the default. The default can be changed using the SET_DATABASE_PREFS Procedure, SET_GLOBAL_PREFS Procedure, SET_SCHEMA_PREFS Procedure and SET_TABLE_PREFS Procedure. DBMS_STATS.AUTO_INVALIDATEdefault
  默认值(取Oracle常量)。让Oracle决定何时使依赖游标失效。
TRUE
  依赖游标有效。
FALSE
  依赖游标失效。
11 force BOOLEAN Y IN Gather statistics on object even if it is locked
当这个参数的值为TRUE时,即使锁表也会强制收集索引统计信息。
TRUE
FALSE default

Most of the DBMS_STATS procedures include the three parameters statown, stattab, and statid. These parameters allow you to store statistics in your own tables (outside of the dictionary), which does not affect the optimizer. Therefore, you can maintain and experiment with sets of statistics.
大多数DBMS_STATS过程包括三个参数statown、stattab和statid。这些参数允许您将统计信息存储在自己的表中(在字典之外),这不会影响优化器。因此,您可以维护和试验统计数据集。
The stattab parameter specifies the name of a table in which to hold statistics, and it is assumed that it resides in the same schema as the object for which statistics are collected (unless the statown parameter is specified). You can create multiple tables with different stattab identifiers to hold separate sets of statistics.
stattab参数指定用于保存统计信息的表的名称,并且假设它与为其收集统计信息的对象驻留在同一个方案(用户)中(除非指定了statown参数)。您可以使用不同的stattab标识符创建多个表,以保存不同的统计数据集。
The statown, stattab, and statid parameters instruct the package to back up current statistics in the specified table before gathering new statistics.
statown、stattab和statid参数指示包在收集新的统计信息之前备份指定表中的当前统计信息。


4.4 Exceptions 异常

ORA-20000: Index does not exist or insufficient privileges
      索引不存在或权限不足
ORA-20001: Bad input value
      输入参数错误


4.5 Usage Notes 使用方式

To invoke this procedure you must be owner of the table, or you need the ANALYZE ANY privilege. For objects owned by SYS, you need to be either the owner of the table, or you need the ANALYZE ANY DICTIONARY privilege or the SYSDBA privilege.
调用这个过程,你必须是表的所有者,或 ANALYZE ANY 权限。
对于SYS拥有的对象,你需要是表的所有者,或 ANALYZE ANY DICTIONARY 权限或 SYSDBA 权限。


20/10/27

M

你可能感兴趣的:(#,2.1.1,Oracle数据字典,oracle,数据库,dba)