OceanBase logo

OceanBase

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

Product Overview
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

OceanBase

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

Product Overview
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.3.3

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    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.3.3
    iconOceanBase Database
    SQL - V 4.3.3
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • 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

    Row estimation based on the selectivity

    Last Updated:2024-11-11 08:44:21  Updated
    Share
    What is on this page
    Share

    Selectivity refers to the ratio of the number of rows returned after passing through predicate conditions to the number of rows returned without passing through predicate conditions. The selectivity value ranges from 0 to 1, with a smaller value indicating better selectivity, and a value of 1 representing the worst selectivity. OceanBase Database's optimizer calculates predicate selectivity based on statistical information and selectivity calculation rules before proceeding with row estimation.

    Here is an example:

    obclient [TEST]>create table t1(c1 int, c2 int, c3 int);
    Query OK, 0 rows affected (0.09 sec)
    
    obclient [TEST]>insert into t1 select mod(level,10),mod(level,100),mod(level,1000) from dual connect by level<=1000;
    Query OK, 1000 rows affected (0.03 sec)
    Records: 1000  Duplicates: 0  Warnings: 0
    
    obclient [TEST]>call dbms_stats.gather_table_stats('TEST','T1');
    Query OK, 0 rows affected (0.48 sec)
    
    obclient [TEST]>select NUM_DISTINCT,LOW_VALUE,HIGH_VALUE from sys.dba_tab_col_statistics where owner = 'TEST' and table_name='T1';
    +--------------+-----------+------------+
    | NUM_DISTINCT | LOW_VALUE | HIGH_VALUE |
    +--------------+-----------+------------+
    |           10 | 0         | 9          |
    |          101 | 0         | 99         |
    |         1031 | 0         | 999        |
    +--------------+-----------+------------+
    3 rows in set (0.19 sec)
    

    After the statistical information is collected, you can query the corresponding view and find that the value of NDV in column c1 is 10. So, for query Q1 select * from t1 where c1 = 10, the selectivity of c1 = 10 is 1/10 = 0.1. Therefore, the estimated number of rows is 1000 * 1/10 = 100. This can be verified through the following execution plan for this query:

    -- Q1
    obclient [TEST]>explain select * from t1 where c1 = 10;
    +------------------------------------------------------------------------------------+
    | Query Plan                                                                         |
    +------------------------------------------------------------------------------------+
    | ===============================================                                    |
    | |ID|OPERATOR       |NAME|EST.ROWS|EST.TIME(us)|                                    |
    | -----------------------------------------------                                    |
    | |0 |TABLE FULL SCAN|t1  |100     |60          |                                    |
    | ===============================================                                    |
    | Outputs & filters:                                                                 |
    | -------------------------------------                                              |
    |   0 - output([t1.c1], [t1.c2], [t1.c3]), filter([t1.c1 = 10]), rowset=256          |
    |       access([t1.c1], [t1.c2], [t1.c3]), partitions(p0)                            |
    |       is_index_back=false, is_global_index=false, filter_before_indexback[false],  |
    |       range_key([t1.__pk_increment]), range(MIN ; MAX)always true                  |
    +------------------------------------------------------------------------------------+
    11 rows in set
    

    Similarly, for query Q2: select * from t1 where c1 = 10 and c2 = 10, when the cardinality_estimation_model is set to partial, the selectivity of the two predicates in Q2 is 1/101 * sqrt(1/10), which is approximately 0.0031. The estimated number of rows is rounded up to 4. This can be verified by the following execution plan:

    -- Q2
    obclient [TEST]>explain select * from t1 where c1 = 10 and c2 = 10;
    +------------------------------------------------------------------------------------------+
    | Query Plan                                                                               |
    +------------------------------------------------------------------------------------------+
    | ===============================================                                          |
    | |ID|OPERATOR       |NAME|EST.ROWS|EST.TIME(us)|                                          |
    | -----------------------------------------------                                          |
    | |0 |TABLE FULL SCAN|T1  |4       |63          |                                          |
    | ===============================================                                          |
    | Outputs & filters:                                                                       |
    | -------------------------------------                                                    |
    |   0 - output([T1.C1], [T1.C2], [T1.C3]), filter([T1.C2 = 10], [T1.C1 = 10]), rowset=16   |
    |       access([T1.C1], [T1.C2], [T1.C3]), partitions(p0)                                  |
    |       is_index_back=false, is_global_index=false, filter_before_indexback[false,false],  |
    |       range_key([T1.__pk_increment]), range(MIN ; MAX)always true                        |
    +------------------------------------------------------------------------------------------+
    11 rows in set (0.050 sec)
    

    Currently, selectivity-based row estimation is the main method used by OceanBase Database's optimizer for estimating the number of rows. During plan generation, the predicates of relevant operators are calculated based on statistical information and their selectivity calculation rules to determine the corresponding selectivity. Ultimately, the number of rows is estimated based on the overall selectivity.

    Previous topic

    Overview
    Last

    Next topic

    Row estimation based on the storage layer
    Next