List partitioning is similar to range partitioning in many ways. As in partitioning by RANGE, each partition must be explicitly defined. The chief difference between the two types of partitioning is that, in list partitioning, each partition is defined and selected based on the membership of a column value in one of a set of value lists, rather than in one of a set of contiguous ranges of values. This is done by using
PARTITION BY LIST(expr) where
expr is a column value or an expression based on a column value and returning an integer value, and then defining each partition by means of a
VALUES IN (value_list), where
value_list is a comma-separated list of integers.
For the examples that follow, we assume that the basic definition of the table to be partitioned is provided by the
CREATE TABLE statement shown here:
CREATE TABLE employees ( id INT NOT NULL, fname VARCHAR(30), lname VARCHAR(30), hired DATE NOT NULL DEFAULT '1970-01-01', separated DATE NOT NULL DEFAULT '9999-12-31', job_code INT, store_id INT );
Suppose that there are 20 video stores distributed among 4 franchises as shown in the following table.
|Region||Store ID Numbers|
|North||3, 5, 6, 9, 17|
|East||1, 2, 10, 11, 19, 20|
|West||4, 12, 13, 14, 18|
|Central||7, 8, 15, 16|
To partition this table in such a way that rows for stores belonging to the same region are stored in the same partition
ALTER TABLE employees PARTITION BY LIST(store_id) ( PARTITION pNorth VALUES IN (3,5,6,9,17), PARTITION pEast VALUES IN (1,2,10,11,19,20), PARTITION pWest VALUES IN (4,12,13,14,18), PARTITION pCentral VALUES IN (7,8,15,16) );
based on MySQL official document.