Understanding Global vs Local Indexes in OceanBase and Their Impact on Query Performance
This article explains the differences between global and local indexes in OceanBase, analyzes why queries using global unique indexes run significantly faster than those using local indexes during Oracle migration, and provides detailed SQL examples, execution plans, and performance testing results to guide database optimization.
The article begins by describing a migration scenario where an Oracle table cannot use row movement, requiring special handling with the dbcat tool and resulting in two possible index strategies: converting the primary key to a global unique index via OMS or adding the partition key to the primary key as a local index via dbcat .
It then clarifies the concepts of global and local indexes, noting that only partitioned tables have this distinction; MySQL InnoDB supports only local indexes, while Oracle supports global indexes. Global indexes store a single index structure for all partitions, whereas local indexes maintain separate structures per partition.
The performance impact is illustrated with a test case: a query on the driven table b using the primary key (a local index) takes 90 seconds, while forcing the use of a global unique index with the hint /*+ index(b UIDX_DATA_ID2) */ reduces execution time to 5 seconds. Execution plans show that the local index forces scans across all 130 partitions, whereas the global index accesses only one partition.
Further analysis of the execution plans demonstrates that the global index’s leaf nodes contain the primary key, enabling partition pruning during the lookup, while the plan output for the local index incorrectly lists many partitions. The article emphasizes that in a non‑distributed OceanBase cluster, global indexes avoid distributed transaction overhead and provide the best performance when the query cannot be partition‑pruned.
Finally, the article concludes that using a global unique index is the most efficient solution for queries that cannot benefit from partition pruning, especially in non‑distributed OceanBase deployments, and provides a reference to the official OceanBase documentation on global and local indexes.
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.