设为首页 加入收藏

TOP

数据库性能优化、统计信息与对象统计信息概述收集、扩展统计信息、dbms_stats.get_prefs(五)
2014-11-24 01:33:44 来源: 作者: 【 】 浏览:26
Tags:数据库 性能 优化 统计 信息 对象 概述 收集 扩展 dbms_stats.get_prefs
mpleted

Executed in 0.593 seconds

SQL> exec dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'T',estimate_percent => 65);

PL/SQL procedure successfully completed

Executed in 0.608 seconds

SQL> set timing off;

由上述实验可知,estimate_percent 设置为null时,为全部采样,也就是100。
当将其设置为其默认值DBMS_STATS.AUTO_SAMPLE_SIZE时,收集统计信息消耗的时间与将其设置为65时相同。
鉴于本实验是在12.1的数据库中测试,所以我们基本可以断定:
在12.1中,estimate_percent的默认采样比例,大致在65%。


1.2.2.5 统计信息锁定与force选项
为预防由于统计信息不规则变化影响执行计划,我们可以选择锁定某些对象的统计信息。
oracle提供了如下锁定统计信息的过程:
LOCK_PARTITION_STATS
LOCK_SCHEMA_STATS
LOCK_TABLE_STATS
对应的,也有如下解除锁定的过程:
UNLOCK_PARTITION_STATS
UNLOCK_SCHEMA_STATS
UNLOCK_TABLE_STATS

我们以前面测试estimate_percent中创建的测试表T为例,显示表统计信息的锁定与解锁问题。

SQL> exec dbms_stats.lock_table_stats(ownname => 'SYS',tabname => 'T');

PL/SQL procedure successfully completed

SQL> desc dba_tab_statistics;
Name Type Nullable Default Comments
------------------------- ------------- -------- ------- --------------------------------------------------------------------
OWNER VARCHAR2(128) Y Owner of the object
TABLE_NAME VARCHAR2(128) Y Name of the table
PARTITION_NAME VARCHAR2(128) Y Name of the partition
PARTITION_POSITION NUMBER Y Position of the partition within table
SUBPARTITION_NAME VARCHAR2(128) Y Name of the subpartition
SUBPARTITION_POSITION NUMBER Y Position of the subpartition within partition
OBJECT_TYPE VARCHAR2(12) Y Type of the object (TABLE, PARTITION, SUBPARTITION)
NUM_ROWS NUMBER Y The number of rows in the object
BLOCKS NUMBER Y The number of used blocks in the object
EMPTY_BLOCKS NUMBER Y The number of empty blocks in the object
AVG_SPACE NUMBER Y The average available free space in the object
CHAIN_CNT NUMBER Y The number of chained rows in the object
AVG_ROW_LEN NUMBER Y The average row length, including row overhead
AVG_SPACE_FREELIST_BLOCKS NUMBER Y The average freespace of all blocks on a freelist
NUM_FREELIST_BLOCKS NUMBER Y The number of blocks on the freelist
AVG_CACHED_BLOCKS NUMBER Y Average number of blocks in buffer cache
AVG_CACHE_HIT_RATIO NUMBER Y Average cache hit ratio for the object
SAMPLE_SIZE NUMBER Y The sample size used in analyzing this table
LAST_ANALYZED DATE Y The date of the most recent time this table was analyzed
GLOBAL_STATS VARCHAR2(3) Y Are the statistics calculated without merging underlying partitions
USER_STATS VARCHAR2(3) Y Were the statistics entered directly by the user
STATTYPE_LOCKED VARCHAR2(5) Y type of statistics lock
STALE_STATS VARCHAR2(3) Y Whether statistics for the object is stale or not
SCOPE VARCHAR2(7) Y whether statistics for the object is shared or session

SQL> col OWNER for a20
SQL> col TABLE_NAME for a20
SQL> col STATTYPE_LOCKED for a20
SQL> select OWNER,TABLE_NAME,STATTYPE_LOCKED from dba_tab_statistics where TABLE_NAME='T';

OWNER TABLE_NAME STATTYPE_LOCKED
-------------------- -------------------- --------------------
SYS T ALL

在T表的统计信息被锁定之后,是否可以重新搜集该表的统计信息呢?
SQL> exec dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'T');

begin dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'T'); end;

ORA-20005: object statistics are locked (stattype = ALL)
ORA-06512: 在 "SYS.DBMS_STATS", line 33859
ORA-06512: 在 line 2

显示该统计信息已经被锁定。
我们此处可以用force参数强制收集。

SQL> exec dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'T',force => true);

PL/SQL procedure successfully completed

强制收集之后,该统计信息依然处于锁定状态:

SQL> select OWNER,TABLE_NAME,STATTYPE_LOCKED f

首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇全面解析Oracle数据库中管理实例.. 下一篇带你深入了解管理Oracle实例的相..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: