mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
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.
This commit is contained in:
@ -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 #
|
||||
|
@ -5858,6 +5858,10 @@ drop_create_field:
|
||||
/* If the name of the key is not specified, */
|
||||
/* let us check the name of the first key part. */
|
||||
if ((keyname= key->name.str) == NULL)
|
||||
{
|
||||
if (key->type == Key::PRIMARY)
|
||||
keyname= primary_key_name;
|
||||
else
|
||||
{
|
||||
List_iterator<Key_part_spec> part_it(key->columns);
|
||||
Key_part_spec *kp;
|
||||
@ -5866,6 +5870,7 @@ drop_create_field:
|
||||
if (keyname == NULL)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (key->type != Key::FOREIGN_KEY)
|
||||
{
|
||||
for (n_key=0; n_key < table->s->keys; n_key++)
|
||||
|
Reference in New Issue
Block a user