Skip to content

Commit d384513

Browse files
vuvovamidenok
authored andcommitted
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.
1 parent 6a7911d commit d384513

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed

mysql-test/suite/versioning/r/alter.result

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,24 @@ No A B C D
426426
create or replace table t (a int) with system versioning;
427427
insert into t values (1), (2), (3);
428428
delete from t where a<3;
429+
alter table t add b int not null unique;
430+
ERROR 23000: Duplicate entry '...' for key 'b'
429431
alter table t add b int auto_increment unique;
432+
ERROR 42000: Table '#sql-temporary' uses an extension that doesn't exist in this MariaDB version
433+
alter table t add b int auto_increment null unique;
434+
select * from t;
435+
a b
436+
3 1
430437
select * from t for system_time all;
431438
a b
432-
1 -1
433-
2 -2
439+
1 NULL
440+
2 NULL
434441
3 1
435-
insert into t values (4, NULL);
442+
insert into t values (4, 0);
436443
select * from t for system_time all;
437444
a b
438-
1 -1
439-
2 -2
445+
1 NULL
446+
2 NULL
440447
3 1
441448
4 2
442449
create or replace table t (a int) with system versioning engine=innodb;
@@ -467,17 +474,17 @@ No A B C D
467474
create or replace table t (a int) with system versioning;
468475
insert into t values (1), (2), (3);
469476
delete from t where a<3;
470-
alter table t add b tinyint auto_increment unique;
477+
alter table t add b tinyint auto_increment null unique;
471478
select * from t for system_time all;
472479
a b
473-
1 -1
474-
2 -2
480+
1 NULL
481+
2 NULL
475482
3 1
476-
insert into t values (4, NULL);
483+
insert into t values (4, 0);
477484
select * from t for system_time all;
478485
a b
479-
1 -1
480-
2 -2
486+
1 NULL
487+
2 NULL
481488
3 1
482489
4 2
483490
create or replace table t (

mysql-test/suite/versioning/t/alter.test

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,16 @@ call verify_vtq;
219219
create or replace table t (a int) with system versioning;
220220
insert into t values (1), (2), (3);
221221
delete from t where a<3;
222+
--replace_regex /'0-[- 0-9.:]+'/'...'/
223+
--error ER_DUP_ENTRY
224+
alter table t add b int not null unique;
225+
--replace_regex /#sql-[0-9a-f_]*/#sql-temporary/
226+
--error ER_UNSUPPORTED_EXTENSION
222227
alter table t add b int auto_increment unique;
228+
alter table t add b int auto_increment null unique;
229+
select * from t;
223230
select * from t for system_time all;
224-
insert into t values (4, NULL);
231+
insert into t values (4, 0);
225232
select * from t for system_time all;
226233

227234
create or replace table t (a int) with system versioning engine=innodb;
@@ -240,9 +247,9 @@ insert into t values (1), (2), (3);
240247
delete from t where a<3;
241248
# kvm-deb-trusty-ppc64le fails with "Out of range value for column 'b' at row 3"
242249
--error 0,ER_WARN_DATA_OUT_OF_RANGE
243-
alter table t add b tinyint auto_increment unique;
250+
alter table t add b tinyint auto_increment null unique;
244251
select * from t for system_time all;
245-
insert into t values (4, NULL);
252+
insert into t values (4, 0);
246253
select * from t for system_time all;
247254

248255
create or replace table t (

sql/handler.cc

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,34 +3056,23 @@ int handler::update_auto_increment()
30563056
enum enum_check_fields save_count_cuted_fields;
30573057
DBUG_ENTER("handler::update_auto_increment");
30583058

3059-
// System Versioning: handle ALTER ADD COLUMN AUTO_INCREMENT
3060-
if (thd->lex->sql_command == SQLCOM_ALTER_TABLE && table->versioned())
3059+
// ALTER TABLE ... ADD COLUMN ... AUTO_INCREMENT
3060+
if (thd->lex->sql_command == SQLCOM_ALTER_TABLE)
30613061
{
3062-
Field *end= table->vers_end_field();
3063-
DBUG_ASSERT(end);
3064-
bitmap_set_bit(table->read_set, end->field_index);
3065-
if (!end->is_max())
3062+
if (table->versioned())
30663063
{
3067-
uchar *ptr= table->next_number_field->ptr;
3068-
switch (table->next_number_field->pack_length())
3064+
Field *end= table->vers_end_field();
3065+
DBUG_ASSERT(end);
3066+
bitmap_set_bit(table->read_set, end->field_index);
3067+
if (!end->is_max())
30693068
{
3070-
case 8:
3071-
int8store(ptr, vers_auto_decrement--);
3072-
break;
3073-
case 4:
3074-
int4store(ptr, vers_auto_decrement--);
3075-
break;
3076-
case 2:
3077-
int2store(ptr, vers_auto_decrement--);
3078-
break;
3079-
case 1:
3080-
*ptr= static_cast<uchar>(vers_auto_decrement--);
3081-
break;
3082-
default:
3083-
DBUG_ASSERT(false);
3069+
if (!table->next_number_field->real_maybe_null())
3070+
DBUG_RETURN(HA_ERR_UNSUPPORTED);
3071+
table->next_number_field->set_null();
3072+
DBUG_RETURN(0);
30843073
}
3085-
DBUG_RETURN(0);
30863074
}
3075+
table->next_number_field->set_notnull();
30873076
}
30883077

30893078
/*

sql/handler.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,8 +2865,6 @@ class handler :public Sql_alloc
28652865
*/
28662866
uint auto_inc_intervals_count;
28672867

2868-
ulonglong vers_auto_decrement;
2869-
28702868
/**
28712869
Instrumented table associated with this handler.
28722870
This member should be set to NULL when no instrumentation is in place,

sql/sql_table.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10112,7 +10112,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
1011210112
}
1011310113
else if (keep_versioned)
1011410114
{
10115-
to->file->vers_auto_decrement= 0xffffffffffffffff;
1011610115
if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE)
1011710116
{
1011810117
query_start= thd->query_start_TIME();

0 commit comments

Comments
 (0)