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 on each day from Monday to Sunday, with a maximum collection duration of 4 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 | 22:00/per week | 4 hours |
| SUNDAY_WINDOW | 22:00/per week | 4 hours |
Note
- For OceanBase Database V4.3.5, starting from V4.3.5 BP1, the default start time and maximum collection duration for the tasks in the
SATURDAY_WINDOWandSUNDAY_WINDOWmaintenance windows have changed from default start time 6:00, maximum collection duration 20 hours to default start time 22:00, maximum collection duration 4 hours. - For OceanBase Database V4.2.5, starting from V4.2.5 BP2, the default start time and maximum collection duration for the tasks in the
SATURDAY_WINDOWandSUNDAY_WINDOWmaintenance windows have changed from default start time 6:00, maximum collection duration 20 hours to default start time 22:00, maximum collection duration 4 hours.
Query MAINTENANCE WINDOW information
Currently, the MAINTENANCE WINDOW in OceanBase Database 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.
schema |
View Name |
Description |
|---|---|---|
| Oracle mode | DBA_SCHEDULER_JOBS | Query job information |
| Oracle mode | sys.ALL_VIRTUAL_TENANT_SCHEDULER_JOB_REAL_AGENT | Query the proxy table for job information. |
| MySQL-compatible mode | oceanbase.DBA_SCHEDULER_JOBS | Query job information |
Set MAINTENANCE WINDOW attributes
Currently, setting attributes for the MAINTENANCE WINDOW in OceanBase Database is also implemented through the DBMS_SCHEDULER system package. The currently supported attribute 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 next start time for 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 8:00 PM.
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. It determines whether statistics collection is required for a table again. The data information in a database table is not updated daily. Therefore, for tables with no data changes or where data changes are within the expected range, there is no need to collect statistics again, which improves the execution efficiency of automatic statistics collection tasks.
The following table lists the relevant views and tables that support querying DML STATS information in Oracle-compatible mode and MySQL-compatible mode.
schema |
View Name |
Description |
|---|---|---|
| Oracle mode | GV$DML_STATS、V$DML_STATS | Query DML STATS of a table from a virtual table |
| Oracle mode | sys.ALL_VIRTUAL_MONITOR_MODIFIED_REAL_AGENT | Query DML STATS of a table in a proxy table |
| Oracle 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, the criteria for determining whether table statistics are expired are as follows: if the cumulative number of rows affected by insert, delete, and update operations on a table since the last statistics collection exceeds a set threshold, the statistics are considered expired. The default value for this threshold is 10% of the total number of rows in the table, which can be adjusted via Prefs. For details, see Collection strategy parameter (Prefs) management function.
The current 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, automatic statistics collection is performed.If a table has
GLOBAL-level statistics but they have expired, automatic statistics collection is performed.
Otherwise, the OceanBase Database optimizer does not perform automatic statistics collection.
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, incremental automatic statistics collection is performed.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 derived incrementally.
For more information about the statistics collection and update strategies for partitioned tables, as well as detailed examples, see Statistics collection and update strategies for partitioned tables.
