Skip to content

Commit 2968543

Browse files
kevgsmidenok
authored andcommitted
IB: NULL instead of autodecrement [closes #373]
1 parent 947aa0b commit 2968543

File tree

4 files changed

+39
-76
lines changed

4 files changed

+39
-76
lines changed

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

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -405,32 +405,13 @@ call verify_vtq;
405405
No A B C D
406406
1 1 1 1 1
407407
2 1 1 1 1
408-
alter table t add b int auto_increment unique;
409-
call verify_vtq;
410-
No A B C D
411-
select * from t for system_time all;
412-
a b
413-
1 -1
414-
2 -2
415-
3 1
416-
insert into t values (4, NULL);
417-
select * from t for system_time all;
418-
a b
419-
1 -1
420-
2 -2
421-
3 1
422-
4 2
423-
call verify_vtq;
424-
No A B C D
425-
1 1 1 1 1
426-
create or replace table t (a int) with system versioning;
427-
insert into t values (1), (2), (3);
428-
delete from t where a<3;
429408
alter table t add b int not null unique;
430409
ERROR 23000: Duplicate entry '...' for key 'b'
431410
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
411+
ERROR 42000: Table 'test/t' uses an extension that doesn't exist in this MariaDB version
433412
alter table t add b int auto_increment null unique;
413+
call verify_vtq;
414+
No A B C D
434415
select * from t;
435416
a b
436417
3 1
@@ -446,35 +427,20 @@ a b
446427
2 NULL
447428
3 1
448429
4 2
449-
create or replace table t (a int) with system versioning engine=innodb;
450-
insert into t values (1), (2), (3);
451-
delete from t where a<3;
452-
call verify_vtq;
453-
No A B C D
454-
1 1 1 1 1
455-
2 1 1 1 1
456-
alter table t add b tinyint auto_increment unique;
457-
call verify_vtq;
458-
No A B C D
459-
select * from t for system_time all;
460-
a b
461-
1 -1
462-
2 -2
463-
3 1
464-
insert into t values (4, NULL);
465-
select * from t for system_time all;
466-
a b
467-
1 -1
468-
2 -2
469-
3 1
470-
4 2
471430
call verify_vtq;
472431
No A B C D
473432
1 1 1 1 1
474433
create or replace table t (a int) with system versioning;
475434
insert into t values (1), (2), (3);
476435
delete from t where a<3;
477-
alter table t add b tinyint auto_increment null unique;
436+
alter table t add b int not null unique;
437+
ERROR 23000: Duplicate entry '...' for key 'b'
438+
alter table t add b int auto_increment unique;
439+
ERROR 42000: Table '#sql-temporary' uses an extension that doesn't exist in this MariaDB version
440+
alter table t add b int auto_increment null unique;
441+
select * from t;
442+
a b
443+
3 1
478444
select * from t for system_time all;
479445
a b
480446
1 NULL

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,16 @@ create or replace table t (a int) with system versioning engine=innodb;
209209
insert into t values (1), (2), (3);
210210
delete from t where a<3;
211211
call verify_vtq;
212+
--replace_regex /'0-[- 0-9.:]+'/'...'/
213+
--error ER_DUP_ENTRY
214+
alter table t add b int not null unique;
215+
--error ER_UNSUPPORTED_EXTENSION
212216
alter table t add b int auto_increment unique;
217+
alter table t add b int auto_increment null unique;
213218
call verify_vtq;
219+
select * from t;
214220
select * from t for system_time all;
215-
insert into t values (4, NULL);
221+
insert into t values (4, 0);
216222
select * from t for system_time all;
217223
call verify_vtq;
218224

@@ -231,27 +237,6 @@ select * from t for system_time all;
231237
insert into t values (4, 0);
232238
select * from t for system_time all;
233239

234-
create or replace table t (a int) with system versioning engine=innodb;
235-
insert into t values (1), (2), (3);
236-
delete from t where a<3;
237-
call verify_vtq;
238-
alter table t add b tinyint auto_increment unique;
239-
call verify_vtq;
240-
select * from t for system_time all;
241-
insert into t values (4, NULL);
242-
select * from t for system_time all;
243-
call verify_vtq;
244-
245-
create or replace table t (a int) with system versioning;
246-
insert into t values (1), (2), (3);
247-
delete from t where a<3;
248-
# kvm-deb-trusty-ppc64le fails with "Out of range value for column 'b' at row 3"
249-
--error 0,ER_WARN_DATA_OUT_OF_RANGE
250-
alter table t add b tinyint auto_increment null unique;
251-
select * from t for system_time all;
252-
insert into t values (4, 0);
253-
select * from t for system_time all;
254-
255240
create or replace table t (
256241
a int,
257242
sys_trx_start bigint(20) unsigned generated always as row start,

sql/handler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3071,8 +3071,8 @@ int handler::update_auto_increment()
30713071
table->next_number_field->set_null();
30723072
DBUG_RETURN(0);
30733073
}
3074+
table->next_number_field->set_notnull();
30743075
}
3075-
table->next_number_field->set_notnull();
30763076
}
30773077

30783078
/*

storage/innobase/row/row0merge.cc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,9 +1742,9 @@ row_merge_read_clustered_index(
17421742
double curr_progress = 0.0;
17431743
ib_uint64_t read_rows = 0;
17441744
ib_uint64_t table_total_rows = 0;
1745-
ulonglong historic_auto_decrement = 0xffffffffffffffff;
17461745
char new_sys_trx_start[8];
17471746
char new_sys_trx_end[8];
1747+
byte any_autoinc_data[8] = {0};
17481748

17491749
DBUG_ENTER("row_merge_read_clustered_index");
17501750

@@ -2253,9 +2253,26 @@ row_merge_read_clustered_index(
22532253
= dfield->is_version_historical_end();
22542254
}
22552255

2256-
const dfield_t* dfield;
2256+
dfield_t* dfield;
22572257

22582258
dfield = dtuple_get_nth_field(row, add_autoinc);
2259+
2260+
if (new_table->versioned()) {
2261+
if (historical_row) {
2262+
if (dfield_get_type(dfield)->prtype & DATA_NOT_NULL) {
2263+
err = DB_UNSUPPORTED;
2264+
my_error(ER_UNSUPPORTED_EXTENSION, MYF(0),
2265+
old_table->name);
2266+
goto func_exit;
2267+
}
2268+
dfield_set_null(dfield);
2269+
} else {
2270+
// set not null
2271+
ulint len = dfield_get_type(dfield)->len;
2272+
dfield_set_data(dfield, any_autoinc_data, len);
2273+
}
2274+
}
2275+
22592276
if (dfield_is_null(dfield)) {
22602277
goto write_buffers;
22612278
}
@@ -2273,12 +2290,7 @@ row_merge_read_clustered_index(
22732290
goto func_exit;
22742291
}
22752292

2276-
ulonglong value;
2277-
if (likely(!historical_row)) {
2278-
value = sequence++;
2279-
} else {
2280-
value = historic_auto_decrement--;
2281-
}
2293+
ulonglong value = sequence++;
22822294

22832295
switch (dtype_get_mtype(dtype)) {
22842296
case DATA_INT: {

0 commit comments

Comments
 (0)