In this method:
- First, Oracle divides the table into partitions based on specific values using List Partitioning.
- Then, each main partition is further divided into smaller subpartitions based on a range of values using Range Partitioning.
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 |
- 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_itstores IT department employees.p_hrstores HR department employees.p_financestores Finance department employees.- Each department is further divided into date-based subpartitions.
Total Number of 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:
- Oracle checks the department value.
- It identifies the appropriate main partition.
- Oracle checks the joining date.
- 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 |
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';
6. Advantages of List-Range Partitioning
- Organizes data based on categories and date ranges.
- Makes large-table management easier.
- Supports partition and subpartition pruning.
- Helps retrieve specific department and date-based records efficiently.
- Simplifies data maintenance.
7. Interview-Ready Answer
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 |
- 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