Skip to content

Commit

Permalink
ALTER TABLE ... DROP VERSIONING
Browse files Browse the repository at this point in the history
don't add columns to the drop list, INVISIBLE_SYSTEM columns
cannot be recognized as specified by the user
  • Loading branch information
vuvova committed Feb 12, 2018
1 parent 59ca71d commit bc0ac28
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
4 changes: 4 additions & 0 deletions mysql-test/suite/versioning/r/alter.result
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
set system_versioning_alter_history= keep;
alter table t add system versioning;
alter table t drop system versioning, drop column row_start;
ERROR 42000: Can't DROP COLUMN `row_start`; check that it exists
alter table t drop system versioning;
alter table t
add column trx_start bigint(20) unsigned as row start invisible,
add column trx_end bigint(20) unsigned as row end invisible,
Expand Down
5 changes: 5 additions & 0 deletions mysql-test/suite/versioning/t/alter.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ show create table t;

set system_versioning_alter_history= keep;

alter table t add system versioning;
--error ER_CANT_DROP_FIELD_OR_KEY
alter table t drop system versioning, drop column row_start;
alter table t drop system versioning;

--error ER_VERS_FIELD_WRONG_TYPE
alter table t
add column trx_start bigint(20) unsigned as row start invisible,
Expand Down
24 changes: 1 addition & 23 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7135,23 +7135,6 @@ bool Table_scope_and_contents_source_st::vers_fix_system_fields(
return false;
}

static bool add_field_to_drop_list_if_not_exists(THD *thd, Alter_info *alter_info, Field *field)
{
DBUG_ASSERT(field);
DBUG_ASSERT(field->field_name.str);
List_iterator_fast<Alter_drop> it(alter_info->drop_list);
while (Alter_drop *drop= it++)
{
if (!my_strcasecmp(system_charset_info, field->field_name.str, drop->name))
return false;
}

alter_info->flags|= Alter_info::ALTER_DROP_COLUMN;
Alter_drop *ad= new (thd->mem_root)
Alter_drop(Alter_drop::COLUMN, field->field_name.str, false);
return !ad || alter_info->drop_list.push_back(ad, thd->mem_root);
}

static bool is_dropping_primary_key(Alter_info *alter_info)
{
List_iterator_fast<Alter_drop> it(alter_info->drop_list);
Expand All @@ -7176,8 +7159,7 @@ static bool is_adding_primary_key(Alter_info *alter_info)
}

bool Vers_parse_info::fix_alter_info(THD *thd, Alter_info *alter_info,
HA_CREATE_INFO *create_info,
TABLE *table)
HA_CREATE_INFO *create_info, TABLE *table)
{
TABLE_SHARE *share= table->s;
const char *table_name= share->table_name.str;
Expand Down Expand Up @@ -7206,10 +7188,6 @@ bool Vers_parse_info::fix_alter_info(THD *thd, Alter_info *alter_info,
return true;
}

if (add_field_to_drop_list_if_not_exists(thd, alter_info, share->vers_start_field()) ||
add_field_to_drop_list_if_not_exists(thd, alter_info, share->vers_end_field()))
return true;

if (share->primary_key != MAX_KEY && !is_adding_primary_key(alter_info) &&
!is_dropping_primary_key(alter_info))
{
Expand Down
12 changes: 10 additions & 2 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7950,7 +7950,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
!my_strcasecmp(system_charset_info,field->field_name.str, drop->name))
break;
}
if (drop && (field->invisible < INVISIBLE_SYSTEM || field->vers_sys_field()))
if (drop && field->invisible < INVISIBLE_SYSTEM)
{
/* Reset auto_increment value if it was dropped */
if (MTYP_TYPENR(field->unireg_check) == Field::NEXT_NUMBER &&
Expand All @@ -7966,6 +7966,14 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
bitmap_set_bit(dropped_fields, field->field_index);
continue;
}
if (!drop && field->invisible == INVISIBLE_SYSTEM &&
field->flags & VERS_SYSTEM_FIELD &&
alter_info->flags & Alter_info::ALTER_DROP_SYSTEM_VERSIONING)
{
if (table->s->tmp_table == NO_TMP_TABLE)
(void) delete_statistics_for_column(thd, table, field);
continue;
}
/* Check if field is changed */
def_it.rewind();
while ((def=def_it++))
Expand All @@ -7975,7 +7983,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
&def->change))
break;
}
if (def && (field->invisible < INVISIBLE_SYSTEM || field->vers_sys_field()))
if (def && field->invisible < INVISIBLE_SYSTEM)
{ // Field is changed
def->field=field;
/*
Expand Down

0 comments on commit bc0ac28

Please sign in to comment.