diff options
author | Yuchen Pei <yuchen.pei@mariadb.com> | 2023-03-01 17:34:05 +1100 |
---|---|---|
committer | Yuchen Pei <yuchen.pei@mariadb.com> | 2023-03-07 16:51:38 +1100 |
commit | 1aa3022bc444f3a98bfd8cf6966dd746939e1637 (patch) | |
tree | cc5f97bcfd3f6c5d5761a53f63b25afe3ac8e4a0 | |
parent | 3758c111e89685f0fc87ea01c234d2cffd84977b (diff) | |
download | mariadb-git-bb-11.0-mdev-28152-alter-value-type.tar.gz |
MDEV-28152 wip wip wip alter sequence as <new_value_type>bb-11.0-mdev-28152-alter-value-type
Basic case:
- start with a narrow value type, the alter to a wider type without
changing any other metadata
Advanced cases to fix once the basic case works:
- start with a wider value type, then alter to a narrower type with
smaller metadata values in range for the narrower value type
- start with a narrower value type, then alter to a wider type with
bigger metadata values out of range for the narrower type but in
range for the wider type
-rw-r--r-- | mysql-test/suite/sql_sequence/alter.test | 33 | ||||
-rw-r--r-- | sql/sql_sequence.cc | 33 | ||||
-rw-r--r-- | sql/sql_sequence.h | 2 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 2 |
4 files changed, 65 insertions, 5 deletions
diff --git a/mysql-test/suite/sql_sequence/alter.test b/mysql-test/suite/sql_sequence/alter.test index a5e6245d609..8457a824723 100644 --- a/mysql-test/suite/sql_sequence/alter.test +++ b/mysql-test/suite/sql_sequence/alter.test @@ -161,3 +161,36 @@ CREATE SEQUENCE s; ALTER TABLE s ORDER BY cache_size; SELECT NEXTVAL(s); DROP SEQUENCE s; + + +--echo # +--echo # MDEV-28152 Features for sequence +--echo # + +create or replace sequence t1 as bigint; +show create sequence t1; +show create table t1; +alter sequence t1 as tinyint; +show create sequence t1; +show create table t1; + +create or replace sequence t1 as bigint maxvalue 123; +show create sequence t1; +show create table t1; +alter sequence t1 as tinyint; +show create sequence t1; +show create table t1; + +create or replace sequence t1 as tinyint; +show create sequence t1; +show create table t1; +alter sequence t1 as bigint; +show create sequence t1; +show create table t1; + +create or replace sequence t1 as int unsigned; +show create sequence t1; +show create table t1; +alter sequence t1 as int; +show create sequence t1; +show create table t1; diff --git a/sql/sql_sequence.cc b/sql/sql_sequence.cc index 9ac7870852c..06d581164c9 100644 --- a/sql/sql_sequence.cc +++ b/sql/sql_sequence.cc @@ -353,7 +353,7 @@ err: true Failure (out of memory) */ -bool sequence_definition::prepare_sequence_fields(List<Create_field> *fields) +bool sequence_definition::prepare_sequence_fields(List<Create_field> *fields, bool alter) { DBUG_ENTER("prepare_sequence_fields"); const Sequence_row_definition row_def= sequence_structure(value_type_handler()); @@ -374,6 +374,8 @@ bool sequence_definition::prepare_sequence_fields(List<Create_field> *fields) new_field->char_length= field_info->length; new_field->comment= field_info->comment; new_field->flags= field_info->flags; + if (alter) + new_field->change = field_name; if (unlikely(fields->push_back(new_field))) DBUG_RETURN(TRUE); /* purify inspected */ } @@ -527,9 +529,9 @@ SEQUENCE::~SEQUENCE() A sequence table can have many readers (trough normal SELECT's). We mark that we have a write lock in the table object so that - ha_sequence::ha_write() can check if we have a lock. If already locked, then + ha_sequence::write_row() can check if we have a lock. If already locked, then ha_write() knows that we are running a sequence operation. If not, then - ha_write() knows that it's an INSERT. + ha_write() knows that it's an INSERT statement. */ void SEQUENCE::write_lock(TABLE *table) @@ -1029,6 +1031,7 @@ bool Sql_cmd_alter_sequence::execute(THD *thd) #endif /* WITH_WSREP */ if (if_exists()) thd->push_internal_handler(&no_such_table_handler); + first_table->mdl_request.set_type(MDL_SHARED_WRITE); error= open_and_lock_tables(thd, first_table, FALSE, 0); if (if_exists()) { @@ -1101,6 +1104,30 @@ bool Sql_cmd_alter_sequence::execute(THD *thd) goto end; } + if (new_seq->value_type_handler() != seq->value_type_handler()) + { + // delete row? + // alter table + /* Set lock type which is appropriate for ALTER TABLE. */ + // first_table->lock_type= TL_READ_NO_INSERT; + // /* Same applies to MDL request. */ + // first_table->mdl_request.set_type(MDL_SHARED_NO_WRITE); + Alter_info alter_info; + alter_info.flags = ALTER_CHANGE_COLUMN; + // alter_info.requested_lock = Alter_info::ALTER_TABLE_LOCK_NONE; + if (new_seq->prepare_sequence_fields(&alter_info.create_list, true)) + { + // fixme: emit error. + abort(); + } + Table_specification_st create_info; + create_info.init(); + create_info.alter_info= &alter_info; + bool res= mysql_alter_table(thd, &null_clex_str, &null_clex_str, &create_info, first_table, &alter_info, 0, (ORDER *) 0, 0, 0); + if (res) + DBUG_RETURN(0); + } + if (likely(!(error= new_seq->write(table, 1)))) { /* Store the sequence values in table share */ diff --git a/sql/sql_sequence.h b/sql/sql_sequence.h index 23e185d8271..0de92a90639 100644 --- a/sql/sql_sequence.h +++ b/sql/sql_sequence.h @@ -108,7 +108,7 @@ public: max_value, cache, round)); } static bool is_allowed_value_type(enum_field_types type); - bool prepare_sequence_fields(List<Create_field> *fields); + bool prepare_sequence_fields(List<Create_field> *fields, bool alter); protected: /* diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index de5c94979c9..a359478145c 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2436,7 +2436,7 @@ create: /* No fields specified, generate them */ if (unlikely(lex->create_info.seq_create_info->prepare_sequence_fields( - &lex->alter_info.create_list))) + &lex->alter_info.create_list, false))) MYSQL_YYABORT; /* CREATE SEQUENCE always creates a sequence */ |