Commit 6b8d34fe authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-14668 ADD PRIMARY KEY IF NOT EXISTS on composite key.

Check the name of the primary key to be 'PRIMARY'. Than
differs it from any implicit primary keys created by an engine.
parent 0ad9c3a0
......@@ -2225,3 +2225,26 @@ t1 CREATE TABLE `t1` (
`b` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
DROP TABLE t1;
#
# MDEV-14668 ADD PRIMARY KEY IF NOT EXISTS on composite key
#
CREATE TABLE t1 (
`ID` BIGINT(20) NOT NULL,
`RANK` MEDIUMINT(4) NOT NULL,
`CHECK_POINT` BIGINT(20) NOT NULL,
UNIQUE INDEX `HORIZON_UIDX01` (`ID`, `RANK`)
) ENGINE=InnoDB;
ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`ID` bigint(20) NOT NULL,
`RANK` mediumint(4) NOT NULL,
`CHECK_POINT` bigint(20) NOT NULL,
PRIMARY KEY (`ID`,`CHECK_POINT`),
UNIQUE KEY `HORIZON_UIDX01` (`ID`,`RANK`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`);
Warnings:
Note 1061 Multiple primary key defined
DROP TABLE t1;
......@@ -1841,3 +1841,19 @@ CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN IF EXISTS c;
SHOW CREATE TABLE t1;
DROP TABLE t1;
--echo #
--echo # MDEV-14668 ADD PRIMARY KEY IF NOT EXISTS on composite key
--echo #
CREATE TABLE t1 (
`ID` BIGINT(20) NOT NULL,
`RANK` MEDIUMINT(4) NOT NULL,
`CHECK_POINT` BIGINT(20) NOT NULL,
UNIQUE INDEX `HORIZON_UIDX01` (`ID`, `RANK`)
) ENGINE=InnoDB;
ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`);
SHOW CREATE TABLE t1;
ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`);
DROP TABLE t1;
......@@ -5930,7 +5930,9 @@ handle_if_exists_options(THD *thd, TABLE *table, Alter_info *alter_info)
/* Check if the table already has a PRIMARY KEY */
if (key->type == Key::PRIMARY &&
table->s->primary_key != MAX_KEY)
table->s->primary_key != MAX_KEY &&
(keyname= table->s->key_info[table->s->primary_key].name) &&
my_strcasecmp(system_charset_info, keyname, primary_key_name) == 0)
{
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_DUP_KEYNAME, ER(ER_MULTIPLE_PRI_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