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

    Local indexes

    Last Updated:2024-11-11 07:37:15  Updated
    share
    What is on this page
    Overview
    Examples
    Create a local index
    Create a local unique index
    Partition pruning

    folded

    share

    A local index is also called a local partitioned index. It is created by using the LOCAL keyword. A local index has the same partitioning key and number of partitions as the table, meaning that the index and the table have the same partitioning mechanism.

    Overview

    A local index is created on data in a single partition. The key-value pairs of the index and the data in the table are in a one-to-one match. Each index partition maps to one table partition. They share the same partitioning rules. Therefore, a local unique index is only guaranteed to be unique in a partition. Its uniqueness within the table is not guaranteed.

    To use a local unique index as a unique constraint on a table, the local unique index must contain a partitioning key of the table.

    Notice

    • In the MySQL mode of OceanBase Database, if the keyword of an index is not specified, LOCAL is used as the keyword by default. In this case, the index is created as a local index.

    • A unique index must contain all columns in the table partitioning function.

    Examples

    Create a local index

    Create a HASH-partitioned table tbl1_h, and then create a local index tbl1_h_idx1 for the table.

    obclient> CREATE TABLE tbl1_h(col1 INT PRIMARY KEY,col2 INT)
           PARTITION BY HASH(col1) PARTITIONS 5;
    Query OK, 0 rows affected
    
    obclient> CREATE INDEX tbl1_h_idx1 ON tbl1_h(col2) LOCAL;
    Query OK, 0 rows affected
    

    Create a local unique index

    Create a RANGE-LIST-subpartitioned table tbl2_f_rl without using a template, and then create a local unique index tbl2_f_rl_idx1 for the table.

    obclient> CREATE TABLE tbl2_f_rl(col1 INT,col2 INT)
           PARTITION BY RANGE(col1)
           SUBPARTITION BY LIST(col2)
           (PARTITION p0 VALUES LESS THAN(100)
             (SUBPARTITION sp0 VALUES IN(1,3),
              SUBPARTITION sp1 VALUES IN(4,6),
              SUBPARTITION sp2 VALUES IN(7,9)),
            PARTITION p1 VALUES LESS THAN(200)
             (SUBPARTITION sp3 VALUES IN(1,3),
              SUBPARTITION sp4 VALUES IN(4,6),
              SUBPARTITION sp5 VALUES IN(7,9))
           );
    Query OK, 0 rows affected
    
    obclient> CREATE UNIQUE INDEX tbl2_f_rl_idx1 ON tbl2_f_rl(col1,col2) LOCAL;
    Query OK, 0 rows affected
    

    Partition pruning

    In OceanBase Database, local indexes also support partition pruning. One prerequisite for partition pruning is that the query condition must contain a partitioning key. This increases query efficiency by reducing the number of partitions accessed by a query.

    The following is an example of partitioning pruning with a partitioning key specified in the query condition:

    obclient> EXPLAIN SELECT /*+index(t1 idx)*/ b FROM t1 WHERE b=1 AND a=1\G
    *************************** 1. row ***************************
    Query Plan: =====================================
    |ID|OPERATOR |NAME   |EST. ROWS|COST|
    -------------------------------------
    |0 |TABLE GET|t1(idx)|1        |52  |
    =====================================
    Outputs & filters:
    -------------------------------------
      0 - output([t1.b]), filter(nil),
          access([t1.b]), partitions(p1)
    1 row in set
    

    If no partitioning key is specified in a query, the local index cannot use partition pruning. In this case, all partitions are scanned, which increases the cost of the scan.

    If no partitioning key is specified in the query condition, partition pruning cannot be used. Here is an example:

    obclient> EXPLAIN SELECT /*+index(t1 idx)*/ b FROM t1 WHERE b=1\G
    *************************** 1. row ***************************
    Query Plan: ====================================================
    |ID|OPERATOR               |NAME    |EST. ROWS|COST|
    ----------------------------------------------------
    |0 |EXCHANGE IN DISTR      |        |4950     |3551|
    |1 | EXCHANGE OUT DISTR    |:EX10000|4950     |3083|
    |2 |  PX PARTITION ITERATOR|        |4950     |3083|
    |3 |   TABLE SCAN          |t1(idx) |4950     |3083|
    ====================================================
    Outputs & filters:
    -------------------------------------
      0 - output([t1.b]), filter(nil)
      1 - output([t1.b]), filter(nil), dop=1
      2 - output([t1.b]), filter(nil)
      3 - output([t1.b]), filter(nil),
          access([t1.b]), partitions(p[0-4])
    1 row in set
    

    Previous topic

    Overview
    Last

    Next topic

    Global indexes
    Next
    What is on this page
    Overview
    Examples
    Create a local index
    Create a local unique index
    Partition pruning