Commit 5f0c98c1 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-5743 Server crashes in mysql_alter_table on an attempt to add a primary key to InnoDB table

parent e82a82ee
......@@ -16,3 +16,11 @@ insert t1 values (repeat('3', 8193),3,1,1);
ALTER TABLE t1 ADD PRIMARY KEY (col4(10)) , ADD UNIQUE KEY uidx (col3);
ERROR 23000: Duplicate entry '1' for key 'uidx'
DROP TABLE t1;
CREATE TABLE t1 (a INT) ENGINE = InnoDB;
INSERT INTO t1 VALUES (2);
ALTER TABLE t1 ADD PRIMARY KEY (a);
ALTER TABLE t1 DROP PRIMARY KEY;
INSERT INTO t1 VALUES (2);
ALTER TABLE t1 ADD PRIMARY KEY (a);
ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
DROP TABLE t1;
......@@ -32,4 +32,16 @@ insert t1 values (repeat('3', 8193),3,1,1);
ALTER TABLE t1 ADD PRIMARY KEY (col4(10)) , ADD UNIQUE KEY uidx (col3);
DROP TABLE t1;
#
# MDEV-5743 Server crashes in mysql_alter_table on an attempt to add a primary key to InnoDB table
#
CREATE TABLE t1 (a INT) ENGINE = InnoDB;
INSERT INTO t1 VALUES (2);
ALTER TABLE t1 ADD PRIMARY KEY (a);
ALTER TABLE t1 DROP PRIMARY KEY;
INSERT INTO t1 VALUES (2);
--error ER_DUP_ENTRY
ALTER TABLE t1 ADD PRIMARY KEY (a);
DROP TABLE t1;
......@@ -6908,7 +6908,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (is_PK(key_info))
{
merged[0]= key_info[0];
if (is_PK(table->key_info))
if (table->key_info && is_PK(table->key_info))
{
old_cnt--;
table->key_info++;
......
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