From d3845132fc50e0bf268b5a9ac904ed89cc533cb5 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 1 Dec 2017 09:09:37 +0100 Subject: [PATCH] remove 'vers_auto_decrement' Do not generate fake values when adding an auto-inc column to a versioned table. This is not a auto-inc issue, but a more general case of adding a not nullalble unique column to a table with history. We don't support it yet, not even with a special auto-inc hack. As a workaround, one can use a nullable unique column, that works. --- mysql-test/suite/versioning/r/alter.result | 31 +++++++++++-------- mysql-test/suite/versioning/t/alter.test | 13 ++++++-- sql/handler.cc | 35 ++++++++-------------- sql/handler.h | 2 -- sql/sql_table.cc | 1 - 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/mysql-test/suite/versioning/r/alter.result b/mysql-test/suite/versioning/r/alter.result index 27c49820231..61efbbdb96f 100644 --- a/mysql-test/suite/versioning/r/alter.result +++ b/mysql-test/suite/versioning/r/alter.result @@ -426,17 +426,24 @@ No A B C D create or replace table t (a int) with system versioning; insert into t values (1), (2), (3); delete from t where a<3; +alter table t add b int not null unique; +ERROR 23000: Duplicate entry '...' for key 'b' alter table t add b int auto_increment unique; -select * from t for system_time all; +ERROR 42000: Table '#sql-temporary' uses an extension that doesn't exist in this MariaDB version +alter table t add b int auto_increment null unique; +select * from t; a b -1 -1 -2 -2 3 1 -insert into t values (4, NULL); select * from t for system_time all; a b -1 -1 -2 -2 +1 NULL +2 NULL +3 1 +insert into t values (4, 0); +select * from t for system_time all; +a b +1 NULL +2 NULL 3 1 4 2 create or replace table t (a int) with system versioning engine=innodb; @@ -467,17 +474,17 @@ No A B C D create or replace table t (a int) with system versioning; insert into t values (1), (2), (3); delete from t where a<3; -alter table t add b tinyint auto_increment unique; +alter table t add b tinyint auto_increment null unique; select * from t for system_time all; a b -1 -1 -2 -2 +1 NULL +2 NULL 3 1 -insert into t values (4, NULL); +insert into t values (4, 0); select * from t for system_time all; a b -1 -1 -2 -2 +1 NULL +2 NULL 3 1 4 2 create or replace table t ( diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test index 6ac05a7702d..2b45d6cc0c8 100644 --- a/mysql-test/suite/versioning/t/alter.test +++ b/mysql-test/suite/versioning/t/alter.test @@ -219,9 +219,16 @@ call verify_vtq; create or replace table t (a int) with system versioning; insert into t values (1), (2), (3); delete from t where a<3; +--replace_regex /'0-[- 0-9.:]+'/'...'/ +--error ER_DUP_ENTRY +alter table t add b int not null unique; +--replace_regex /#sql-[0-9a-f_]*/#sql-temporary/ +--error ER_UNSUPPORTED_EXTENSION alter table t add b int auto_increment unique; +alter table t add b int auto_increment null unique; +select * from t; select * from t for system_time all; -insert into t values (4, NULL); +insert into t values (4, 0); select * from t for system_time all; create or replace table t (a int) with system versioning engine=innodb; @@ -240,9 +247,9 @@ insert into t values (1), (2), (3); delete from t where a<3; # kvm-deb-trusty-ppc64le fails with "Out of range value for column 'b' at row 3" --error 0,ER_WARN_DATA_OUT_OF_RANGE -alter table t add b tinyint auto_increment unique; +alter table t add b tinyint auto_increment null unique; select * from t for system_time all; -insert into t values (4, NULL); +insert into t values (4, 0); select * from t for system_time all; create or replace table t ( diff --git a/sql/handler.cc b/sql/handler.cc index dd14c7d6302..28e304496b6 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -3056,34 +3056,23 @@ int handler::update_auto_increment() enum enum_check_fields save_count_cuted_fields; DBUG_ENTER("handler::update_auto_increment"); - // System Versioning: handle ALTER ADD COLUMN AUTO_INCREMENT - if (thd->lex->sql_command == SQLCOM_ALTER_TABLE && table->versioned()) + // ALTER TABLE ... ADD COLUMN ... AUTO_INCREMENT + if (thd->lex->sql_command == SQLCOM_ALTER_TABLE) { - Field *end= table->vers_end_field(); - DBUG_ASSERT(end); - bitmap_set_bit(table->read_set, end->field_index); - if (!end->is_max()) + if (table->versioned()) { - uchar *ptr= table->next_number_field->ptr; - switch (table->next_number_field->pack_length()) + Field *end= table->vers_end_field(); + DBUG_ASSERT(end); + bitmap_set_bit(table->read_set, end->field_index); + if (!end->is_max()) { - case 8: - int8store(ptr, vers_auto_decrement--); - break; - case 4: - int4store(ptr, vers_auto_decrement--); - break; - case 2: - int2store(ptr, vers_auto_decrement--); - break; - case 1: - *ptr= static_cast(vers_auto_decrement--); - break; - default: - DBUG_ASSERT(false); + if (!table->next_number_field->real_maybe_null()) + DBUG_RETURN(HA_ERR_UNSUPPORTED); + table->next_number_field->set_null(); + DBUG_RETURN(0); } - DBUG_RETURN(0); } + table->next_number_field->set_notnull(); } /* diff --git a/sql/handler.h b/sql/handler.h index 90b7bb4ba1a..50e8d7e0e78 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -2865,8 +2865,6 @@ public: */ uint auto_inc_intervals_count; - ulonglong vers_auto_decrement; - /** Instrumented table associated with this handler. This member should be set to NULL when no instrumentation is in place, diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 7e4cf00a6b8..bbb27228e2f 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -10112,7 +10112,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, } else if (keep_versioned) { - to->file->vers_auto_decrement= 0xffffffffffffffff; if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE) { query_start= thd->query_start_TIME();