Error
Error Code:
1479
MySQL Error 1479: Missing Partition Values Definition
Description
This error indicates a syntax problem when defining partitions for a MySQL table. It arises when creating or altering a table that uses RANGE or LIST partitioning, but the `VALUES` clause is either missing or improperly specified for one or more partitions. MySQL requires explicit value definitions for each individual partition.
Error Message
Syntax error: %s PARTITIONING requires definition of VALUES %s for each partition
Known Causes
3 known causesMissing VALUES Clause
When defining `RANGE` or `LIST` partitions, the `VALUES` clause (e.g., `VALUES LESS THAN`, `VALUES IN`) is entirely omitted for one or more individual partitions.
Invalid VALUES Syntax
The `VALUES` clause is present but contains a syntax error, such as mismatched parentheses, incorrect keywords, or data types incompatible with the partitioning column.
Incomplete Partition Coverage
For `RANGE` or `LIST` partitioning, the defined `VALUES` do not cover all necessary ranges or discrete values, leaving gaps or undefined sets that MySQL cannot assign.
Solutions
3 solutions available1. Correctly Define Partition Values in `CREATE TABLE` easy
Ensure all `VALUES` clauses are present and correctly formatted for each partition in your `CREATE TABLE` statement.
1
Review your `CREATE TABLE` statement carefully. The error message `Missing Partition Values Definition` indicates that for a partitioning type that requires explicit value definitions (like `RANGE` or `LIST`), you've omitted or incorrectly formatted the `VALUES` clause for one or more partitions.
Example of incorrect syntax:
CREATE TABLE my_table (
id INT PRIMARY KEY,
data VARCHAR(50)
) PARTITION BY RANGE (id) (
PARTITION p0 VALUES LESS THAN (10),
PARTITION p1 VALUES LESS THAN (20),
PARTITION p2 -- Missing VALUES clause here
);
2
For `RANGE` partitioning, each `PARTITION` definition must include `VALUES LESS THAN (value)`. For `LIST` partitioning, each `PARTITION` definition must include `VALUES IN (value1, value2, ...)`.
Example of correct syntax for `RANGE` partitioning:
CREATE TABLE my_table (
id INT PRIMARY KEY,
data VARCHAR(50)
) PARTITION BY RANGE (id) (
PARTITION p0 VALUES LESS THAN (10),
PARTITION p1 VALUES LESS THAN (20),
PARTITION p2 VALUES LESS THAN MAXVALUE -- Or a specific upper bound
);
3
Ensure that the last partition in a `RANGE` partitioning scheme correctly handles the remaining values. Using `MAXVALUE` is a common and effective way to achieve this.
Example for `LIST` partitioning:
CREATE TABLE sales (
id INT,
region VARCHAR(50)
) PARTITION BY LIST (region) (
PARTITION r0 VALUES IN ('North', 'South'),
PARTITION r1 VALUES IN ('East', 'West'),
PARTITION r2 VALUES IN ('Central')
);
2. Add Missing Partition Definitions to an Existing Table medium
Use `ALTER TABLE` to add the necessary `VALUES` clauses to partitions that are missing them in a table that is already partitioned.
1
First, identify which partitions are missing their `VALUES` definitions. You can inspect the table's structure using `SHOW CREATE TABLE table_name;`.
SHOW CREATE TABLE your_table_name;
2
Once identified, use the `ALTER TABLE ... ADD PARTITION` statement to add the missing partition definition with the correct `VALUES` clause. The exact syntax depends on whether you are using `RANGE` or `LIST` partitioning.
For RANGE partitioning (assuming you need to add a partition for values >= 20 and < 30):
ALTER TABLE your_table_name
ADD PARTITION (PARTITION p3 VALUES LESS THAN (30));
3
If you are using LIST partitioning and need to add a partition for a specific value (e.g., 'Northwest'):
ALTER TABLE your_table_name
ADD PARTITION (PARTITION p_nw VALUES IN ('Northwest'));
ALTER TABLE your_table_name
ADD PARTITION (PARTITION p_nw VALUES IN ('Northwest'));
4
Be aware that adding partitions might involve data redistribution if the new partition's values overlap with existing ones in a way that requires it. For simple additions of missing partitions, this is usually straightforward.
If you are modifying an existing partition (less common for this specific error, but possible if a definition was partially defined):
ALTER TABLE your_table_name
REORGANIZE PARTITION p2 INTO (
PARTITION p2 VALUES LESS THAN (25)
);
3. Recreate Table with Correct Partitioning advanced
If the partitioning scheme is complex or has been misconfigured, recreating the table with a correct definition is a robust solution.
1
Obtain the current `CREATE TABLE` statement for the problematic table using `SHOW CREATE TABLE your_table_name;`.
SHOW CREATE TABLE your_table_name;
2
Create a temporary table with the same schema but without partitioning, or with a corrected partitioning definition. Ensure all partitions have their `VALUES` clauses correctly specified.
CREATE TABLE your_table_name_temp (
id INT PRIMARY KEY,
data VARCHAR(50)
) PARTITION BY RANGE (id) (
PARTITION p0 VALUES LESS THAN (10),
PARTITION p1 VALUES LESS THAN (20),
PARTITION p2 VALUES LESS THAN MAXVALUE
);
3
Copy the data from the original table to the temporary table.
INSERT INTO your_table_name_temp (id, data)
SELECT id, data FROM your_table_name;
4
Drop the original table.
DROP TABLE your_table_name;
5
Rename the temporary table to the original table name.
RENAME TABLE your_table_name_temp TO your_table_name;