What is List-Range Partitioning in Oracle

List-Range Partitioning in Oracle is a type of composite partitioning that combines List Partitioning and Range Partitioning.

In this method:

  1. First, Oracle divides the table into partitions based on specific values using List Partitioning.
  2. Then, each main partition is further divided into smaller subpartitions based on a range of values using Range Partitioning.
It is useful when we want to organize data based on categories and further divide each category based on dates or numeric ranges.

1. Real-time Example

Suppose we are working on an employee management application.

We have an EMPLOYEES table containing 10 lakh records.

We want to divide the data using two conditions:

  • First level: Divide employee records department-wise using DEPARTMENT.
  • Second level: Divide each department's records year-wise using JOIN_DATE.

Reference: Oracle Database 11g for Data Warehousing – PowerPoint Presentation

Oracle Database 11g for Data Warehousing – SlideServe

Example: Partition Structure

Main Partition Subpartitions
P_IT 2024, 2025, 2026
P_HR 2024, 2025, 2026
P_FINANCE 2024, 2025, 2026
Remember:
  • List Partitioning separates employees department-wise.
  • Range Partitioning further separates each department's employees based on joining year.

2. SQL Example

Let's create a List-Range partitioned table in Oracle.

CREATE TABLE employees
(
    emp_id NUMBER,
    emp_name VARCHAR2(100),
    department VARCHAR2(30),
    join_date DATE,
    salary NUMBER
)
PARTITION BY LIST (department)
SUBPARTITION BY RANGE (join_date)
(
    PARTITION p_it VALUES ('IT')
    (
        SUBPARTITION p_it_2024
        VALUES LESS THAN (DATE '2025-01-01'),

        SUBPARTITION p_it_2025
        VALUES LESS THAN (DATE '2026-01-01'),

        SUBPARTITION p_it_2026
        VALUES LESS THAN (DATE '2027-01-01')
    ),

    PARTITION p_hr VALUES ('HR')
    (
        SUBPARTITION p_hr_2024
        VALUES LESS THAN (DATE '2025-01-01'),

        SUBPARTITION p_hr_2025
        VALUES LESS THAN (DATE '2026-01-01'),

        SUBPARTITION p_hr_2026
        VALUES LESS THAN (DATE '2027-01-01')
    ),

    PARTITION p_finance VALUES ('FINANCE')
    (
        SUBPARTITION p_finance_2024
        VALUES LESS THAN (DATE '2025-01-01'),

        SUBPARTITION p_finance_2025
        VALUES LESS THAN (DATE '2026-01-01'),

        SUBPARTITION p_finance_2026
        VALUES LESS THAN (DATE '2027-01-01')
    )
);

3. Explanation of the SQL Query

  • PARTITION BY LIST (department) divides employees based on department values.
  • SUBPARTITION BY RANGE (join_date) further divides each department partition based on joining dates.
  • p_it stores IT department employees.
  • p_hr stores HR department employees.
  • p_finance stores Finance department employees.
  • Each department is further divided into date-based subpartitions.

Total Number of Subpartitions

3 Main Partitions × 3 Subpartitions = 9 Subpartitions

4. Insert Sample Records

Let's insert some sample records into the employees table.

INSERT INTO employees
VALUES (101, 'Ravi', 'IT',
        DATE '2024-05-10', 50000);

INSERT INTO employees
VALUES (102, 'Kumar', 'HR',
        DATE '2025-06-15', 40000);

INSERT INTO employees
VALUES (103, 'Raj', 'FINANCE',
        DATE '2026-03-20', 60000);

COMMIT;

What Happens Internally?

For each inserted record:

  1. Oracle checks the department value.
  2. It identifies the appropriate main partition.
  3. Oracle checks the joining date.
  4. It stores the record in the appropriate range subpartition.

Where Will the Records Be Stored?

Employee Department Joining Date Stored In
Ravi IT 10-May-2024 P_IT_2024
Kumar HR 15-Jun-2025 P_HR_2025
Raj FINANCE 20-Mar-2026 P_FINANCE_2026
Important: The subpartition boundaries use VALUES LESS THAN. For example, the 2024 subpartition stores dates before 01-Jan-2025. The 2025 subpartition stores dates from 01-Jan-2025 up to, but not including, 01-Jan-2026.

5. How to Check Partitions and Subpartitions?

To Check Main Partitions

SELECT
    TABLE_NAME,
    PARTITION_NAME
FROM USER_TAB_PARTITIONS
WHERE TABLE_NAME = 'EMPLOYEES';

To Check Subpartitions

SELECT
    TABLE_NAME,
    PARTITION_NAME,
    SUBPARTITION_NAME
FROM USER_TAB_SUBPARTITIONS
WHERE TABLE_NAME = 'EMPLOYEES';
Note: USER_TAB_PARTITIONS and USER_TAB_SUBPARTITIONS display partition information for tables owned by the current user.

6. Advantages of List-Range Partitioning

  1. Organizes data based on categories and date ranges.
  2. Makes large-table management easier.
  3. Supports partition and subpartition pruning.
  4. Helps retrieve specific department and date-based records efficiently.
  5. Simplifies data maintenance.

7. Interview-Ready Answer

Question: What is List-Range Partitioning in Oracle?

Answer:

"List-Range Partitioning in Oracle is a composite partitioning technique that combines List Partitioning and Range Partitioning. First, data is divided into partitions based on specific values, such as department names (IT, HR, and Finance). Then each partition is further divided into subpartitions based on a range of values, such as joining dates. It helps organize large volumes of data and improves data management."

8. Difference Between Composite Partitioning Types

Type First-Level Partition Second-Level Subpartition
Range-Hash Range Hash
Range-List Range List
List-Hash List Hash
List-Range List Range
Interview Tip: Remember These Four Types
  • Range-List: Year-wise → Department-wise.
  • List-Range: Department-wise → Year-wise.
  • Range-Hash: Year-wise → Hash distribution.
  • List-Hash: Department-wise → Hash distribution.

9. Important Point to Remember

The first partitioning method determines the main partition, and the second method determines the subpartitions.

In List-Range Partitioning:

  • List Partitioning determines the department.
  • Range Partitioning determines the date-based subpartition within that department.

Conclusion

List-Range Partitioning is useful when we need to divide large Oracle tables based on specific categories and further organize records within those categories based on date ranges.

List Partitioning handles category-wise separation, while Range Partitioning handles date-wise separation.

Understanding this concept is important for Oracle Database Developers and DBAs, especially when working with large tables.

No comments:

Post a Comment