OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.2.1

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.2.1
    iconOceanBase Database
    SQL - V 4.2.1
    SQL
    KV
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Manage statistics preferences

    Last Updated:2023-12-25 08:49:42  Updated
    share
    What is on this page
    Available statistics preferences
    Set and retrieve preferences
    Set and retrieve global preferences
    Set and retrieve table-level preferences
    Examples

    folded

    share

    Statistics preferences specify the default values for statistics collection strategies, such as the values of granularity and method_opt.

    Available statistics preferences

    In Oracle mode, the following virtual tables are provided for you to query the current settings of statistics preferences:

    • SYS.ALL_VIRTUAL_OPTSTAT_GLOBAL_PREFS_REAL_AGENT for querying global preference settings

    • SYS.ALL_VIRTUAL_OPTSTAT_USER_PREFS_REAL_AGENT for querying table-level preference settings

    The following table lists the available preferences that you can set.

    Preference name Preference value Description
    APPROXIMATE_NDV Valid values:
    • "TRUE" (default)
    • "FALSE"
    Specifies whether estimation is used for the calculation of the number of distinct values (NDV). Note that this preference cannot be inserted into __all_optstat_user_prefs.
    CASCADE Valid values:
    • "TRUE"
    • "FALSE"
    • "DBMS_STATS.AUTO_CASCADE" (default)
    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 percentage of rows to estimate.
    GRANULARITY Default value: "AUTO". The collection granularity. Its syntax is the same as that of granularity.
    INCREMENTAL Valid values:
    • "TRUE"
    • "FALSE" (default)
    Specifies whether to use the incremental collection strategy.
    INCREMENTAL_LEVEL Valid values:
    • "PARTITION"
    • "TABLE" (default)
    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:
    • "TRUE"
    • "FALSE"
    • "DBMS_STATS.AUTO_INVALIDATE" (default)
    This parameter is not used.
    OPTIONS Valid values:
    • "GATHER" (default)
    • "GATHER AUTO"
    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.

    Set and retrieve preferences

    Set and retrieve global preferences

    You can set and retrieve global preferences by using the following stored procedures:

    • reset_global_pref_defaults

    • reset_param_defaults

    • set_global_prefs

    • set_param

    • get_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;
    

    The parameters are described as follows:

    • pname: the name of a preference.

    • pvalue: the value of the preference.

    Set and retrieve table-level preferences

    You can set and retrieve table-level preferences by using the following stored procedures:

    • set_schema_prefs

    • set_table_prefs

    • delete_schema_prefs

    • delete_table_prefs

    • get_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
    • Oracle mode: the username. If the username is set to NULL, the current logon username is used by default.
    • MySQL mode: the name of the database to which the table belongs.
    tabname The name of the table.
    pname The name of the preference.
    pvalue The value of the preference.

    Examples

    • Set the global APPROXIMATE_NDV preference to FALSE.

      CALL dbms_stats.set_global_prefs('APPROXIMATE_NDV', 'FALSE');
      
    • Reset all global preferences to their default values.

      CALL reset_global_pref_defaults();
      
    • Set the DEGREE preference for the statistics collection strategy of tbl1 to 128 for user test.

      CALL dbms_stats.set_table_prefs('test', 'tbl1', 'DEGREE', '128');
      
    • Delete the DEGREE preference for the statistics collection strategy of tbl1 for user test.

      CALL dbms_stats.delete_table_prefs('test', 'tbl1', 'DEGREE');
      

    Previous topic

    Manage statistics history
    Last

    Next topic

    Monitoring and diagnostics for statistics collection
    Next
    What is on this page
    Available statistics preferences
    Set and retrieve preferences
    Set and retrieve global preferences
    Set and retrieve table-level preferences
    Examples