【DB笔试面试632】在Oracle中,如何锁住统计信息?
作者:互联网
在Oracle中,如何锁住统计信息?
♣ 答案部分
Oracle会自动收集表的统计信息,大部分情况下,这种行为是有利的。当不需要对某个表做收集的时候,可以采用锁定统计信息的方法,把不需要收集的表排除在外,这样可以使得此表上的统计信息不变,如下所示:
1EXEC DBMS_STATS.LOCK_TABLE_STATS(); --表 2EXEC DBMS_STATS.LOCK_PARTITION_STATS(); --分区表 3EXEC DBMS_STATS.LOCK_SCHEMA_STATS(); --锁定用户统计信息 4EXEC DBMS_STATS.UNLOCK_SCHEMA_STATS();--解锁用户统计信息
如果在锁定条件下收集统计信息,那么会出现如下报错:
1ERROR at line 1: 2ORA-20005: object statistics are locked (stattype = ALL) 3ORA-06512: at "SYS.DBMS_STATS", line 20337 4ORA-06512: at "SYS.DBMS_STATS", line 20360 5ORA-06512: at line 1
可以使用如下的SQL查询到统计信息被锁的表或索引:
1SELECT D.OWNER, 2 D.INDEX_NAME, 3 D.TABLE_OWNER, 4 D.TABLE_NAME, 5 D.PARTITION_NAME, 6 D.SUBPARTITION_NAME, 7 D.OBJECT_TYPE 8 FROM DBA_IND_STATISTICS D 9 WHERE STATTYPE_LOCKED = 'ALL' 10UNION ALL 11SELECT '', 12 '', 13 D.OWNER, 14 D.TABLE_NAME, 15 D.PARTITION_NAME, 16 D.SUBPARTITION_NAME, 17 D.OBJECT_TYPE 18 FROM DBA_TAB_STATISTICS D 19 WHERE STATTYPE_LOCKED = 'ALL' ;
真题1、You have statistics collected for some selected tables. Your requirement is that the statistics for the tables and all dependent indexes must not be overwritten by further statistics collection until a certain point of time. How would you achieve this?
A、Lock statistics for the tables.
B、Change STALE_PERCENT to zero for the tables.
C、Set the TIMED_ST A TISTICS parameter to TRUE.
D、Set the ST ATISTICS_LEVEL parameter to BASIC.
E、Set the OPTIMIZER_USE_PENDING parameter statistics to TRUE.
答案:A。
若要保持统计信息不被覆盖,则必须利用DBMS_STATS包将统计信息锁住。
标签:632,statistics,STATS,NAME,DB,DBMS,信息,Oracle,统计 来源: https://blog.51cto.com/lhrbest/2708357