Currently, the optimizer of OceanBase Database implements daily automatic statistics collection through the MAINTENANCE WINDOW defined by the DBMS_SCHEDULER system package, ensuring continuous iteration and update of statistics.
MAINTENANCE WINDOW
OceanBase Database defines the MAINTENANCE WINDOW as having seven automatic statistics collection tasks from Monday to Sunday. The tasks start at 22:00 from Monday to Friday, with a maximum collection duration of 4 hours. On Saturday and Sunday, they start at 06:00, with a maximum collection duration of 20 hours, as shown in the following table.
Maintenance Window Name |
Start Time/Frequency |
Maximum Collection Duration |
|---|---|---|
| MONDAY_WINDOW | 22:00/per week | 4 hours |
| TUESDAY_WINDOW | 22:00/per week | 4 hours |
| WEDNESDAY_WINDOW | 22:00/per week | 4 hours |
| THURSDAY_WINDOW | 22:00/per week | 4 hours |
| FRIDAY_WINDOW | 22:00/per week | 4 hours |
| SATURDAY_WINDOW | 6:00/per week | 20 hours |
| SUNDAY_WINDOW | 6:00/per week | 20 hours |
Query MAINTENANCE WINDOW information
In OceanBase Database, the MAINTENANCE WINDOW is implemented based on the DBMS_SCHEDULER system package. Therefore, you can also query the related views of the DBMS_SCHEDULER system package to obtain information about the MAINTENANCE WINDOW.
Mode |
View Name |
Description |
|---|---|---|
| Oracle-compatible mode | DBA_SCHEDULER_JOBS | Query job information |
| Oracle-compatible mode | sys.ALL_VIRTUAL_TENANT_SCHEDULER_JOB_REAL_AGENT | Proxy Table for Querying Job Information |
| MySQL-compatible mode | oceanbase.DBA_SCHEDULER_JOBS | Query job information |
Set MAINTENANCE WINDOW attributes
In OceanBase Database, the attribute settings for the MAINTENANCE WINDOW are also implemented through the DBMS_SCHEDULER system package. The currently supported attribute setting syntax is as follows:
Disable/enable automatic statistics task collection:
DBMS_SCHEDULER.DISABLE($window_name); DBMS_SCHEDULER.ENABLE($window_name);Example 1: Disable automatic statistics collection on Monday
CALL DBMS_SCHEDULER.DISABLE('MONDAY_WINDOW');Example 2: Enable automatic statistics collection on Monday
CALL DBMS_SCHEDULER.ENABLE('MONDAY_WINDOW');
Set the time for the next start of the statistics task:
DBMS_SCHEDULER.SET_ATTRIBUTE($window_name, 'NEXT_DATE', $next_time);Example: Set the start time for automatic statistics collection on Monday to 20:00.
CALL DBMS_SCHEDULER.SET_ATTRIBUTE('MONDAY_WINDOW', 'NEXT_DATE', '2022-09-12 20:00:00');
DML STATS
DML STATS records the number of insert, delete, and update operations performed on a table.
The DML STATS of a table play a crucial role in automatic statistics collection, as they determine whether statistics collection is needed again for that table. Table data in the database is not updated daily. Therefore, for tables with no data changes or where data changes are within expected ranges, there is no need to collect statistics again, which improves the execution efficiency of automatic statistics collection tasks.
The following table lists the related views and tables that support querying DML STATS information in Oracle and MySQL-compatible modes.
Mode |
View name |
Description |
|---|---|---|
| Oracle-compatible mode | GV$DML_STATS、V$DML_STATS | Query DML STATS of tables recorded in a virtual table |
| Oracle-compatible mode | sys.ALL_VIRTUAL_MONITOR_MODIFIED_REAL_AGENT | Query DML STATS of a table in a proxy table |
| Oracle-compatible mode | ALL_TAB_MODIFICATIONS、DBA_TAB_MODIFICATIONS、USER_TAB_MODIFICATIONS | Query all DML STATS in a table |
| MySQL-compatible mode | oceanbase.GV$DML_STATS、oceanbase.V$DML_STATS | Query DML STATS of Tables Recorded in Virtual Tables |
| MySQL-compatible mode | oceanbase.DBA_TAB_MODIFICATIONS | Query all DML STATS in a table |
Automatic statistics collection strategy
In OceanBase Database, a table's statistics are considered expired if the cumulative number of rows affected by insertions, deletions, or modifications since the last statistics collection exceeds a set threshold. The default threshold is 10% of the total table rows and can be adjusted via Prefs. For more information, see Collection strategy parameter (Prefs) management function.
The automatic statistics collection strategies of the OceanBase Database optimizer are as follows:
Automatic collection strategy for system tables and non-partitioned user tables:
If a table has no
GLOBAL-level statistics, it is automatically collected.If a table has
GLOBAL-level statistics but they have expired, they are automatically collected.
Otherwise, the OceanBase Database optimizer does not automatically collect statistics.
Automatic collection strategy for partitioned user tables in OceanBase Database:
If a table has no statistics at all, all statistics are automatically collected.
If a table has partition-level statistics but no
GLOBAL-level statistics, statistics are automatically collected incrementally.If a table has
GLOBAL-level statistics but they have expired, all statistics are automatically collected.If a table has
GLOBAL-level statistics that are not all expired, only some partition statistics are expired, the expired partition statistics are automatically collected, and theGLOBAL-level statistics are inferred incrementally.
For more information about the statistics collection and update strategy for partitioned tables, as well as detailed examples, see Statistics collection and update strategy for partitioned tables.
