发布于:2021-02-21 00:00:33
0
495
0
调用DBMS_STATS包的自动优化器统计信息收集作业在预定义的维护窗口中运行,这些维护窗口每天打开一次,在此期间执行各种作业,包括收集统计信息。
对于volatile表,在连续两次执行此类自动统计信息收集作业之间,统计信息可能会过时。过时统计信息的存在可能会导致性能问题,因为优化器正在选择次优的执行计划。
在oracle19c中引入的新特性称为高频自动优化器统计数据收集(High Frequency Automatic Optimizer Statistics Collection),它补充了标准的自动统计数据收集作业。
默认情况下,高频统计信息收集每15分钟进行一次,因此,即使对于那些数据不断变化的表,也不太可能有过时的统计信息。
所述DBMS_STATS.SET_GLOBAL_PREFS程序用于启用和禁用高频统计收集任务以及改变执行间隔(默认值15分钟)和最大运行时间(60分钟)。
让我们看一个使用这个新的oracle19c特性的例子。
我们可以看到MYOBJECTS_19C表的统计信息是过时的,现在我们使用DBMS_STATS.SET_GLOBAL_PREFS过程启用每隔5分钟收集一次高频统计信息。
SQL> select stale_stats from user_tab_statistics where table_name='MYOBJECTS_19C';
STALE_S
-------
YES
SQL> EXEC DBMS_STATS.SET_GLOBAL_PREFS('AUTO_TASK_STATUS','ON');
PL/SQL procedure successfully completed.
SQL> EXEC DBMS_STATS.SET_GLOBAL_PREFS('AUTO_TASK_INTERVAL','300');
PL/SQL procedure successfully completed.
我们可以查询DBA_AUTO_STAT_EXECUTIONS数据字典表以获取有关每日标准自动统计执行作业的状态的信息。我们可以看到该工作在工作日的夜间维护时段中运行,而在晚上的维护时段运行中这一天。
SQL> SELECT OPID, ORIGIN, STATUS, TO_CHAR(START_TIME, 'DD/MM HH24:MI:SS' ) AS BEGIN_TIME,
TO_CHAR(END_TIME, 'DD/MM HH24:MI:SS') AS END_TIME, COMPLETED, FAILED,
TIMED_OUT AS TIMEOUT, IN_PROGRESS AS INPROG
FROM DBA_AUTO_STAT_EXECUTIONS
ORDER BY OPID;
OPID ORIGIN STATUS BEGIN_TIME END_TIME COMPLETED FAILED TIMEOUT INPROG
----- -------------------- ----------- -------------- -------------- --------- ------ ------- ------
659 AUTO_TASK COMPLETED 10/06 23:00:50 10/06 23:02:02 569 2 0 0
681 AUTO_TASK COMPLETED 11/06 00:10:58 11/06 00:11:20 296 2 0 0
684 AUTO_TASK COMPLETED 11/06 00:20:59 11/06 00:21:11 62 2 0 0
687 AUTO_TASK COMPLETED 11/06 00:31:00 11/06 00:31:04 43 2 0 0
690 AUTO_TASK COMPLETED 11/06 00:41:01 11/06 00:41:05 46 2 0 0
693 AUTO_TASK COMPLETED 11/06 00:51:02 11/06 00:51:05 44 2 0 0
699 AUTO_TASK COMPLETED 11/06 01:01:04 11/06 01:01:12 148 2 0 0
702 AUTO_TASK COMPLETED 11/06 01:11:05 11/06 01:11:08 43 2 0 0
705 AUTO_TASK COMPLETED 11/06 01:21:06 11/06 01:21:08 31 2 0 0
708 AUTO_TASK COMPLETED 11/06 01:31:07 11/06 01:31:10 39 2 0 0
711 AUTO_TASK COMPLETED 11/06 01:41:09 11/06 01:41:12 39 2 0 0
1045 AUTO_TASK COMPLETED 12/06 22:00:09 12/06 22:02:47 644 1 0 0
1085 AUTO_TASK COMPLETED 13/06 22:00:03 13/06 22:02:09 467 1 0 0
1125 AUTO_TASK COMPLETED 15/06 08:23:50 15/06 08:25:46 362 1 0 0
14 rows selected.
如果再次运行同一查询,大约5分钟后,我们可以运行另一个“自动任务”统计作业,这就是高频统计信息收集作业。
我们还可以看到,以前将统计数据报告为过时的表现在收集了新的统计数据。
SQL> SELECT OPID, ORIGIN, STATUS, TO_CHAR(START_TIME, 'DD/MM HH24:MI:SS' ) AS BEGIN_TIME,
TO_CHAR(END_TIME, 'DD/MM HH24:MI:SS') AS END_TIME, COMPLETED, FAILED,
TIMED_OUT AS TIMEOUT, IN_PROGRESS AS INPROG
FROM DBA_AUTO_STAT_EXECUTIONS
ORDER BY OPID;
OPID ORIGIN STATUS BEGIN_TIME END_TIME COMPLETED FAILED TIMEOUT INPROG
----- -------------------- ----------- -------------- -------------- --------- ------ ------- ------
659 AUTO_TASK COMPLETED 10/06 23:00:50 10/06 23:02:02 569 2 0 0
681 AUTO_TASK COMPLETED 11/06 00:10:58 11/06 00:11:20 296 2 0 0
684 AUTO_TASK COMPLETED 11/06 00:20:59 11/06 00:21:11 62 2 0 0
687 AUTO_TASK COMPLETED 11/06 00:31:00 11/06 00:31:04 43 2 0 0
690 AUTO_TASK COMPLETED 11/06 00:41:01 11/06 00:41:05 46 2 0 0
693 AUTO_TASK COMPLETED 11/06 00:51:02 11/06 00:51:05 44 2 0 0
699 AUTO_TASK COMPLETED 11/06 01:01:04 11/06 01:01:12 148 2 0 0
702 AUTO_TASK COMPLETED 11/06 01:11:05 11/06 01:11:08 43 2 0 0
705 AUTO_TASK COMPLETED 11/06 01:21:06 11/06 01:21:08 31 2 0 0
708 AUTO_TASK COMPLETED 11/06 01:31:07 11/06 01:31:10 39 2 0 0
711 AUTO_TASK COMPLETED 11/06 01:41:09 11/06 01:41:12 39 2 0 0
1045 AUTO_TASK COMPLETED 12/06 22:00:09 12/06 22:02:47 644 1 0 0
1085 AUTO_TASK COMPLETED 13/06 22:00:03 13/06 22:02:09 467 1 0 0
1125 AUTO_TASK COMPLETED 15/06 08:23:50 15/06 08:25:46 362 1 0 0
1287 AUTO_TASK IN PROGRESS 15/06 17:38:25 15/06 17:38:25 83 0 0 1
15 rows selected.
SQL>
SQL> select stale_stats from user_tab_statistics where table_name='MYOBJECTS_19C';
STALE_S
-------
NO
作者介绍