What is the purpose of the DEFAULT partition

A DEFAULT partition in Oracle is used in List Partitioning to store values that do not match any of the explicitly defined partition values.

In simple words:

DEFAULT acts as a catch-all partition for values that are not included in the other LIST partitions.

Let's understand with a real-time example.

1. Example: List Partitioning

Imagine you have an EMPLOYEES table containing employee details.

You want to partition employees based on their department.

Suppose the departments are:

  • HR
  • IT
  • FINANCE
  • Other departments

Creating the Table

CREATE TABLE employees (
    emp_id NUMBER,
    emp_name VARCHAR2(50),
    department VARCHAR2(30)
)
PARTITION BY LIST (department)
(
    PARTITION p_hr
    VALUES ('HR'),

    PARTITION p_it
    VALUES ('IT'),

    PARTITION p_finance
    VALUES ('FINANCE'),

    PARTITION p_default
    VALUES (DEFAULT)
);

Here, we have the following configuration:

Concept Description
Partition Key DEPARTMENT
Partitioning Method LIST
DEFAULT Stores values not explicitly listed in other partitions
Remember:

The DEFAULT partition stores department values that are not explicitly defined in P_HR, P_IT, or P_FINANCE.

2. How Does DEFAULT Work?

Let's insert some employee records into the EMPLOYEES table.

INSERT INTO employees
VALUES (101, 'Ravi', 'HR');

INSERT INTO employees
VALUES (102, 'Kiran', 'IT');

INSERT INTO employees
VALUES (103, 'Suresh', 'FINANCE');

INSERT INTO employees
VALUES (104, 'Raj', 'SALES');

INSERT INTO employees
VALUES (105, 'Arun', 'MARKETING');

COMMIT;

How Oracle Distributes the Data

P_HR

Partition condition: VALUES ('HR')

  • Ravi — HR
P_IT

Partition condition: VALUES ('IT')

  • Kiran — IT
P_FINANCE

Partition condition: VALUES ('FINANCE')

  • Suresh — FINANCE
P_DEFAULT — Catch-all Partition

Partition condition: VALUES (DEFAULT)

  • Raj — SALES
  • Arun — MARKETING

Notice that we did not explicitly create partitions for SALES and MARKETING.

Both records automatically go into P_DEFAULT because their department values are not included in the other LIST partitions.

Important:

Oracle checks the partition key value against the explicitly defined LIST values.

If the value does not match any of those values, Oracle stores the row in the DEFAULT partition, if one exists.

3. What Happens Without DEFAULT?

Suppose we create the EMPLOYEES table without a DEFAULT partition.

CREATE TABLE employees (
    emp_id NUMBER,
    emp_name VARCHAR2(50),
    department VARCHAR2(30)
)
PARTITION BY LIST (department)
(
    PARTITION p_hr
    VALUES ('HR'),

    PARTITION p_it
    VALUES ('IT'),

    PARTITION p_finance
    VALUES ('FINANCE')
);

Now, let's insert an employee belonging to the SALES department.

INSERT INTO employees
VALUES (104, 'Raj', 'SALES');

Oracle returns the following error:

ORA-14400: inserted partition key
does not map to any partition

Why Does This Error Occur?

Because SALES is not included in any of the existing partitions.

We have defined only HR, IT, and FINANCE values. There is no partition to accommodate SALES.

Solution:

Create a DEFAULT partition to handle department values that are not explicitly defined in the other partitions.

4. Can We Add a Partition After DEFAULT?

Yes, but there is one important condition.

Suppose the P_DEFAULT partition already exists and you want to create a separate partition for the SALES department.

You cannot simply add a new partition containing SALES while the DEFAULT partition still covers that value.

You need to split the DEFAULT partition.

Example: Splitting the DEFAULT Partition

Let's create a separate partition for SALES.

ALTER TABLE employees
SPLIT PARTITION p_default
VALUES ('SALES')
INTO (
    PARTITION p_sales,
    PARTITION p_default
);

After executing this statement, Oracle divides the existing DEFAULT partition into two partitions.

Partition Data Stored
P_SALES Employees belonging to SALES
P_DEFAULT All other unmatched department values
Important:

Existing SALES records in P_DEFAULT are moved into P_SALES during the split.

Other unmatched department values, such as MARKETING, continue to be stored in P_DEFAULT.

5. MAXVALUE vs DEFAULT in Oracle

This is a very important Oracle Database interview question.

MAXVALUE DEFAULT
Used in Range Partitioning Used in List Partitioning
Defines the highest possible boundary Handles unmatched values
Works with ordered values Works with explicitly listed values
Used with VALUES LESS THAN Used with VALUES (DEFAULT)
Catch-all for values beyond the previous range boundary Catch-all for values not explicitly listed

Easy Way to Remember

MAXVALUE

Range Partitioning → Values beyond the previous boundary.

DEFAULT

List Partitioning → Values not explicitly mentioned.

Interview Tip:

MAXVALUE handles values outside the existing range boundaries, whereas DEFAULT handles values not included in the explicitly defined LIST partitions.

6. Important Rules of DEFAULT Partition

Remember these important points when working with DEFAULT partitions in Oracle:

  1. Only one DEFAULT partition: Oracle allows only one DEFAULT partition in a LIST-partitioned table.
  2. Catch-all functionality: It stores values not covered by the explicitly defined LIST partitions.
  3. Prevents insert failures: It helps prevent ORA-14400 errors for unmatched partition key values.
  4. Partition splitting: You can split a DEFAULT partition to create a dedicated partition for a particular value.
  5. Existing data: During a partition split, Oracle redistributes existing rows according to the new partition definitions.
Note about NULL values:

For a single-column LIST partition key, NULL can be included explicitly in a partition using VALUES (NULL). If NULL is not explicitly covered and a DEFAULT partition exists, it can be accommodated by the DEFAULT partition.

7. Interview-Ready Answer

Interviewer Question:

What is the purpose of DEFAULT partition in Oracle?

Answer:

"DEFAULT partition is used in LIST Partitioning to handle values that are not explicitly defined in other partitions.

It acts as a catch-all partition and helps prevent insert failures when unexpected partition key values are inserted.

For example, if an EMPLOYEES table has HR, IT, and FINANCE partitions, any other department, such as SALES or MARKETING, will go into the DEFAULT partition.

Oracle allows only one DEFAULT partition in a LIST-partitioned table."

8. Important Interview Questions

Q1. What is DEFAULT partition in Oracle?

DEFAULT is a special partition used in LIST Partitioning to store values that are not explicitly included in other partitions.

Q2. Can we insert unexpected values into a DEFAULT partition?

Yes. If a DEFAULT partition exists, Oracle automatically stores unmatched partition key values in it.

Q3. Can we create multiple DEFAULT partitions?

No. Oracle allows only one DEFAULT partition in a LIST-partitioned table.

Q4. Can we add a new partition after DEFAULT?

You cannot simply add a partition for a value already covered by DEFAULT. You can split the DEFAULT partition to create a dedicated partition for that value.

Q5. What happens if DEFAULT is not defined?

If an inserted partition key value does not match any existing LIST partition, Oracle returns ORA-14400.

Q6. What is the difference between MAXVALUE and DEFAULT?

MAXVALUE is used in Range Partitioning to handle values beyond the previous range boundary. DEFAULT is used in List Partitioning to handle values not explicitly listed.

9. Conclusion

Final Summary

DEFAULT partition is used in Oracle LIST Partitioning to store values that are not explicitly defined in other partitions.

It acts as a catch-all partition and helps prevent ORA-14400 errors when unexpected partition key values are inserted.

For example, if an EMPLOYEES table has HR, IT, and FINANCE partitions, other department values such as SALES and MARKETING are automatically stored in the DEFAULT partition.

If you want to create a dedicated partition for a value already covered by DEFAULT, you can split the DEFAULT partition.

DEFAULT = Catch-all Partition for Unmatched Values

No comments:

Post a Comment