A DEFAULT or MAXVALUE partition or subpartition will capture any rows that do not meet the other partitioning rules defined for a table.
Defining a DEFAULT Partition
A DEFAULT partition will capture any rows that do not fit into any other partition in a LIST partitioned (or subpartitioned) table. If you do not include a DEFAULT rule, any row that does not match one of the values in the partitioning constraints will result in an error. Each LIST partition or subpartition may have its own DEFAULT rule.
The syntax of a DEFAULT rule is:
Where partition_name specifies the name of the partition or subpartition that will store any rows that do not match the rules specified for other partitions.
The last example created a list partitioned table in which the server decided which partition to store the data based upon the value of the country column. If you attempt to add a row in which the value of the country column contains a value not listed in the rules, Advanced Server reports an error.
The following example creates the same table, but adds a DEFAULT partition. The server will store any rows that do not match a value specified in the partitioning rules for europe, asia, or americas partitions in the others partition.
To test the DEFAULT partition, add row with a value in the country column that does not match one of the countries specified in the partitioning constraints.
Querying the contents of the sales table confirms that the previously rejected row is now stored in the sales_others partition.
Advanced Server provides the following methods to re-assign the contents of a DEFAULT partition or subpartition:
You can use the ALTER TABLE… ADD PARTITION command to add a partition to a table with a DEFAULT rule as long as there are no conflicting values between existing rows in the table and the values of the partition to be added. You can alternatively use the ALTER TABLE… SPLIT PARTITION command to split an existing partition. Examples are shown following this bullet point list.
You can use the ALTER TABLE… ADD SUBPARTITION command to add a subpartition to a table with a DEFAULT rule as long as there are no conflicting values between existing rows in the table and the values of the subpartition to be added. You can alternatively use the ALTER TABLE… SPLIT SUBPARTITION command to split an existing subpartition.
Adding a Partition to a Table with a DEFAULT Partition
Using the table that was created with the CREATE TABLE sales command shown at the beginning of this section, the following shows use of the ALTER TABLE... ADD PARTITION command assuming there is no conflict of values between the existing rows in the table and the values of the partition to be added.
However, the following shows the error when there are conflicting values when the following rows have been inserted into the table.
Row (4,'SOUTH AFRICA') conflicts with the VALUES list in the ALTER TABLE... ADD PARTITION statement, thus resulting in an error.
Splitting a DEFAULT Partition
The following example splits a DEFAULT partition, redistributing the partition's content between two new partitions. The table was created with the CREATE TABLE sales command shown at the beginning of this section.
The following inserts rows into the table including rows into the DEFAULT partition.
The partitions include the DEFAULT others partition.
The following shows the rows distributed amongst the partitions.
The following command splits the DEFAULT others partition into two partitions named africa and others.
The partitions now include the africa partition along with the DEFAULT others partition.
The following shows that the rows have been redistributed across the new partitions.
Defining a MAXVALUE Partition
A MAXVALUE partition (or subpartition) will capture any rows that do not fit into any other partition in a range-partitioned (or subpartitioned) table. If you do not include a MAXVALUE rule, any row that exceeds the maximum limit specified by the partitioning rules will result in an error. Each partition or subpartition may have its own MAXVALUE partition.
The syntax of a MAXVALUE rule is:
Where partition_name specifies the name of the partition that will store any rows that do not match the rules specified for other partitions.
The last example created a range-partitioned table in which the data was partitioned based upon the value of the date column. If you attempt to add a row with a date that exceeds a date listed in the partitioning constraints, Advanced Server reports an error.
The following CREATE TABLE command creates the same table, but with a MAXVALUE partition. Instead of throwing an error, the server will store any rows that do not match the previous partitioning constraints in the others partition.
To test the MAXVALUE partition, add a row with a value in the date column that exceeds the last date value listed in a partitioning rule. The server will store the row in the others partition.
Querying the contents of the sales table confirms that the previously rejected row is now stored in the sales_others partition.
Please note that Advanced Server does not have a way to re-assign the contents of a MAXVALUE partition or subpartition.
You cannot use the ALTER TABLE… ADD PARTITION statement to add a partition to a table with a MAXVALUE rule, but you can use the ALTER TABLE… SPLIT PARTITION statement to split an existing partition.
You cannot use the ALTER TABLE… ADD SUBPARTITION statement to add a subpartition to a table with a MAXVALUE rule , but you can split an existing subpartition with the ALTER TABLE… SPLIT SUBPARTITION statement.