Statistics preferences specify the default values for statistics collection strategies, such as the values of granularity and method_opt.
Tables for storing statistics preferences
Currently, the OceanBase Database optimizer uses two internal tables to store global-level and table-level statistics preferences, respectively.
The internal table
__all_optstat_global_prefsstores global-level statistics preferences.The internal table
__all_optstat_user_prefsstores table-level statistics preferences.
The following table describes the fields in the __all_optstat_global_prefs internal table.
| Column name | Type | Description |
|---|---|---|
| SNAME | VARCHAR2(30) | The name of preference. |
| SVAL1 | NUMBER(38) | The interval at which statistics are retained. |
| SVAL2 | TIMESTAMP(6) WITH LOCAL TIME ZONE | The time when the preference was last modified. |
| SPARE1 | NUMBER(38) | This parameter is not used. |
| SPARE2 | NUMBER(38) | This parameter is not used. |
| SPARE3 | NUMBER(38) | This parameter is not used. |
| SPARE4 | VARCHAR2(4096) | The value of the preference. |
| SPARE5 | VARCHAR2(4096) | This parameter is not used. |
| SPARE6 | TIMESTAMP(6) WITH LOCAL TIME ZONE | This parameter is not used. |
Note
When a tenant is created, the related preferences are inserted into
__all_optstat_global_prefs. You cannot add data to or delete data from this table, but you can modify the data in this table.
The following table describes the fields in the __all_optstat_user_prefs internal table.
| Column name | Type | Description |
|---|---|---|
| PNAME | VARCHAR2(30) | The name of preference. |
| VALNUM | NUMBER(38) | This parameter is not used. |
| VALCHAR | VARCHAR2(4000) | The value of the preference. |
| CHGTIME | TIMESTAMP(6) WITH LOCAL TIME ZONE | The time when the preference was last modified. |
| SPARE1 | NUMBER(38) | This parameter is not used. |
Note
Data in the
__all_optstat_user_prefsinternal table is explicitly inserted when the user creates the table. When the OceanBase Database optimizer obtains a preference, it queries the__all_optstat_user_prefsinternal table first. If the preference cannot be found in__all_optstat_user_prefs, the optimizer queries the__all_optstat_global_prefsinternal table.
In Oracle mode, the following virtual tables are provided for you to query the current preference:
SYS.ALL_VIRTUAL_OPTSTAT_GLOBAL_PREFS_REAL_AGENTfor querying global-level preferencesSYS.ALL_VIRTUAL_OPTSTAT_USER_PREFS_REAL_AGENTfor querying table-level preferences
Configurable statistics preferences
The following table lists the configurable statistics preferences.
| Preference name | Preference value | Description |
|---|---|---|
| APPROXIMATE_NDV | Valid values:
|
Specifies whether estimation is used for the calculation of NDV. Note that this preference cannot be inserted into __all_optstat_user_prefs. |
| CASCADE | Valid values:
|
This parameter is not used. |
| DEGREE | Default value: NULL | The collection concurrency. |
| ESTIMATE_PERCENT | Value range: [0.000001, 100]; Default value: "DBMS_STATS.AUTO_SAMPLE_SIZE". | The sampling ratio. |
| GRANULARITY | Default value: "AUTO" | The collection granularity. Its syntax is the same as that of granularity. |
| INCREMENTAL | Valid values:
|
Specifies whether to use the incremental collection strategy. |
| INCREMENTAL_LEVEL | Valid values:
|
The incremental collection level. Currently, only the table level is supported. |
| METHOD_OPT | Default value: "FOR ALL COLUMNS SIZE AUTO" | The statistics collection method at the column level. Its syntax is the same as that of method_opt. |
| NO_INVALIDATE | Valid values:
|
This parameter is not used. |
| OPTIONS | Valid values:
|
This parameter is not used. |
| STALE_PERCENT | Default value: 10 | The expiration ratio threshold for statistics. |
| STATS_RETENTION | Value range: [0-365000]; Default value: 31 | The interval at which statistics are retained. |
Configure and retrieve statistics preferences
Configure and retrieve global-level statistics preferences
You can configure and retrieve global-level statistics preferences by using the following stored procedures:
reset_global_pref_defaultsreset_param_defaultsset_global_prefsset_paramget_param
The definitions are as follows:
PROCEDURE reset_global_pref_defaults;
PROCEDURE reset_param_defaults;
PROCEDURE set_global_prefs(
pname VARCHAR2,
pvalue VARCHAR2
);
PROCEDURE set_param(
pname VARCHAR2,
pval VARCHAR2
);
FUNCTION get_param (
pname VARCHAR2
)RETURN VARCHAR2;
Parameters:
pname: the name of the preference.pvalue: the value of the preference.
Configure and retrieve table-level statistics preferences
You can configure and retrieve table-level statistics preferences by using the following stored procedures:
set_schema_prefsset_table_prefsdelete_schema_prefsdelete_table_prefsget_prefs
The definitions are as follows:
PROCEDURE set_schema_prefs(
ownname VARCHAR2,
pname VARCHAR2,
pvalue VARCHAR2
);
PROCEDURE set_table_prefs(
ownname VARCHAR2,
tabname VARCHAR2,
pname VARCHAR2,
pvalue VARCHAR2
);
PROCEDURE delete_schema_prefs(
ownname VARCHAR2,
pname VARCHAR2
);
PROCEDURE delete_table_prefs (
ownname VARCHAR2,
tabname VARCHAR2,
pname VARCHAR2
);
FUNCTION get_prefs (
pname VARCHAR2,
ownname VARCHAR2 DEFAULT NULL,
tabname VARCHAR2 DEFAULT NULL
) RETURN VARCHAR2;
The following table describes the parameters.
| Parameter | Description |
|---|---|
| ownname | The username. If the username is set to NULL, the current logon username is used by default. |
| tabname | The name of the table. |
| pname | The name of the preference. |
| pvalue | The value of the preference. |
Examples
Set the default value of the global-level
APPROXIMATE_NDVparameter toFALSE.CALL dbms_stats.set_global_prefs('APPROXIMATE_NDV', 'FALSE');Reset all global-level preferences to default values.
CALL reset_global_pref_defaults();Set the default value of
DEGREEfor the statistics collection strategy oftbl1to128for usertest.CALL dbms_stats.set_table_prefs('test', 'tbl1', 'DEGREE', '128');Delete the default value of
DEGREEfor the statistics collection strategy oftbl1for usertest.CALL dbms_stats.delete_table_prefs('test', 'tbl1', 'DEGREE');