Bug#6236

  Incomplete ALTER TABLE breaks MERGE compatibility
  Fix implicit NOT NULL not set on ALTER of PK columns
parent bc27c14e
...@@ -9,6 +9,7 @@ acurtis@pcgem.rdg.cyberkinetica.com ...@@ -9,6 +9,7 @@ acurtis@pcgem.rdg.cyberkinetica.com
ahlentz@co3064164-a.rochd1.qld.optusnet.com.au ahlentz@co3064164-a.rochd1.qld.optusnet.com.au
akishkin@work.mysql.com akishkin@work.mysql.com
antony@ltantony.dsl-verizon.net antony@ltantony.dsl-verizon.net
antony@ltantony.mysql.com
antony@ltantony.rdg.cyberkinetica.homeunix.net antony@ltantony.rdg.cyberkinetica.homeunix.net
arjen@bitbike.com arjen@bitbike.com
arjen@co3064164-a.bitbike.com arjen@co3064164-a.bitbike.com
......
...@@ -386,3 +386,23 @@ Incorrect table name 't1\\' ...@@ -386,3 +386,23 @@ Incorrect table name 't1\\'
rename table t1 to `t1\\`; rename table t1 to `t1\\`;
Incorrect table name 't1\\' Incorrect table name 't1\\'
drop table t1; drop table t1;
drop table if exists t1, t2;
create table t1 ( a varchar(10) not null primary key ) engine=myisam;
create table t2 ( a varchar(10) not null primary key ) engine=merge union=(t1);
flush tables;
alter table t1 modify a varchar(10);
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` varchar(10) NOT NULL default '',
PRIMARY KEY (`a`)
) TYPE=MRG_MyISAM UNION=(t1)
flush tables;
alter table t1 modify a varchar(10) not null;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` varchar(10) NOT NULL default '',
PRIMARY KEY (`a`)
) TYPE=MRG_MyISAM UNION=(t1)
drop table if exists t1, t2;
...@@ -254,3 +254,16 @@ alter table t1 rename to `t1\\`; ...@@ -254,3 +254,16 @@ alter table t1 rename to `t1\\`;
rename table t1 to `t1\\`; rename table t1 to `t1\\`;
drop table t1; drop table t1;
#
# BUG#6236 - ALTER TABLE MODIFY should set implicit NOT NULL on PK columns
#
drop table if exists t1, t2;
create table t1 ( a varchar(10) not null primary key ) engine=myisam;
create table t2 ( a varchar(10) not null primary key ) engine=merge union=(t1);
flush tables;
alter table t1 modify a varchar(10);
show create table t2;
flush tables;
alter table t1 modify a varchar(10) not null;
show create table t2;
drop table if exists t1, t2;
...@@ -1795,6 +1795,11 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -1795,6 +1795,11 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
} }
KEY_PART_INFO *key_part= key_info->key_part; KEY_PART_INFO *key_part= key_info->key_part;
enum Key::Keytype key_type= key_info->flags & HA_NOSAME ?
(!my_strcasecmp(key_name, "PRIMARY") ?
Key::PRIMARY : Key::UNIQUE) :
(key_info->flags & HA_FULLTEXT ?
Key::FULLTEXT : Key::MULTIPLE);
key_parts.empty(); key_parts.empty();
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++) for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
{ {
...@@ -1824,16 +1829,22 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -1824,16 +1829,22 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
cfield->pack_length <= key_part_length)) cfield->pack_length <= key_part_length))
key_part_length=0; // Use whole field key_part_length=0; // Use whole field
} }
if (!(cfield->flags & NOT_NULL_FLAG))
{
if (key_type == Key::PRIMARY)
{
/* Implicitly set primary key fields to NOT NULL for ISO conf. */
cfield->flags|= NOT_NULL_FLAG;
cfield->pack_flag&= ~FIELDFLAG_MAYBE_NULL;
}
else
key_info->flags|= HA_NULL_PART_KEY;
}
key_parts.push_back(new key_part_spec(cfield->field_name, key_parts.push_back(new key_part_spec(cfield->field_name,
key_part_length)); key_part_length));
} }
if (key_parts.elements) if (key_parts.elements)
key_list.push_back(new Key(key_info->flags & HA_NOSAME ? key_list.push_back(new Key(key_type,key_name,key_parts));
(!my_strcasecmp(key_name, "PRIMARY") ?
Key::PRIMARY : Key::UNIQUE) :
(key_info->flags & HA_FULLTEXT ?
Key::FULLTEXT : Key::MULTIPLE),
key_name,key_parts));
} }
key_it.rewind(); key_it.rewind();
{ {
......
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