This topic describes how to collect statistics. OceanBase Cloud Platform (OCP) supports two statistics collection modes: automatic collection and manual collection.
Prerequisites
To collect statistics, make sure that you have the following permissions:
-
Resource Permissions : Cluster Maintenance or Tenant Maintenance permission -
Menu Permissions : Permission on theStatistics Management menu ofTenants
Automatic statistics collection
By default, the OceanBase Database optimizer automatically collects statistics every day based on the maintenance windows to ensure iterative updates of statistics. By default, the optimizer starts to collect statistics at 22:00 on Monday to Friday with the maximum collection duration of 4 hours and at 6:00 on Saturday and Sunday with the maximum collection duration of 20 hours. The following table describes the maintenance windows.
| Maintenance window | Start time | Frequency | Maximum collection duration |
|---|---|---|---|
| MONDAY_WINDOW | 22:00 | Weekly | 4 hours |
| TUESDAY_WINDOW | 22:00 | Weekly | 4 hours |
| WEDNESDAY_WINDOW | 22:00 | Weekly | 4 hours |
| THURSDAY_WINDOW | 22:00 | Weekly | 4 hours |
| FRIDAY_WINDOW | 22:00 | Weekly | 4 hours |
| SATURDAY_WINDOW | 6:00 | Weekly | 20 hours |
| SUNDAY_WINDOW | 6:00 | Weekly | 20 hours |
You can configure the maintenance windows based on your business needs. For example, when a maintenance window coincides with peak hours, you can modify the start time of the maintenance window or specify not to collect statistics on specific dates. When your business environment contains a large number of tables or many ultra-large tables, you can modify the maximum collection duration of the maintenance window.
You can perform the following steps to adjust automatic statistics collection settings:
Log in to the OCP console.
In the left-side navigation pane, select
Tenants . TheTenants page appears.On the
Tenants page, find the target tenant and click its name to go to theOverview page of the tenant.In the left-side navigation pane of the page that appears, click
Statistics Management .On the
Statistics Overview page that appears, clickAutomatic Statistics Collection in the upper-right corner.
Notice
If the version of the cluster to which the tenant belongs is OceanBase Database V4.2.2.1, maintenance windows appear repeatedly when you adjust automatic statistics collection settings. We recommend that you directly use the default settings to avoid system errors caused by setting adjustment.
Enable or disable automatic statistics collection
By default, all maintenance windows are enabled. You can click
Edit automatic statistics collection settings
To edit automatic statistics collection settings, click
Modify automatic statistics collection parameters
OCP provides default automatic statistics settings regarding the collection method, degree of parallelism (DOP), and granularity. You can use the default settings or click the
The following table describes the parameters.
| Parameter | Default value | Value range | Description |
|---|---|---|---|
cascade |
DBMS_STATS.AUTO_CASCADE |
TUREFALSE |
Specifies whether to collect index statistics on the table at the same time. |
degree |
NULL (indicating the DOP of 1) |
[0,100] | The DOP of statistics collection. |
estimate_percent |
DBMS_STATS.AUTO_SAMPLE_SIZE |
[1,100]. The value NULL specifies to use all data. |
The percentage of data to be used to compute distribution features. |
granularity |
AUTO |
GLOBAL: collects global statistics.PARTITION: collects partition-level statistics.SUBPARTITION: collects subpartition-level statistics.ALL: collects statistics at all levels, including GLOBAL, PARTITION, and SUBPARTITION.AUTO: uses the default method to collect statistics at all levels, including GLOBAL, PARTITION, and SUBPARTITION. If granularity is not specified, the default value AUTO is used.DEFAULT: collects global and partition-level statistics.GLOBAL AND PARTITION: collects global and partition-level statistics.APPROX_GLOBAL AND PARTITION: collects partition-level statistics and deduces global statistics based on the partition-level statistics. |
The granularity in statistics collection. |
method_opt |
FOR ALL COLUMNS SIZE AUTO |
FOR ALL COLUMNS SIZE AUTO: The OceanBase Database optimizer determines whether to collect column histograms based on column usage. The default number of histogram buckets is 254.FOR ALL COLUMNS SIZE SKEWONLY: specifies to collect histograms only for columns with uneven data distribution. The default number of histogram buckets is 254.FOR ALL COLUMNS SIZE REPEAT: specifies to collect histograms only for columns whose histograms have been collected. The previous number of histogram buckets set for collection is used.FOR ALL COLUMNS SIZE integer: the number of histogram buckets for the column. Value range: [1, 2048]. |
The statistics collection method at the column level. |
Manual statistics collection
The OceanBase Database optimizer may be unable to complete statistics collection on ultra-large tables or too many tables within one maintenance window based on the default statistics collection strategies. In this case, you can manually collect statistics. Manual statistics collection is supported at the schema and table levels.
Notice
Collect schema-level statistics
You can collect statistics on all tables under a tenant.
Procedure
Log in to the OCP console.
In the left-side navigation pane, select
Tenants . TheTenants page appears.On the
Tenants page, find the target tenant and click its name to go to theOverview page of the tenant.In the left-side navigation pane, click
Statistics Management to go to theStatistics Overview page.Click Collect Schema Statistics in the upper-right corner.
(Optional) In the panel that appears on the right, select the database for statistics collection and configure related parameters.
For more information about statistics collection parameters, see Modify automatic statistics collection parameters.
Click
OK .
Example
Here is an example of manually collecting schema-level statistics:
Go to the
Statistics Overview page and click Collect Schema Statistics in the upper-right corner.The Collect Schema Statistics panel appears.
Select a database for statistics collection. You can perform a fuzzy search for the target database. The drop-down list displays all databases under the current tenant. You can select only one database.
Modify statistics collection parameters. To collect partition-level statistics without collecting index statistics by using an DOP of 5 and the default settings of other parameters, modify related parameters as follows:
Change the value of the
granularityparameter toPARTITION.Change the value of the
degreeparameter to5.Change the value of the
cascadeparameter toFALSE.Retain the default settings of other parameters.
Click
OK .
Collect table-level statistics
You can manually collect statistics on a single table in the
Procedure
Log in to the OCP console.
In the left-side navigation pane, select
Tenants . TheTenants page appears.On the
Tenants page, find the target tenant and click its name to go to theOverview page of the tenant.In the left-side navigation pane, click
Statistics Management to go to theStatistics Overview page.In the
Statistics Table section, select the business table for statistics collection and clickCollect in theActions column.(Optional) In the panel that appears on the right, configure statistics collection parameters.
For more information about statistics collection parameters, see Modify automatic statistics collection parameters.
Click
OK .
Related operations
In the
Statistics Table section, enter a table name keyword in the search box in the upper-right corner and click theSearch icon. Business tables meeting the search condition are displayed.- You can specify a table in the
schema.tableortableformat. - Fuzzy match is supported only for table names.
- You can specify a table in the
For a table in the
Normal state, you can collect statistics on the table or lock the table.For a table in the
Locked state, you can only unlock the table.