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 calledsales
PARTITION BY RANGE (sale_date)
: partitions the table by range, using thesale_date
columnPARTITION p0 VALUES LESS THAN ('2020-01-01')
: creates a partition for data with asale_date
before 2020-01-01PARTITION p5 VALUES LESS THAN (MAXVALUE)
: creates a partition for data with asale_date
after all other partitions
Helpful links
More of Mariadb
- What type to use for a year in Mariadb?
- How to use UUID in Mariadb?
- How to install Mariadb on Ubuntu?
- How to work with XML in Mariadb?
- How to get current year in Mariadb?
- How to check version of Mariadb?
- How to use xtrabackup in Mariadb?
- How to use window functions in Mariadb?
- How to use variables in Mariadb?
See more codes...