What is a global prefixed index

A GLOBAL PREFIXED INDEX is a global partitioned index in which the leftmost (first) column of the index is the same as the partition key of the index.

In simple words:

If the first column of a global partitioned index matches its own index partitioning key, it is called a Global Prefixed Index.

Important difference: For a global index, we compare the first index column with the global index's partition key, not necessarily the table's partition key.

Let's understand with a practical example.

1. Create a Partitioned Table

Suppose we have an ORDERS table partitioned by ORDER_DATE.

Creating the Table

CREATE TABLE orders (
    order_id NUMBER,
    order_date DATE,
    customer_id NUMBER,
    amount NUMBER
)
PARTITION BY RANGE (order_date)
(
    PARTITION p_jan
    VALUES LESS THAN (DATE '2025-02-01'),

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

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

    PARTITION p_apr
    VALUES LESS THAN (DATE '2025-05-01')
);

Here:

  • Table partition key = ORDER_DATE
  • Table partitioning method = RANGE
  • Number of table partitions = 4
Remember:

Table partition key = ORDER_DATE

Table partitioning method = RANGE

Number of table partitions = 4

2. Create a Global Prefixed Index

Now create a global partitioned index on CUSTOMER_ID.

CREATE INDEX idx_orders_global
ON orders (customer_id, order_id)
GLOBAL PARTITION BY RANGE (customer_id)
(
    PARTITION ip1 VALUES LESS THAN (1000),
    PARTITION ip2 VALUES LESS THAN (2000),
    PARTITION ip3 VALUES LESS THAN (3000),
    PARTITION ip4 VALUES LESS THAN (MAXVALUE)
);

Understand the Index Definition

Property Value
Table partition key ORDER_DATE
Index columns CUSTOMER_ID, ORDER_ID
Index partition key CUSTOMER_ID
Index partitioning method RANGE
Index type Global partitioned
Index structure Prefixed

Why Is This a Global Prefixed Index?

Because:

  • Global index partition key = CUSTOMER_ID.
  • First index column = CUSTOMER_ID.
  • Both match.
Index Partition Key = CUSTOMER_ID

First Index Column = CUSTOMER_ID

Therefore, it is a Global Prefixed Index.

3. How Does a Global Prefixed Index Work?

ORDERS Table

Range partitioning on ORDER_DATE.

P_JAN

January table partition

P_FEB

February table partition

P_MAR

March table partition

P_APR

April table partition

GLOBAL INDEX

Range partitioning on CUSTOMER_ID.

IP1

CUSTOMER_ID less than 1000

IP2

CUSTOMER_ID from 1000 to less than 2000

IP3

CUSTOMER_ID from 2000 to less than 3000

IP4

CUSTOMER_ID 3000 and above

Global Prefixed Index

The index is partitioned independently from the table.

Each index partition can contain entries pointing to rows in multiple table partitions.

Notice the difference:

  • Table is divided based on ORDER_DATE.
  • Global index is divided based on CUSTOMER_ID.
  • The first index column matches the index partition key.
Important:

A Global Prefixed Index does not need to use the table partition key as its leading column. It must use its own index partition key as the leading column.

4. Example Query

Suppose we execute the following query:

SELECT *
FROM orders
WHERE customer_id = 1500;

What Happens Internally?

  1. Oracle checks the global index partition boundaries.
  2. It identifies IP2 because CUSTOMER_ID 1500 falls between 1000 and 2000.
  3. It searches the relevant global index partition.
  4. The index provides row locations (ROWIDs).
  5. Oracle accesses the corresponding table partitions to retrieve the records.

This can help when searching for customers across multiple monthly table partitions.

Performance Note:

A global prefixed index can support efficient index partition pruning when the query contains suitable predicates on the index partition key.

The optimizer decides whether this index is the most efficient access path.

5. What Is a Global Non-Prefixed Index?

Let's change the index column order.

CREATE INDEX idx_orders_global_np
ON orders (order_id, customer_id)
GLOBAL PARTITION BY RANGE (customer_id)
(
    PARTITION ip1 VALUES LESS THAN (1000),
    PARTITION ip2 VALUES LESS THAN (2000),
    PARTITION ip3 VALUES LESS THAN (3000),
    PARTITION ip4 VALUES LESS THAN (MAXVALUE)
);

Here:

  • Index partition key = CUSTOMER_ID.
  • First index column = ORDER_ID.
  • The first index column does not match the index partition key.

Therefore, this is a Global Non-Prefixed Index.

Index Partition Key = CUSTOMER_ID

First Index Column = ORDER_ID

GLOBAL NON-PREFIXED INDEX

6. Global Prefixed vs Global Non-Prefixed

This is an important Oracle interview comparison.

Feature Global Prefixed Global Non-Prefixed
Index partition key First index column Not the first index column
Global index Yes Yes
Partitioning structure Independent of table Independent of table
Index partition pruning Supported when query filters on index partition key May require scanning multiple index partitions
Main difference Column order matches Column order does not match

7. Local Prefixed vs Global Prefixed

This is particularly important for Oracle interviews.

Feature Local Prefixed Global Prefixed
Index partitioning Follows table partitioning Independent of table
Leading column Table partition key Index partition key
Partition key Same as table's partition key Can differ from table's partition key
Number of index partitions Corresponds to table partitions Independently defined
Maintenance Generally easier May require additional maintenance
Interview Tip:

For a local prefixed index, compare the leading index column with the table partition key.

For a global prefixed index, compare the leading index column with the global index partition key.

8. How to Identify a Global Prefixed Index?

Check the index partitioning information:

SELECT
    INDEX_NAME,
    TABLE_NAME,
    LOCALITY,
    ALIGNMENT
FROM USER_PART_INDEXES
WHERE TABLE_NAME = 'ORDERS';

Check the index columns:

SELECT
    INDEX_NAME,
    COLUMN_NAME,
    COLUMN_POSITION
FROM USER_IND_COLUMNS
WHERE TABLE_NAME = 'ORDERS'
ORDER BY INDEX_NAME, COLUMN_POSITION;

Compare the first index column with the index partition key to determine whether the global index is prefixed.

Remember:

USER_PART_INDEXES provides index locality and alignment information.

USER_IND_COLUMNS provides index column order.

For the exact partition key definition, examine USER_IND_PARTITIONS and the index DDL using DBMS_METADATA.GET_DDL where appropriate.

9. Interview-Ready Answer

Interviewer Question:

What is a Global Prefixed Index in Oracle?

Answer:

"A Global Prefixed Index is a global partitioned index in which the leading column of the index matches the index partitioning key.

For example, if an ORDERS table is partitioned by ORDER_DATE, we can create a global range-partitioned index on CUSTOMER_ID and ORDER_ID, with CUSTOMER_ID as the index partition key.

Since CUSTOMER_ID is also the first index column, it is a Global Prefixed Index.

Unlike a local index, its partitioning structure is independent of the underlying table's partitioning structure."

10. Test Your Understanding

Interview Question

Your global index is partitioned by CUSTOMER_ID.

Which index definition is a Global Prefixed Index?

Conclusion

Final Summary

A Global Prefixed Index in Oracle is a global partitioned index in which the first index column matches the index partition key.

  • The index has its own independent partitioning structure.
  • The index partition key can differ from the table partition key.
  • The first index column must match the global index partition key.
  • It can support index partition pruning when queries filter on the index partition key.
  • It is useful for queries accessing data across multiple table partitions.
GLOBAL PREFIXED INDEX
= First Index Column Matches Index Partition Key
Next Topic:

Global Non-Prefixed Index in Oracle with Practical Example.

No comments:

Post a Comment