相关链接
Sets table-related information
设置表相关的信息
This procedure sets table-related information.
此过程设置与表相关的信息。
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 表示自动样本大小应该使用的算法 |
参数有default值:可以不传参,使用默认值
参数无default值:必须传参才可调用
DBMS_STATS.SET_TABLE_STATS (
ownname VARCHAR2,
tabname VARCHAR2,
partname VARCHAR2 DEFAULT NULL,
stattab VARCHAR2 DEFAULT NULL,
statid VARCHAR2 DEFAULT NULL,
numrows NUMBER DEFAULT NULL,
numblks NUMBER DEFAULT NULL,
avgrlen NUMBER DEFAULT NULL,
flags NUMBER DEFAULT NULL,
statown VARCHAR2 DEFAULT NULL,
no_invalidate BOOLEAN DEFAULT to_no_invalidate_type (
get_param('NO_INVALIDATE')),
cachedblk NUMBER DEFAULT NULL,
cachehit NUMBER DEFUALT NULL,
force BOOLEAN DEFAULT FALSE);
1.如果是命令窗口就用exec 存储过程名,举个例子:
EXEC procedure;--procedure是存储过程名
2.如果是PL/SQL窗口就用 begin 存储过程名 end; 举个例子:
begin
procedure;--procedure是存储过程名
end;
3.如果是程序中调用就用 call 存储过程名 ,举个例子:
hibernateDao.excuteSqlUpdate("{Call proc_stuInfo()}");//存储过程proc_stuInfo
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_table_stats(ownname => :ownname,
tabname => :tabname,
partname => :partname,
stattab => :stattab,
statid => :statid,
numrows => :numrows,
numblks => :numblks,
avgrlen => :avgrlen,
flags => :flags,
statown => :statown,
no_invalidate => no_invalidate,
cachedblk => :cachedblk,
cachehit => :cachehit,
force => force);
end;
Table 142-95 SET_TABLE_STATS Procedure Parameters
Ser 序号 |
Parameter 参数名称 |
Type 类型 |
Default | IO TYPE | Note 参数说明 |
Range 取值范围 |
---|---|---|---|---|---|---|
1 | ownname | VARCHAR2 | IN | name of the schema. 方案名 |
[Any Schema] | |
2 | tabname | VARCHAR2 | IN | Name of the table 此列所属的表名 |
[Any Table] | |
3 | partname | VARCHAR2 | Y | IN | Name 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 index level)。 |
NULL default [Any table partition] |
4 | stattab | VARCHAR2 | Y | IN | User 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] 指定要存储统计信息的表。 |
5 | statid | VARCHAR2 | Y | IN | Identifier (optional) to associate with these statistics within stattab (Only pertinent if stattab is not NULL )statid表明stattab这个数据集的主键,可以理解为stattab的一个分区。(只有当stattab不是NULL时设置statid才有效) |
NULLdefault 不指定分区。 [Any Statid] 指定要存储统计信息的表的分区。 |
6 | numrows | NUMBER | Y | IN | Number of rows in the table (partition) 索引(分区)中的行数 |
NULLdefault |
7 | numblks | NUMBER | Y | IN | Number of blocks the table (partition) occupies 表(分区)占用的块数 |
NULLdefault |
8 | avgrlen | NUMBER | Y | IN | Average row length for the table (partition) 表(分区)的平均行长度(没有指明但应该是字节长度) |
NULLdefault |
9 | flags | NUMBER | Y | IN | For internal Oracle use (should be left as NULL )用于内部Oracle使用(应该保留为NULL) |
NULLdefault [Any Number] |
10 | statown | VARCHAR2 | Y | IN | Schema containing stattab (if different than ownname) statown表明stattab在哪个方案(schema)下,如果statown=当前schema,则可以不指定此参数。 |
NULLdefault [Any Schema] 指定要存储统计信息的表的分区。 |
11 | 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 依赖游标失效。 |
12 | cachedblk | NUMBER | Y | IN | The average number of blocks in the buffer cache for the segment (index/table/index partition/table partition) 该段(索引/表/索引分区/表分区)的缓冲区缓存中的平均块数 |
NULLdefault |
13 | cachehit | NUMBER | Y | IN | The average cache hit ratio for the segment (index/table/index partition/table partition) 段(索引/表/索引分区/表分区)的平均缓存命中率 |
NULLdefault |
14 | force | BOOLEAN | Y | IN | Sets the values even if statistics of the index 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参数指示包在收集新的统计信息之前备份指定表中的当前统计信息。
ORA-20000
:Object does not exist or insufficient privileges
对象不存在或权限不足
ORA-20001
: Invalid input value
输入值无效
ORA-20005
: Object statistics are locked
对象统计信息被锁定
● 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 权限。
● The Optimizer uses the cached data to estimate number of cached blocks for index or statistics table access. The total cost of the operation will be combined from the I/O cost of reading not cached blocks from disk, the CPU cost of getting cached blocks from the buffer cache, and the CPU cost of processing the data.
优化器(Optimizer)使用缓存数据来预估访问 索引 / 统计表 时需要的缓存块数量。总代价(cost) 包括 【磁盘读取非缓存块的I/O成本】、【从缓冲区缓存获取缓存块的CPU成本】以及【处理数据的CPU成本】。
● Oracle maintains cachedblk
and cachehit
at all times but uses correspondent caching statistics for optimization as part of the table and index statistics only when the user calls DBMS_STATS.GATHER_[TABLE/INDEX/SCHEMA/DATABASE]_STATS
procedure for auto mode or DBMS_STATS.GATHER_SYSTEM_STATS
for manual mode. In order to prevent the user from utilizing inaccurate and unreliable data, the optimizer will compute a ‘confidence factor’ for each cachehit
and a cachedblk
for each object. If the ‘confidence factor’ for the value meets confidence criteria, this value will be used, otherwise the defaults will be used.
Oracle始终维护(20)cachedblk 和(21)cachehit,但只有当用户在自动模式下调用 DBMS_STATS.GATHER_[TABLE/INDEX/SCHEMA/DATABASE]_STATS 过程或在手动模式下调用 DBMS_STATS.GATHER_SYSTEM_STATS 时,才使用相应的缓存统计信息作为表和索引统计信息的一部分进行优化。为了防止用户使用不准确和不可靠的数据,优化器将计算每个cachehit的“置信因子”和每个对象的cachedblk。如果值的“置信因子”满足置信标准,则将使用此值,否则将使用缺省值。
● The automatic maintenance algorithm for object caching statistics assumes that there is only one major workload for the system and adjusts statistics to this workload, ignoring other “minor” workloads. If this is not the case, you must use manual mode for maintaining object caching statistics.
自动维护算法假设系统只有一个主要工作负载来进行对象的缓存统计信息,并根据这个工作负载调整统计信息,忽略其他“较小”的工作负载。如果需要调整,则必须使用手动模式来维护对象缓存统计信息。
● The object caching statistics maintenance algorithm for auto mode prevents you from using statistics in the following situations
用于自动模式的对象缓存统计信息维护算法阻止您在下列情况下使用统计信息
○ When not enough data has been analyzed, such as when an object has been recently create
当分析的数据不够时,比如最近创建了一个对象
○ When the system does not have one major workload resulting in averages not corresponding to real values.
当系统没有一个主要工作负载时,导致平均值与实际值不对应。
20/11/03
M