41.You have recently collected statistics on certain objects of a schema in your database. But you o

41.You have recently collected statistics on certain objects of a schema in your database. But you
observe suboptimal execution plans for the queries on these objects after two days of statistics collection.
The optimizer statistics retention period is set to its default value.
Which action would help to use the previous set of statistics on the objects?
A.Restore statistics from statistics history.
B.Reduce the optimizer statistics retention period by 2 days.
C.Set the OPTIMIZER_PENDING_STATISTICS parameter to TRUE.
D.Reduce the Automatic Workload Repository (AWR) retention period by 2 days.
答案:A
解析:题目说的是,优化器收集统计信息的周期为默认值,最近你在一个schema的object上收集了统计信息,但是发现
对于查询的执行计划不如之前的不太好,你应该怎么做
A:从统计信息历史记录中restore
B:减少统计信息的保留时间
C:设置OPTIMIZER_PENDING_STATISTICS为true
D:减少awr的保留时间
从这里可以看出应该选择A,那A是干啥的
SQL> select to_char(stats_update_time,'yyyy-mm-dd hh24:mi:ss') FROM DBA_TAB_STATS_HISTORY where owner = 'SCOTT' and table_name = 'SALES';


TO_CHAR(STATS_UPDAT
-------------------
2016-07-17 09:20:14
2016-07-15 22:00:20


SQL> select to_char(last_analyzed,'yyyy-mm-dd hh24:mi:ss') from dba_tables where table_name = 'SALES' and owner = 'SCOTT';
TO_CHAR(LAST_ANALYZ
-------------------
2016-07-17 09:20:14
SQL> exec dbms_stats.restore_table_stats('SCOTT', 'SALES', TO_DATE('2016-07-15 22:00:20', 'yyyy-mm-dd hh24:mi:ss'));


PL/SQL procedure successfully completed.
SQL> select to_char(last_analyzed,'yyyy-mm-dd hh24:mi:ss') from dba_tables where table_name = 'SALES' and owner = 'SCOTT';


TO_CHAR(LAST_ANALYZ
-------------------
--查看统计信息保存的时间
select DBMS_STATS.GET_STATS_HISTORY_RETENTION from dual; 
--这里为啥没有恢复回去
SQL> exec dbms_stats.gather_table_stats('SCOTT', 'SALES', cascade=>true);
PL/SQL procedure successfully completed.
---收集一下信息我们在来一次
SQL> select to_char(last_analyzed,'yyyy-mm-dd hh24:mi:ss') from dba_tables where table_name = 'SALES' and owner = 'SCOTT';
TO_CHAR(LAST_ANALYZ
-------------------
2016-07-17 21:20:59


SQL> select to_char(stats_update_time,'yyyy-mm-dd hh24:mi:ss') FROM DBA_TAB_STATS_HISTORY where owner = 'SCOTT' and table_name = 'SALES';
TO_CHAR(STATS_UPDAT
-------------------
2016-07-17 21:20:59 --这个是gather_table_stats
2016-07-17 09:20:14 --这个是restore_table_stats
2016-07-17 17:51:41
2016-07-15 22:00:20
--再来执行一次
SQL> exec dbms_stats.restore_table_stats('SCOTT', 'SALES', '15-JUL-16 10.00.20.846989 PM +08:00',force=>true);


PL/SQL procedure successfully completed.


SQL> select to_char(last_analyzed,'yyyy-mm-dd hh24:mi:ss') from dba_tables where table_name = 'SALES' and owner = 'SCOTT';


TO_CHAR(LAST_ANALYZ
-------------------
2016-07-17 09:16:33
--但是这里为啥显示的是这个时间就不知道了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值