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.2.0

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive 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.2.0
    iconOceanBase Database
    SQL - V 4.2.0
    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

    Overview

    Last Updated:2025-12-02 03:06:22  Updated
    Share
    What is on this page
    Advantages and disadvantages of indexes
    Availability and visibility of indexes
    Index availability
    Index visibility
    Relationship between indexes and keys

    folded

    Share

    An index, also known as a secondary index, is an optional structure that users can choose to create on specific fields based on their business needs. This helps accelerate queries on those fields. This topic describes the advantages and disadvantages of using indexes, their availability and visibility, and their relationship with keys.

    In OceanBase Database, the clustered index table model is used. This means that a primary key index is automatically created for the user-specified primary key, while other user-created indexes are secondary indexes.

    For example, you can create a table named employee and insert three data records.

    obclient> CREATE TABLE employee(id INT, name VARCHAR(20), PRIMARY KEY(id));
    Query OK, 0 rows affected
    
    obclient> INSERT INTO employee VALUES(1,'John'),(2,'Alice'),(3,'Bob');
    Query OK, 3 rows affected 
    Records: 3  Duplicates: 0  Warnings: 0
    
    obclient> SELECT * FROM employee;
    +----+-------+
    | ID | NAME  |
    +----+-------+
    |  1 | John  |
    |  2 | Alice |
    |  3 | Bob   |
    +----+-------+
    3 rows in set
    

    The data in the employee table is stored in an ordered manner based on the user-specified id. When you want to locate specific data, you can use the id field for binary search. If you need to quickly locate data based on the name field, you can create a secondary index on the name field, as shown in the following example:

    CREATE INDEX name_index ON employee(name);
    

    The data in the index table is as follows:

    name: Alice, id: 2
    name: Bob, id :3
    name: John, id: 1
    

    The data in the name_index index table is stored in an ordered manner based on the name field. When you want to locate specific data based on the name field, you can use the name field for binary search.

    Advantages and disadvantages of indexes

    The advantages of indexes are as follows:

    • You can accelerate queries without modifying SQL statements. This is because only the required data is scanned.

    • Indexes typically contain fewer columns, which can reduce query I/O.

    The disadvantages of indexes are as follows:

    • You need a deep understanding of your business and data model to decide which fields to create indexes on.

    • When your business changes, you need to re-evaluate whether the existing indexes still meet your needs.

    • Maintaining indexes during data writes consumes some performance.

    • Indexes occupy resources such as memory and disk space.

    Availability and visibility of indexes

    Index availability

    When you drop a partition without specifying the rebuild index option, the index is marked as UNUSABLE, indicating that it is unavailable. In this case, the index does not need to be maintained during DML operations, and the optimizer will ignore it.

    Index visibility

    Index visibility refers to whether the optimizer ignores the index. If an index is invisible, the optimizer will ignore it, but the index still needs to be maintained during DML operations. Generally, before deleting an index, you can set it to invisible to observe its impact on your business. If there is no impact, you can then delete the index.

    Relationship between indexes and keys

    A key is a set of columns or expressions on which you can create an index. However, indexes and keys are different. An index is an object stored in the data, while a key is a logical concept.

    Previous topic

    Temporary tables
    Last

    Next topic

    Local and global indexes
    Next
    What is on this page
    Advantages and disadvantages of indexes
    Availability and visibility of indexes
    Index availability
    Index visibility
    Relationship between indexes and keys