Commit 4fd48678 authored by Sergei Golubchik's avatar Sergei Golubchik

ALTER TABLE ... DROP COLUMN sys_start

update all unique keys, not just PK
parent dfd42ed9
......@@ -390,6 +390,23 @@ a b
2 NULL
3 1
4 2
create or replace table t (a int, b int primary key, c int unique) with system versioning;
insert t values (1,2,3),(1,3,4),(1,4,5);
alter table t drop system versioning;
show create table t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) NOT NULL,
`c` int(11) DEFAULT NULL,
PRIMARY KEY (`b`),
UNIQUE KEY `c` (`c`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from t;
a b c
1 2 3
1 3 4
1 4 5
create or replace table t (
a int,
row_start timestamp(6) as row start invisible,
......
......@@ -267,6 +267,12 @@ select * from t for system_time all;
insert into t values (4, 0);
select * from t for system_time all;
create or replace table t (a int, b int primary key, c int unique) with system versioning;
insert t values (1,2,3),(1,3,4),(1,4,5);
alter table t drop system versioning;
show create table t;
select * from t;
create or replace table t (
a int,
row_start timestamp(6) as row start invisible,
......
......@@ -7135,29 +7135,6 @@ bool Table_scope_and_contents_source_st::vers_fix_system_fields(
return false;
}
static bool is_dropping_primary_key(Alter_info *alter_info)
{
List_iterator_fast<Alter_drop> it(alter_info->drop_list);
while (Alter_drop *ad= it++)
{
if (ad->type == Alter_drop::KEY &&
!my_strcasecmp(system_charset_info, ad->name, primary_key_name))
return true;
}
return false;
}
static bool is_adding_primary_key(Alter_info *alter_info)
{
List_iterator_fast<Key> it(alter_info->key_list);
while (Key *key= it++)
{
if (key->type == Key::PRIMARY)
return true;
}
return false;
}
bool Vers_parse_info::fix_alter_info(THD *thd, Alter_info *alter_info,
HA_CREATE_INFO *create_info, TABLE *table)
{
......@@ -7188,42 +7165,6 @@ bool Vers_parse_info::fix_alter_info(THD *thd, Alter_info *alter_info,
return true;
}
if (share->primary_key != MAX_KEY && !is_adding_primary_key(alter_info) &&
!is_dropping_primary_key(alter_info))
{
alter_info->flags|= Alter_info::ALTER_DROP_INDEX;
Alter_drop *ad= new (thd->mem_root)
Alter_drop(Alter_drop::KEY, primary_key_name, false);
if (!ad || alter_info->drop_list.push_back(ad, thd->mem_root))
return true;
alter_info->flags|= Alter_info::ALTER_ADD_INDEX;
LEX_CSTRING key_name= {NULL, 0};
DDL_options_st options;
options.init();
Key *pk= new (thd->mem_root)
Key(Key::PRIMARY, &key_name, HA_KEY_ALG_UNDEF, false, options);
if (!pk)
return true;
st_key &key= table->key_info[share->primary_key];
for (st_key_part_info *it= key.key_part,
*end= it + key.user_defined_key_parts;
it != end; ++it)
{
if (it->field->vers_sys_field())
continue;
Key_part_spec *key_part_spec= new (thd->mem_root)
Key_part_spec(&it->field->field_name, it->length);
if (!key_part_spec ||
pk->columns.push_back(key_part_spec, thd->mem_root))
return true;
}
alter_info->key_list.push_back(pk);
}
return false;
}
......
......@@ -8260,9 +8260,10 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
bool delete_index_stat= FALSE;
for (uint j=0 ; j < key_info->user_defined_key_parts ; j++,key_part++)
{
if (!key_part->field)
Field *kfield= key_part->field;
if (!kfield)
continue; // Wrong field (from UNIREG)
const char *key_part_name=key_part->field->field_name.str;
const char *key_part_name=kfield->field_name.str;
Create_field *cfield;
uint key_part_length;
......@@ -8284,7 +8285,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
if (table->s->primary_key == i)
modified_primary_key= TRUE;
delete_index_stat= TRUE;
dropped_key_part= key_part_name;
if (!(kfield->flags & VERS_SYSTEM_FIELD))
dropped_key_part= key_part_name;
continue; // Field is removed
}
key_part_length= key_part->length;
......@@ -8321,10 +8323,10 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
cfield->real_field_type() <= MYSQL_TYPE_BLOB) ?
blob_length_by_type(cfield->real_field_type()) :
cfield->length) <
key_part_length / key_part->field->charset()->mbmaxlen)))
key_part_length / kfield->charset()->mbmaxlen)))
key_part_length= 0; // Use whole field
}
key_part_length /= key_part->field->charset()->mbmaxlen;
key_part_length /= kfield->charset()->mbmaxlen;
key_parts.push_back(new Key_part_spec(&cfield->field_name,
key_part_length),
thd->mem_root);
......
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