Table Partitioning
Partitioning splits a large table into sub-tables based on a key (range, list, hash). Queries that filter on the partition key only scan relevant partitions.
Partitioning splits a large table into sub-tables based on a key (range, list, hash). Queries that filter on the partition key only scan relevant partitions.
CREATE TABLE sales (
id INT,
sale_date DATE,
amount DECIMAL(10,2)
)
PARTITION BY RANGE (YEAR(sale_date)) (
PARTITION p2022 VALUES LESS THAN (2023),
PARTITION p2023 VALUES LESS THAN (2024),
PARTITION p2024 VALUES LESS THAN (2025)
);
Partitioning is most beneficial for tables with hundreds of millions of rows.