What is a Global Partitioned Index in Oracle

A Global Partitioned Index in Oracle Database is an index that is divided into multiple smaller index partitions, and its partitioning structure is independent of the underlying table's partitioning structure.

In simple words, the table and index can be partitioned using different columns and different partition boundaries.

It is mainly used to improve data retrieval and index management in large partitioned tables.

Important: A Global Partitioned Index has its own independent partitioning structure. It does not follow the partitioning structure of the underlying table.

1. Example of a Global Partitioned Index

Suppose we have a SALES table containing millions of records.

We partition the SALES table based on SALE_DATE, but we want to create an index based on SALE_ID.

SALES Table

SALE_ID CUSTOMER_NAME SALE_DATE AMOUNT
101Ravi2023-05-1010000
102Kumar2023-08-1515000
103Priya2024-03-2020000
104Arun2024-07-2525000
105Raj2025-01-1030000

Step 1: Create a Partitioned Table

First, create a partitioned SALES table using RANGE partitioning.

SQL - Create Partitioned Table
CREATE TABLE sales
(
    sale_id NUMBER,
    customer_name VARCHAR2(50),
    sale_date DATE,
    amount NUMBER
)
PARTITION BY RANGE (sale_date)
(
    PARTITION sales_2023
    VALUES LESS THAN (DATE '2024-01-01'),

    PARTITION sales_2024
    VALUES LESS THAN (DATE '2025-01-01'),

    PARTITION sales_2025
    VALUES LESS THAN (DATE '2026-01-01')
);

Here, the SALES table is divided into three partitions:

  • SALES_2023
  • SALES_2024
  • SALES_2025

Step 2: Create a Global Partitioned Index

Now create an index on SALE_ID, partitioned by the SALE_ID values.

SQL - Create Global Partitioned Index
CREATE INDEX idx_sales_global
ON sales(sale_id)
GLOBAL PARTITION BY RANGE (sale_id)
(
    PARTITION idx_p1 VALUES LESS THAN (1000),

    PARTITION idx_p2 VALUES LESS THAN (2000),

    PARTITION idx_p3 VALUES LESS THAN (MAXVALUE)
);
Result: Global Partitioned Index created successfully.

Here:

  • GLOBAL PARTITION BY RANGE specifies a Global Partitioned Index.
  • SALE_ID is the indexed column.
  • IDX_P1, IDX_P2 and IDX_P3 are index partitions.
Important Observation:
  • Table partitioning column = SALE_DATE.
  • Index partitioning column = SALE_ID.
Both use different partitioning columns.

Step 3: How Does It Work?

The table and index have separate partition structures.

Table Partitions Global Index Partitions
SALES_2023 IDX_P1: SALE_ID below 1000
SALES_2024 IDX_P2: SALE_ID below 2000
SALES_2025 IDX_P3: SALE_ID 2000 and above

This table illustrates the separate partitioning schemes, not a one-to-one relationship between their partitions.

Remember: The Global Partitioned Index partitions are determined by SALE_ID, whereas the table partitions are determined by SALE_DATE.

2. Query Using a Global Partitioned Index

Consider the following query:

SQL - Select Query
SELECT *
FROM sales
WHERE sale_id = 1500;

Oracle can use the Global Partitioned Index to locate the relevant index entry in IDX_P2 and then access the corresponding table row.

This is useful when we search using SALE_ID without specifying SALE_DATE.

Practical Example: If we search for SALE_ID = 1500, Oracle can identify the relevant index partition using the index partitioning key.

3. Advantages of Global Partitioned Indexes

  1. Independent Partitioning: Index partitions can use a different column from the table partitions.
  2. Efficient Searching: Can help locate records across multiple table partitions.
  3. Better Manageability: Large indexes can be divided into smaller partitions.
  4. Flexible Design: Useful when queries frequently search using columns other than the table partitioning key.
  5. Scalability: Useful for large database applications.

4. Disadvantages of Global Partitioned Indexes

  • More complex to maintain than Local Indexes.
  • Table partition operations can affect Global Indexes.
  • Additional maintenance may be required.
  • Requires careful partition design.

For example, when dropping a table partition, we can maintain Global Indexes using:

SQL - Drop Partition with Index Maintenance
ALTER TABLE sales
DROP PARTITION sales_2023
UPDATE INDEXES;

The UPDATE INDEXES clause helps maintain Global Indexes during this operation.

5. Difference Between Local and Global Partitioned Index

Local Partitioned Index Global Partitioned Index
Follows table partitioning. Independent of table partitioning.
Index partitions correspond to table partitions. Index partitions can have different boundaries.
Usually uses the table partitioning key. Can use a different index partitioning key.
Easier partition maintenance in general. Requires additional maintenance consideration.
Created using LOCAL. Created using GLOBAL PARTITION BY.

6. How to Check Global Partitioned Indexes?

Use the following query to check Global Partitioned Index information.

SQL - USER_PART_INDEXES
SELECT index_name,
       table_name,
       locality,
       partitioning_type
FROM user_part_indexes
WHERE table_name = 'SALES';

For a Global Partitioned Index, the output will show:

INDEX_NAME LOCALITY PARTITIONING_TYPE
IDX_SALES_GLOBAL GLOBAL RANGE

Check Individual Index Partitions

To check individual Global Index partitions, execute:

SQL - USER_IND_PARTITIONS
SELECT index_name,
       partition_name,
       status
FROM user_ind_partitions
WHERE index_name = 'IDX_SALES_GLOBAL';

This query displays the index partition names and their status.

7. Important Oracle Interview Questions

Q1. What is a Global Partitioned Index?

A Global Partitioned Index is an index divided into multiple partitions independently of the underlying table partitioning structure.

Q2. Can table and index partitioning columns be different?

Yes. For example, a table can be partitioned by SALE_DATE, while its Global Partitioned Index can be partitioned by SALE_ID.

Q3. How do we create a Global Partitioned Index?

We can use GLOBAL PARTITION BY RANGE while creating the index.

CREATE INDEX idx_sales_global
ON sales(sale_id)
GLOBAL PARTITION BY RANGE (sale_id)
(
    PARTITION idx_p1 VALUES LESS THAN (1000),
    PARTITION idx_p2 VALUES LESS THAN (2000),
    PARTITION idx_p3 VALUES LESS THAN (MAXVALUE)
);
Q4. What is the main difference between Local and Global Partitioned Indexes?

A Local Index follows the table partitioning structure, whereas a Global Partitioned Index has its own independent partitioning structure.

Q5. Can a Global Partitioned Index be used when searching records across multiple table partitions?

Yes. It can locate matching index entries across the table's partitions.

Interview Answer: What is a Global Partitioned Index?

A Global Partitioned Index in Oracle is an index divided into multiple index partitions independently of the underlying table partitions. It allows us to partition the index using a different column or partitioning strategy from the table.

Easy Way to Remember:

  • Local Partitioned Index → Index partitions follow table partitions.
  • Global Partitioned Index → Index partitions are independent of table partitions.

Important Interview Point: A table can be partitioned by SALE_DATE, while its Global Partitioned Index can be partitioned by SALE_ID. This is the key difference between Local and Global Partitioned Indexes.

Conclusion

Global Partitioned Indexes are useful in Oracle Database when we need an independent index partitioning structure for large partitioned tables.

They provide flexibility by allowing the table and index to use different partitioning columns and partition boundaries.

Understanding Local and Global Partitioned Indexes is important for Oracle Developers, DBAs, and database performance tuning professionals.

Thanks for Reading!
Keep learning Oracle SQL, PL/SQL, and Database Administration. Practice these examples to improve your Oracle Database knowledge.

No comments:

Post a Comment