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.
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 |
|---|---|---|---|
| 101 | Ravi | 2023-05-10 | 10000 |
| 102 | Kumar | 2023-08-15 | 15000 |
| 103 | Priya | 2024-03-20 | 20000 |
| 104 | Arun | 2024-07-25 | 25000 |
| 105 | Raj | 2025-01-10 | 30000 |
Step 1: Create a Partitioned Table
First, create a partitioned SALES table using RANGE partitioning.
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.
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)
);
Here:
GLOBAL PARTITION BY RANGEspecifies a Global Partitioned Index.SALE_IDis the indexed column.IDX_P1,IDX_P2andIDX_P3are index partitions.
- Table partitioning column = SALE_DATE.
- Index partitioning column = SALE_ID.
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.
2. Query Using a Global Partitioned Index
Consider the following 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.
3. Advantages of Global Partitioned Indexes
- Independent Partitioning: Index partitions can use a different column from the table partitions.
- Efficient Searching: Can help locate records across multiple table partitions.
- Better Manageability: Large indexes can be divided into smaller partitions.
- Flexible Design: Useful when queries frequently search using columns other than the table partitioning key.
- 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:
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.
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:
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
A Global Partitioned Index is an index divided into multiple partitions independently of the underlying table partitioning structure.
Yes. For example, a table can be partitioned by SALE_DATE, while its Global Partitioned Index can be partitioned by SALE_ID.
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)
);
A Local Index follows the table partitioning structure, whereas a Global Partitioned Index has its own independent partitioning structure.
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.
Keep learning Oracle SQL, PL/SQL, and Database Administration. Practice these examples to improve your Oracle Database knowledge.
No comments:
Post a Comment