Commit 37e5db5c authored by Yuchen Pei's avatar Yuchen Pei

MDEV-24610 Check for partition auto increment overflow

When ha_partition::info() is called with a flag containing
HA_STATUS_AUTO, it may iterate partitions and call info() on them with
HA_STATUS_AUTO, and update its own auto increment value with the
maximum of the partitions.

When info() is called on the MEMORY SE, it could cause an overflow
when its internal auto increment value is already ULONGLONG_MAX,
thereby setting the table stats auto increment value to 0.

If such an overflow happens, we return an error in
ha_partition::info() indicating so.

Note that callsites of ha_partition::update_next_auto_inc_val(), which
calls ha_partition::info() with HA_STATUS_AUTO, do not handle any
returned error.
parent 81cd539e
CREATE TABLE t (c BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=MEMORY PARTITION BY KEY();
INSERT INTO t VALUES (18446744073709551615);
drop table t;
CREATE TABLE t (c BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=MEMORY;
INSERT INTO t VALUES (18446744073709551615);
ALTER TABLE t PARTITION BY KEY();
INSERT INTO t VALUES (1);
drop table t;
CREATE TABLE t (c BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=MEMORY;
INSERT INTO t VALUES (18446744073709551615);
ALTER TABLE t PARTITION BY KEY();
INSERT INTO t VALUES (NULL);
ERROR 22003: Out of range value for column 'c' at row 1
drop table t;
--source include/have_partition.inc
CREATE TABLE t (c BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=MEMORY PARTITION BY KEY();
INSERT INTO t VALUES (18446744073709551615);
drop table t;
CREATE TABLE t (c BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=MEMORY;
INSERT INTO t VALUES (18446744073709551615);
ALTER TABLE t PARTITION BY KEY();
INSERT INTO t VALUES (1);
drop table t;
CREATE TABLE t (c BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=MEMORY;
INSERT INTO t VALUES (18446744073709551615);
ALTER TABLE t PARTITION BY KEY();
--error HA_ERR_AUTOINC_ERANGE
INSERT INTO t VALUES (NULL);
drop table t;
......@@ -8388,6 +8388,11 @@ int ha_partition::info(uint flag)
unlock_auto_increment();
DBUG_RETURN(error);
}
if (file->stats.auto_increment_value == 0)
{
unlock_auto_increment();
DBUG_RETURN(HA_ERR_AUTOINC_ERANGE);
}
set_if_bigger(auto_increment_value,
file->stats.auto_increment_value);
} while (*(++file_array));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment