MySQL MariaDB

What is MySQL List Partitioning

Partitioning of a MySQL database is a process in which data placed in the tables is further divided into small tables; which makes it easy to handle the large size of data. MySQL is a database that is very much popular among SQL databases to manage the data.

MySQL supports only horizontal partitioning. In MySQL, there are six types of partitioning, one of them is List partitioning, which is going to be explained in this article with the help of an example.

What is the List Partitioning in MySQL

In MySQL, List partitioning is used similar to range partitioning, the difference is that, in range partitioning, we have to define the range on the basis of which it partitioned the data whereas, in the List partition, it partitions the data on the basis of pre-defined information, to understand this by creating a table of the products_data and we will partition the data on the basis of the products and create a table using the command:

CREATE TABLE products_data (rep_id INT NOT NULL, rep_name VARCHAR(50) NOT NULL, prod_id INT NOT NULL) PARTITION BY LIST (prod_id) (PARTITION a VALUES IN (11), PARTITION b VALUES IN (22), PARTITION c VALUES IN (33), PARTITION d VALUES IN (44));

To insert values in the newly created table, run the command:

INSERT INTO products_data VALUES (1, ‘John’, 11), (2,’Paul’, 22), (3,’Rogger’, 44), (4,’Somio’, 11), (5,’Alaxender’, 33), (6,’Micheal’,11);

The data can be displayed in the table, products_data:

SELECT * FROM products_data;

To insert a value against the list partition which is not predefined and let us see what happened:

INSERT INTO products_data VALUES (7, ‘Tom’, 77);

In the above output, we can see that the error has been displayed as no partition has been defined for “77” so it generated an error for the value inserted against the partition “77”, which means in the List partition, data is inserted only against the pre-defined partitions.

It is important to note here that in the List partition while inserting the values, the table will allow only those values which will fulfill the definition of the List partition.

Conclusion

Partitioning is a process by which tables of MySQL are divided into further tables and this makes it easy for the user to manage the data as well as for the processor of the computer to execute the queries. List partitioning is the type of partitioning in which the partitions are pre-defined and the data inserted in the tables according to these pre-defined partitions. In this write-up, we explained the List partition with the help of an example and also demonstrated that if the value is inserted against the definition of List partition, it does not accept it and generates the error.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.