1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-10 23:02:54 +03:00

MDEV-17038 ALTER TABLE CHANGE COLUMN c1 c1 bigint NOT NULL - generates error if table uses SYSTEM VERSIONING

* Fine-grained inplace skipping by INNOBASE_ALTER_VERSIONED_REBUILD;
* Fixed column WITHOUT SYSTEM VERSIONING + ADD COLUMN;
* Fixed instant field change (MDEV-16330);
* Revisited test versioning.online;
* Merged the test versioning.trx_id_versioning_attribute_persistence
  to versioning.online;
* Renamed some versioning functions:
** change_fields_versioning_cache() -> vers_change_fields_cache()
** change_field_versioning_try() -> vers_change_field_try()
Skip condition moved out of func.

Closes tempesta-tech/mariadb#414
Closes tempesta-tech/mariadb#540
Related to tempesta-tech/mariadb#281
This commit is contained in:
Aleksey Midenkov
2018-09-27 23:34:24 +03:00
committed by Marko Mäkelä
parent d30124e844
commit 4acfc6ecd9
8 changed files with 277 additions and 256 deletions

View File

@@ -370,7 +370,7 @@ a b
1 NULL
2 NULL
3 1
4 4
4 2
create or replace table t (a int) with system versioning;
insert into t values (1), (2), (3);
delete from t where a<3;

View File

@@ -1,34 +1,116 @@
set system_versioning_alter_history=keep;
create or replace table t (a int, b int) engine=innodb;
create or replace table t (a int);
alter table t add system versioning, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned tables. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned timestamp tables. Try LOCK=SHARED
alter table t add system versioning, algorithm=inplace;
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Not implemented for system-versioned timestamp tables. Try ALGORITHM=COPY
alter table t add system versioning, lock=shared;
alter table t drop column b, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned tables. Try LOCK=SHARED
alter table t drop column b, algorithm=inplace;
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Not implemented for system-versioned tables. Try ALGORITHM=COPY
alter table t add index idx(a), lock=none;
alter table t add column b int, change column a a int without system versioning, lock=none;
alter table t drop system versioning, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned tables. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned operations. Try LOCK=SHARED
alter table t drop system versioning, algorithm=inplace;
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Not implemented for system-versioned tables. Try ALGORITHM=COPY
create or replace table t (a int, b int) engine=innodb;
alter table t
add s bigint unsigned as row start,
add e bigint unsigned as row end,
add period for system_time(s, e),
add system versioning,
lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned tables. Try LOCK=SHARED
alter table t
add s bigint unsigned as row start,
add e bigint unsigned as row end,
add period for system_time(s, e),
add system versioning;
create or replace table t (
a int, b int,
row_start SYS_DATATYPE as row start invisible,
row_end SYS_DATATYPE as row end invisible,
period for system_time (row_start, row_end)
) with system versioning;
insert into t values (1, 0);
insert into t values (2, 0);
delete from t where a = 2;
alter table t drop column b, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned tables. Try LOCK=SHARED
alter table t add index idx(a), lock=none;
alter table t drop column s, drop column e;
alter table t drop system versioning, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned tables. Try LOCK=SHARED
drop table t;
select a, check_row(row_start, row_end) from t for system_time all order by a;
a check_row(row_start, row_end)
1 CURRENT ROW
2 HISTORICAL ROW
# MDEV-17038 ALTER TABLE CHANGE COLUMN c1 c1 bigint NOT NULL -
# generates error if table uses SYSTEM VERSIONING [tempesta-tech/mariadb#540]
create or replace table t1 (a int, key(a)) with system versioning;
create or replace table t2 like t;
alter table t2 add foreign key(a) references t1(a);
alter table t2 modify column a int not null, lock=none;
drop table t2;
drop table t1;
# MDEV-16330 Allow instant change of WITH SYSTEM VERSIONING column attribute
create or replace table t1 (
a int,
b int,
row_start SYS_DATATYPE as row start invisible,
row_end SYS_DATATYPE as row end invisible,
period for system_time(row_start, row_end)
) with system versioning;
create or replace table t2 (
a int without system versioning,
b int,
row_start SYS_DATATYPE as row start invisible,
row_end SYS_DATATYPE as row end invisible,
period for system_time(row_start, row_end)
) with system versioning;
insert into t1 values (1,1);
insert into t2 values (1,1);
set @@system_versioning_alter_history=keep;
# without rebuild
alter table t1
change a a int without system versioning,
algorithm=instant;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
alter table t2
change a a int with system versioning,
add primary key pk (a),
algorithm=instant;
ERROR 0A000: ALGORITHM=INSTANT is not supported for this operation. Try ALGORITHM=INPLACE
# with rebuild
alter table t2
change a a int with system versioning,
add primary key pk (a);
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
update t1 set a=2;
select count(*) from t1 for system_time all;
count(*)
1
update t2 set a=2;
select count(*) from t2 for system_time all;
count(*)
2
drop table t1, t2;
# rollback ALTER TABLE: nothing should change
create or replace table t (
a int,
b int,
row_start SYS_DATATYPE as row start invisible,
row_end SYS_DATATYPE as row end invisible,
period for system_time(row_start, row_end)
) with system versioning;
insert into t values (1, 1);
select c.prtype from information_schema.innodb_sys_columns as c
join information_schema.innodb_sys_tables as t on c.table_id=t.table_id
where t.name='test/t' and c.name='b';
prtype
50179
set @@system_versioning_alter_history=keep;
select c.prtype from information_schema.innodb_sys_columns as c
join information_schema.innodb_sys_tables as t on c.table_id=t.table_id
where t.name='test/t' and c.name='b';
prtype
50179
show create table t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`row_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START INVISIBLE,
`row_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END INVISIBLE,
PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
select count(*) from t for system_time all;
count(*)
1
update t set b=11;
select count(*) from t for system_time all;
count(*)
2
drop database test;
create database test;

View File

@@ -1,86 +0,0 @@
CREATE OR REPLACE TABLE t1 (
a INT,
b INT,
row_start BIGINT UNSIGNED AS ROW START INVISIBLE,
row_end BIGINT UNSIGNED AS ROW END INVISIBLE,
PERIOD FOR SYSTEM_TIME(row_start, row_end)
) WITH SYSTEM VERSIONING ENGINE=INNODB;
CREATE OR REPLACE TABLE t2 (
a INT WITHOUT SYSTEM VERSIONING,
b INT,
row_start BIGINT UNSIGNED AS ROW START INVISIBLE,
row_end BIGINT UNSIGNED AS ROW END INVISIBLE,
PERIOD FOR SYSTEM_TIME(row_start, row_end)
) WITH SYSTEM VERSIONING ENGINE=INNODB;
INSERT INTO t1 VALUES (1,1);
INSERT INTO t2 VALUES (1,1);
SET @@SYSTEM_VERSIONING_ALTER_HISTORY=KEEP;
# without rebuild
ALTER TABLE t1
CHANGE a a INT WITHOUT SYSTEM VERSIONING,
ALGORITHM=INSTANT;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
ALTER TABLE t2
CHANGE a a INT WITH SYSTEM VERSIONING,
ADD PRIMARY KEY pk (a),
ALGORITHM=INSTANT;
ERROR 0A000: ALGORITHM=INSTANT is not supported for this operation. Try ALGORITHM=INPLACE
# with rebuild
ALTER TABLE t2
CHANGE a a INT WITH SYSTEM VERSIONING,
ADD PRIMARY KEY pk (a);
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
UPDATE t1 SET a=2;
SELECT COUNT(*) FROM t1 FOR SYSTEM_TIME ALL;
COUNT(*)
1
UPDATE t2 SET a=2;
SELECT COUNT(*) FROM t2 FOR SYSTEM_TIME ALL;
COUNT(*)
2
DROP TABLE t1, t2;
# rollback ALTER TABLE: nothing should change
CREATE TABLE t (
a INT,
b INT,
row_start BIGINT UNSIGNED AS ROW START INVISIBLE,
row_end BIGINT UNSIGNED AS ROW END INVISIBLE,
PERIOD FOR SYSTEM_TIME(row_start, row_end)
) WITH SYSTEM VERSIONING ENGINE=INNODB;
INSERT INTO t VALUES (1, 1);
SELECT C.PRTYPE FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS AS C
JOIN INFORMATION_SCHEMA.INNODB_SYS_TABLES AS t ON C.TABLE_ID=t.TABLE_ID
WHERE t.NAME='test/t' AND C.NAME='b';
PRTYPE
50179
SET @@SYSTEM_VERSIONING_ALTER_HISTORY=KEEP;
SET @SAVED_DEBUG_DBUG = @@SESSION.DEBUG_DBUG;
SET DEBUG_DBUG='+d,ib_commit_inplace_fail_1';
ALTER TABLE t
CHANGE b b INT WITHOUT SYSTEM VERSIONING;
ERROR HY000: Internal error: Injected error!
SET DEBUG_DBUG = @SAVED_DEBUG_DBUG;
SELECT C.PRTYPE FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS AS C
JOIN INFORMATION_SCHEMA.INNODB_SYS_TABLES AS t ON C.TABLE_ID=t.TABLE_ID
WHERE t.NAME='test/t' AND C.NAME='b';
PRTYPE
50179
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`row_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START INVISIBLE,
`row_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END INVISIBLE,
PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
SELECT COUNT(*) FROM t FOR SYSTEM_TIME ALL;
COUNT(*)
1
UPDATE t SET b=11;
SELECT COUNT(*) FROM t FOR SYSTEM_TIME ALL;
COUNT(*)
2
DROP TABLE t;