2.1.1.2_13 Oracle数据字典 142-87 SYS.DBMS_STATS.set_column_stats


相关链接


一、Summary of SET_COLUMN_STATS Procedure

Sets column-related information
设置与列相关的信息


二、SET_COLUMN_STATS Procedure

This procedure sets column-related information. In the version of this procedure that deals with user-defined statistics, the statistics type specified is the type to store in the dictionary, in addition to the actual user-defined statistics. If this statistics type is NULL, the statistics type associated with the index or column is stored.
此过程设置与列相关的信息。


三、Constants 常量

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

Name
名称
Type
类型
Value
Description
描述
AUTO_CASCADEBOOLEANNULLLets Oracle decide whether to collect statistics for indexes or not
让Oracle决定是否收集索引的统计信息
AUTO_DEGREENUMBER32768Lets 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_INVALIDATEBOOLEANNULLLets Oracle decide when to invalidate dependent cursors
让Oracle决定何时使依赖游标失效
AUTO_SIMPLESIZENUMBER0Indicates that auto-sample size algorithms should be used
表示自动样本大小应该使用的算法

四、SET_COLUMN_STATS

4.1 Syntax 语法

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

DBMS_STATS.SET_COLUMN_STATS (
   ownname       VARCHAR2, 
   tabname       VARCHAR2, 
   colname       VARCHAR2, 
   partname      VARCHAR2 DEFAULT NULL,
   stattab       VARCHAR2 DEFAULT NULL, 
   statid        VARCHAR2 DEFAULT NULL,
   distcnt       NUMBER DEFAULT NULL,
   density       NUMBER DEFAULT NULL,
   nullcnt       NUMBER DEFAULT NULL,
   srec          StatRec DEFAULT NULL,
   avgclen       NUMBER DEFAULT NULL,
   flags         NUMBER DEFAULT NULL,
   statown       VARCHAR2 DEFAULT NULL,
   no_invalidate BOOLEAN DEFAULT to_no_invalidate_type(
                                    get_param('NO_INVALIDATE')),
   force         BOOLEAN DEFAULT FALSE);

or

DBMS_STATS.SET_COLUMN_STATS (
   ownname       VARCHAR2, 
   tabname       VARCHAR2, 
   colname       VARCHAR2, 
   partname      VARCHAR2 DEFAULT NULL,
   stattab       VARCHAR2 DEFAULT NULL, 
   statid        VARCHAR2 DEFAULT NULL,
   ext_stats     RAW,
   stattypown    VARCHAR2 DEFAULT NULL, 
   stattypname   VARCHAR2 DEFAULT NULL, 
   statown       VARCHAR2 DEFAULT NULL,
   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);
  -- Non-scalar parameters require additional processing 
  srec SYS.DBMS_STATS.STATREC;
begin
  -- Call the procedure
  sys.dbms_stats.set_column_stats(ownname => :ownname,
                                  tabname => :tabname,
                                  colname => :colname,
                                  partname => :partname,
                                  stattab => :stattab,
                                  statid => :statid,
                                  distcnt => :distcnt,
                                  density => :density,
                                  nullcnt => :nullcnt,
                                  srec => srec,
                                  avgclen => :avgclen,
                                  flags => :flags,
                                  statown => :statown,
                                  no_invalidate => no_invalidate,
                                  force => force);
end;

or


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.set_column_stats(ownname => :ownname,
                                  tabname => :tabname,
                                  colname => :colname,
                                  partname => :partname,
                                  stattab => :stattab,
                                  statid => :statid,
                                  ext_stats => :ext_stats,
                                  stattypown => :stattypown,
                                  stattypname => :stattypname,
                                  statown => :statown,
                                  no_invalidate => no_invalidate,
                                  force => force);
end;

4.3 Parameters 参数

Table 142-87 SET_COLUMN_STATS Procedure Parameters

Ser
序号
Parameter
参数名称
Type
类型
DefaultIO TYPENote
参数说明
Range
取值范围
1ownnameVARCHAR2INname of the schema.
方案名
[Any Schema]
2tabnameVARCHAR2INName of the table to which this column belongs.
此列所属的表名
[Any Table]
3colnameVARCHAR2INName of the column or extension
列名或扩展名
[Any column or extension]
4partnameVARCHAR2YINName of the table partition in which to store the statistics. If the table is partitioned and partname is NULL, then the statistics are stored at the global table level.
用于存储统计信息的表分区名称。如果表是分区的,且partname=NULL,则统计信息存储在表全局级别(global level)。
NULL default
[Any table partition]
5stattabVARCHAR2YINUser statistics table identifier describing where to store the statistics. If stattab is NULL, then the statistics are stored directly in the dictionary.
存储统计信息的目标表名。
NULLdefault
  如果指定参数为NULL,统计信息将直接更新到数据字典。
[Any Stattab]
  指定要存储统计信息的表。
6statidVARCHAR2YINIdentifier (optional) to associate with these statistics within stattab (Only pertinent if stattab is not NULL)
statid表明stattab这个数据集的主键,可以理解为stattab的一个分区。(只有当stattab不是NULL时设置statid才有效)
NULLdefault
  不指定分区。
[Any Statid]
  指定要存储统计信息的表的分区。
7ext_statsRAWINUser-defined statistics
用户定义的数据
NULLdefault
8stattypownVARCHAR2YINSchema of the statistics type
统计信息类型的方案(Schema)
NULLdefault
9stattypnameVARCHAR2YINName of the statistics type
统计信息类型的名称
NULLdefault
10distcntNUMBERYINNumber of distinct values
不同值的个数
NULLdefault
[Any Number]
11densityNUMBERYINColumn density. If this value is NULL and if distcnt is not NULL, then density is derived from distcnt
列密度。如果 density=NULL 且 distcnt<>NULL ,那么 density = distcnt 。
NULLdefault
[Any Number]
12nullcntNUMBERYINNumber of NULLs
NULL值的个数
NULLdefault
[Any Number]
13srecStatRecYINStatRec structure filled in by a call to PREPARE_COLUMN_VALUES or GET_COLUMN_STATS
调用PREPARE_COLUMN_VALUES 或 GETCOLUMN_STATS 来填充StatRec结构 ?
NULLdefault
14avgclenNUMBERYINAverage length for the column (in bytes)
列的平均长度(以字节为单位)
NULLdefault
[Any Number]
15flagsNUMBERYINFor internal Oracle use (should be left as NULL)
??
NULLdefault
[Any Number]
16statownVARCHAR2YINSchema containing stattab (if different than ownname)
statown表明stattab在哪个方案(schema)下,如果statown=当前schema,则可以不指定此参数。
NULLdefault
[Any Schema]
  指定要存储统计信息的方案。
17no_invalidateBOOLEANYINDoes 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
  依赖游标失效。
18forceBOOLEANYINSets the values even if statistics of the column are 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: Object does not exist or insufficient privileges
      对象不存在或权限不足
ORA-20001: Invalid or inconsistent input values
      输入值无效或不一致
ORA-20005: Object statistics are locked
      对象统计信息被锁定


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/30

M

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`DBMS_STATS.GATHER_TABLE_STATS` 是 Oracle 数据库中一个过程(procedure),用于收集表的统计信息。它可以替代旧版的 `ANALYZE TABLE` 语句,提供更高效和更精确的统计信息收集方法。 使用 `DBMS_STATS.GATHER_TABLE_STATS` 可以收集表的各种统计信息,包括行数、块数、列的分布等。这些统计信息对于优化查询性能非常重要,因为它们可以帮助优化器生成更准确的执行计划。 以下是使用 `DBMS_STATS.GATHER_TABLE_STATS` 收集表统计信息的示例: ```sql BEGIN DBMS_STATS.GATHER_TABLE_STATS( ownname => 'schema_name', tabname => 'table_name', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR ALL COLUMNS SIZE AUTO', cascade => TRUE ); END; ``` 在上面的示例中,`schema_name` 是表所属的模式名,`table_name` 是要收集统计信息的表名。`estimate_percent` 参数控制了采样的百分比,使用 `DBMS_STATS.AUTO_SAMPLE_SIZE` 可以自动选择合适的采样大小。`method_opt` 参数指定了统计信息收集的方法和选项,'FOR ALL COLUMNS SIZE AUTO' 表示对所有列进行统计,并自动选择合适的大小。`cascade` 参数表示是否同时收集相关索引的统计信息。 需要注意的是,`DBMS_STATS.GATHER_TABLE_STATS` 还有其他可选的参数,可以根据具体需求进行设置,如 `granularity`、`degree` 等。详细的参数说明可以参考 Oracle 官方文档。 通过使用 `DBMS_STATS.GATHER_TABLE_STATS`,可以更灵活地、更高效地收集表的统计信息,并提升查询性能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值