mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-36032 Check whether a table can be a sequence when ALTERed with SEQUENCE=1
To check the rows, the table needs to be opened. To that end, and like MDEV-36038, we force COPY algorithm on ALTER TABLE ... SEQUENCE=1. This also results in checking the sequence state / metadata. The table structure was already validated before this patch.
This commit is contained in:
@@ -12154,6 +12154,16 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, bool ignore,
|
||||
Create_field *def;
|
||||
copy_end=copy;
|
||||
to->s->default_fields= 0;
|
||||
if (to->s->table_type == TABLE_TYPE_SEQUENCE &&
|
||||
from->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT &&
|
||||
from->file->stats.records != 1)
|
||||
{
|
||||
if (from->file->stats.records > 1)
|
||||
my_error(ER_SEQUENCE_TABLE_HAS_TOO_MANY_ROWS, MYF(0));
|
||||
else
|
||||
my_error(ER_SEQUENCE_TABLE_HAS_TOO_FEW_ROWS, MYF(0));
|
||||
goto err;
|
||||
}
|
||||
for (Field **ptr=to->field ; *ptr ; ptr++)
|
||||
{
|
||||
def=it++;
|
||||
@@ -12337,6 +12347,12 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, bool ignore,
|
||||
else
|
||||
to->next_number_field->reset();
|
||||
}
|
||||
if (to->s->table_type == TABLE_TYPE_SEQUENCE && found_count == 1)
|
||||
{
|
||||
my_error(ER_SEQUENCE_TABLE_HAS_TOO_MANY_ROWS, MYF(0));
|
||||
error= 1;
|
||||
break;
|
||||
}
|
||||
error= to->file->ha_write_row(to->record[0]);
|
||||
to->auto_increment_field_not_null= FALSE;
|
||||
if (unlikely(error))
|
||||
@@ -12356,6 +12372,12 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, bool ignore,
|
||||
thd->get_stmt_da()->inc_current_row_for_warning();
|
||||
}
|
||||
|
||||
if (to->s->table_type == TABLE_TYPE_SEQUENCE && found_count == 0)
|
||||
{
|
||||
my_error(ER_SEQUENCE_TABLE_HAS_TOO_FEW_ROWS, MYF(0));
|
||||
error= 1;
|
||||
}
|
||||
|
||||
THD_STAGE_INFO(thd, stage_enabling_keys);
|
||||
thd_progress_next_stage(thd);
|
||||
|
||||
|
Reference in New Issue
Block a user