Commit 196528eb authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-8212 alter table - failing to ADD PRIMARY KEY IF NOT EXISTS when existing...

MDEV-8212 alter table - failing to ADD PRIMARY KEY IF NOT EXISTS when existing index of same as column name.
        The default name for the primary key is rather 'PRIMARY' instead of the indexed column name.
parent fc31e311
......@@ -1488,6 +1488,17 @@ t2 CREATE TABLE `t2` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
DROP TABLE t1;
CREATE TABLE t1 (
`transaction_id` int(11) NOT NULL DEFAULT '0',
KEY `transaction_id` (`transaction_id`));
ALTER TABLE t1 DROP KEY IF EXISTS transaction_id, ADD PRIMARY KEY IF NOT EXISTS (transaction_id);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`transaction_id` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`transaction_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
# Bug#11748057 (formerly known as 34972): ALTER TABLE statement doesn't
# identify correct column name.
#
......
......@@ -1326,6 +1326,14 @@ SHOW CREATE TABLE t2;
DROP TABLE t2;
DROP TABLE t1;
CREATE TABLE t1 (
`transaction_id` int(11) NOT NULL DEFAULT '0',
KEY `transaction_id` (`transaction_id`));
ALTER TABLE t1 DROP KEY IF EXISTS transaction_id, ADD PRIMARY KEY IF NOT EXISTS (transaction_id);
SHOW CREATE TABLE t1;
DROP TABLE t1;
--echo # Bug#11748057 (formerly known as 34972): ALTER TABLE statement doesn't
--echo # identify correct column name.
--echo #
......
......@@ -5859,12 +5859,17 @@ drop_create_field:
/* let us check the name of the first key part. */
if ((keyname= key->name.str) == NULL)
{
List_iterator<Key_part_spec> part_it(key->columns);
Key_part_spec *kp;
if ((kp= part_it++))
keyname= kp->field_name.str;
if (keyname == NULL)
continue;
if (key->type == Key::PRIMARY)
keyname= primary_key_name;
else
{
List_iterator<Key_part_spec> part_it(key->columns);
Key_part_spec *kp;
if ((kp= part_it++))
keyname= kp->field_name.str;
if (keyname == NULL)
continue;
}
}
if (key->type != Key::FOREIGN_KEY)
{
......
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