mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
ALTER TABLE ... DROP VERSIONING
don't add columns to the drop list, INVISIBLE_SYSTEM columns cannot be recognized as specified by the user
This commit is contained in:
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
@ -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;
|
||||
@ -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))
|
||||
{
|
||||
|
@ -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 &&
|
||||
@ -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++))
|
||||
@ -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;
|
||||
/*
|
||||
|
Reference in New Issue
Block a user