Suppose you submit the following ALTER TABLE request on orders.
ALTER TABLE orders MODIFY PRIMARY INDEX DROP RANGE BETWEEN 0 AND 9 EACH 10 ADD RANGE BETWEEN 51 AND 70 EACH 10, DROP RANGE BETWEEN 100 AND 100 ADD RANGE -100 TO -2;
This alters the row partitioning expressions to be the following expressions.
RANGE_N(o_custkey1 BETWEEN 10 AND 50 EACH 10, 51 AND 70 EACH 10), RANGE_N(o_custkey2 BETWEEN -100 AND -2, 0 AND 99 EACH 10)
That is, the table definition after you have performed the ALTER TABLE request is as follows.
CREATE TABLE orders ( o_orderkey INTEGER NOT NULL, o_custkey1 INTEGER, o_custkey2 INTEGER) PRIMARY INDEX (o_orderkey) PARTITION BY (RANGE_N(o_custkey1 BETWEEN 10 AND 50 EACH 10, /* p1 */ 51 AND 70 EACH 10), RANGE_N(o_custkey2 BETWEEN -100 AND -2, 0 AND 99 EACH 10)) /* p2 */;
This changes the information implied by the initial table definition about the row partitioning of orders as follows.
- Number of partitions in the first, and highest, level = d1 = 7
- Number of partitions in the second, and lowest, level = d2 = 11
- Total number of combined partitions = d1 * d2 = 7 * 11 = 77
- Combined partitioning expression = (p1 - 1) * d2 + p2 = (p1 - 1) * 11 + p2
Now if o_custkey1 is 15 and o_custkey2 is 55, the following additional information is implied.
- Partition number for level 1 = PARTITION#L1 = p1(15) = 1.
- Partition number for level 2 = PARTITION#L2 = p2(55) = 7.
- PARTITION#L3 through PARTITION#L15 are all 0.
- Combined partition number = PARTITION = (1-1)*11 + 7 = 7.
The following cases provide examples of how multilevel row partitioning may be useful.
SELECT * FROM orders WHERE o_custkey1 = 15;
There may be qualifying rows in the row partitions where the combined partition numbers are in the range (1-1)*11 + (1 TO 11) = 1 TO 11.
SELECT * FROM orders WHERE (o_custkey1 = 15 OR o_custkey1 = 25) AND o_custkey2 BETWEEN 20 AND 50;
There may be qualifying rows in the row partitions where the combined partition numbers are in the ranges 4 TO 7 and 15 TO 18.
SELECT * FROM orders WHERE o_custkey2 BETWEEN 42 AND 47;
There may be qualifying rows in the row partitions where the combined partition number is any of the following.
- 6
- 17
- 28
- 39
- 50
- 61
- 72