mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
better fix BUG#2361: ALTER TABLE ... DROP PRIMARY KEY drops a non-primary key
This commit is contained in:
parent
d01e810128
commit
832ea1206d
8 changed files with 20 additions and 24 deletions
|
@ -412,12 +412,15 @@ t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE
|
|||
t1 0 PRIMARY 2 User A 0 NULL NULL BTREE
|
||||
t1 1 Host 1 Host A NULL NULL NULL BTREE disabled
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (a int UNIQUE);
|
||||
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE);
|
||||
ALTER TABLE t1 DROP PRIMARY KEY;
|
||||
SHOW CREATE TABLE t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`a` int(11) default NULL,
|
||||
UNIQUE KEY `a` (`a`)
|
||||
`a` int(11) NOT NULL default '0',
|
||||
`b` int(11) default NULL,
|
||||
UNIQUE KEY `b` (`b`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
ALTER TABLE t1 DROP PRIMARY KEY;
|
||||
ERROR 42000: Can't DROP 'PRIMARY'. Check that column/key exists
|
||||
DROP TABLE t1;
|
||||
|
|
|
@ -249,7 +249,9 @@ DROP TABLE t1;
|
|||
# Bug 2361
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (a int UNIQUE);
|
||||
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE);
|
||||
ALTER TABLE t1 DROP PRIMARY KEY;
|
||||
SHOW CREATE TABLE t1;
|
||||
--error 1091
|
||||
ALTER TABLE t1 DROP PRIMARY KEY;
|
||||
DROP TABLE t1;
|
||||
|
|
|
@ -509,7 +509,6 @@ int mysql_alter_table(THD *thd, char *new_db, char *new_name,
|
|||
List<Key> &keys,List<Alter_drop> &drop_list,
|
||||
List<Alter_column> &alter_list,
|
||||
uint order_num, ORDER *order,
|
||||
bool drop_primary,
|
||||
enum enum_duplicates handle_duplicates,
|
||||
enum enum_enable_or_disable keys_onoff=LEAVE_AS_IS,
|
||||
enum tablespace_op_type tablespace_op=NO_TABLESPACE_OP,
|
||||
|
|
|
@ -2395,7 +2395,7 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
|
|||
create_info.default_table_charset= thd->variables.collation_database;
|
||||
DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
|
||||
&create_info, table_list,
|
||||
fields, keys, drop, alter, 0, (ORDER*)0, FALSE,
|
||||
fields, keys, drop, alter, 0, (ORDER*)0,
|
||||
DUP_ERROR));
|
||||
}
|
||||
|
||||
|
@ -2412,7 +2412,7 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, List<Alter_drop> &drop)
|
|||
create_info.default_table_charset= thd->variables.collation_database;
|
||||
DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
|
||||
&create_info, table_list,
|
||||
fields, keys, drop, alter, 0, (ORDER*)0, FALSE,
|
||||
fields, keys, drop, alter, 0, (ORDER*)0,
|
||||
DUP_ERROR));
|
||||
}
|
||||
|
||||
|
|
|
@ -575,7 +575,7 @@ typedef struct st_lex
|
|||
uint param_count;
|
||||
uint slave_thd_opt;
|
||||
uint8 describe;
|
||||
bool drop_primary, drop_if_exists, drop_temporary, local_file;
|
||||
bool drop_if_exists, drop_temporary, local_file;
|
||||
bool in_comment, ignore_space, verbose, simple_alter, no_write_to_binlog;
|
||||
bool derived_tables;
|
||||
bool safe_to_cache_query;
|
||||
|
|
|
@ -2319,7 +2319,7 @@ mysql_execute_command(THD *thd)
|
|||
lex->key_list, lex->drop_list, lex->alter_list,
|
||||
select_lex->order_list.elements,
|
||||
(ORDER *) select_lex->order_list.first,
|
||||
lex->drop_primary, lex->duplicates,
|
||||
lex->duplicates,
|
||||
lex->alter_keys_onoff,
|
||||
lex->tablespace_op,
|
||||
lex->simple_alter);
|
||||
|
@ -2466,7 +2466,7 @@ mysql_execute_command(THD *thd)
|
|||
tables, lex->create_list,
|
||||
lex->key_list, lex->drop_list, lex->alter_list,
|
||||
0, (ORDER *) 0,
|
||||
0, DUP_ERROR);
|
||||
DUP_ERROR);
|
||||
}
|
||||
else
|
||||
res = mysql_optimize_table(thd, tables, &lex->check_opt);
|
||||
|
|
|
@ -1962,7 +1962,6 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
|||
List<Key> &keys,List<Alter_drop> &drop_list,
|
||||
List<Alter_column> &alter_list,
|
||||
uint order_num, ORDER *order,
|
||||
bool drop_primary,
|
||||
enum enum_duplicates handle_duplicates,
|
||||
enum enum_enable_or_disable keys_onoff,
|
||||
enum tablespace_op_type tablespace_op,
|
||||
|
@ -2171,7 +2170,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
|||
def_it.rewind();
|
||||
while ((def=def_it++))
|
||||
{
|
||||
if (def->change &&
|
||||
if (def->change &&
|
||||
!my_strcasecmp(system_charset_info,field->field_name, def->change))
|
||||
break;
|
||||
}
|
||||
|
@ -2265,14 +2264,6 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
|||
for (uint i=0 ; i < table->keys ; i++,key_info++)
|
||||
{
|
||||
char *key_name= key_info->name;
|
||||
|
||||
if (drop_primary && (key_info-> flags & HA_NOSAME) &&
|
||||
!my_strcasecmp(system_charset_info, key_name, primary_key_name))
|
||||
{
|
||||
drop_primary= 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
Alter_drop *drop;
|
||||
drop_it.rewind();
|
||||
while ((drop=drop_it++))
|
||||
|
@ -2315,7 +2306,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
|||
{ // Check if sub key
|
||||
if (cfield->field->type() != FIELD_TYPE_BLOB &&
|
||||
(cfield->field->pack_length() == key_part_length ||
|
||||
cfield->length <= key_part_length /
|
||||
cfield->length <= key_part_length /
|
||||
key_part->field->charset()->mbmaxlen))
|
||||
key_part_length=0; // Use whole field
|
||||
}
|
||||
|
|
|
@ -1689,7 +1689,6 @@ alter:
|
|||
if (!lex->select_lex.add_table_to_list(thd, $4, NULL,
|
||||
TL_OPTION_UPDATING))
|
||||
YYABORT;
|
||||
lex->drop_primary=0;
|
||||
lex->create_list.empty();
|
||||
lex->key_list.empty();
|
||||
lex->col_list.empty();
|
||||
|
@ -1761,12 +1760,14 @@ alter_list_item:
|
|||
lex->drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
|
||||
$3.str)); lex->simple_alter=0;
|
||||
}
|
||||
| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
|
||||
| DROP PRIMARY_SYM KEY_SYM
|
||||
{
|
||||
LEX *lex=Lex;
|
||||
lex->drop_primary=1; lex->simple_alter=0;
|
||||
lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
|
||||
primary_key_name));
|
||||
lex->simple_alter=0;
|
||||
}
|
||||
| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
|
||||
| DROP key_or_index field_ident
|
||||
{
|
||||
LEX *lex=Lex;
|
||||
|
|
Loading…
Reference in a new issue