mariadbMariadb partitioning example
Partitioning in MariaDB is a way to divide a large table into smaller, more manageable parts. It can improve query performance and reduce storage space.
Example
CREATE TABLE sales (
id INT NOT NULL,
sale_date DATE NOT NULL,
amount DECIMAL(10,2) NOT NULL,
PRIMARY KEY (id)
)
PARTITION BY RANGE (sale_date) (
PARTITION p0 VALUES LESS THAN ('2020-01-01'),
PARTITION p1 VALUES LESS THAN ('2020-02-01'),
PARTITION p2 VALUES LESS THAN ('2020-03-01'),
PARTITION p3 VALUES LESS THAN ('2020-04-01'),
PARTITION p4 VALUES LESS THAN ('2020-05-01'),
PARTITION p5 VALUES LESS THAN (MAXVALUE)
);
This example creates a table called sales with a sale_date column. The table is partitioned by range, with each partition containing data for a single month.
Code explanation
CREATE TABLE sales: creates a table calledsalesPARTITION BY RANGE (sale_date): partitions the table by range, using thesale_datecolumnPARTITION p0 VALUES LESS THAN ('2020-01-01'): creates a partition for data with asale_datebefore 2020-01-01PARTITION p5 VALUES LESS THAN (MAXVALUE): creates a partition for data with asale_dateafter all other partitions
Helpful links
More of Mariadb
- How to change wait_timeout in Mariadb?
- How to check version of Mariadb?
- How to use the WITH clause in Mariadb?
- How to use UUID in Mariadb?
- How to use window functions in Mariadb?
- How to get current year in Mariadb?
- What type to use for a year in Mariadb?
- How to use XA transactions in Mariadb?
- How to list users in Mariadb?
See more codes...