1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-27293 Allow converting a versioned table from implicit

to explicit row_start/row_end columns

In case of adding both system fields of same type (length, unsigned
flag) as old implicit system fields do the rename of implicit system
fields to the ones specified in ALTER, remove SYSTEM_INVISIBLE flag in
that case. Correct PERIOD clause must be specified in ALTER as well.

MDEV-34904 Inplace alter for implicit to explicit versioning is broken

Whether ALTER goes inplace and how it goes inplace depends on
handler_flags which goes from alter_info->flags by this logic:

  ha_alter_info->handler_flags|= (alter_info->flags & ~flags_to_remove);

ALTER_VERS_EXPLICIT was not in flags_to_remove and its value (1ULL <<
35) clashed with ALTER_ADD_NON_UNIQUE_NON_PRIM_INDEX.

ALTER_VERS_EXPLICIT must not affect inplace, it is SQL-only so we
remove it from handler_flags.
This commit is contained in:
Aleksey Midenkov
2024-10-29 14:18:38 +03:00
parent 5e5c3c7cb6
commit cc183489da
10 changed files with 170 additions and 45 deletions

View File

@@ -88,9 +88,9 @@ t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci WITH SYSTEM VERSIONING
alter table t add column trx_start timestamp(6) as row start;
ERROR HY000: Duplicate ROW START column `trx_start`
ERROR HY000: Wrong parameters for `t`: missing 'AS ROW END'
alter table t modify a int as row start;
ERROR HY000: Duplicate ROW START column `a`
ERROR 42000: Incorrect column specifier for column 'a'
alter table t add column b int;
show create table t;
Table Create Table
@@ -879,3 +879,58 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci WITH SYSTEM VERSIONING
drop table t1;
# End of 10.5 tests
#
# MDEV-27293 Allow converting a versioned table from implicit
# to explicit row_start/row_end columns
#
create table t1 (x int) with system versioning;
insert t1 values (0), (1);
update t1 set x= x + 10;
set @old_system_versioning_alter_history= @@system_versioning_alter_history;
set @@system_versioning_alter_history= keep;
alter table t1 add column y int;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`x` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci WITH SYSTEM VERSIONING
alter table t1 add column rs timestamp(6) as row start;
ERROR HY000: Wrong parameters for `t1`: missing 'AS ROW END'
alter table t1 add column re timestamp(6) as row end, add period for system_time (row_start, re);
ERROR HY000: Wrong parameters for `t1`: missing 'AS ROW START'
alter table t1 add column rs timestamp(6) as row start, add column re timestamp(6) as row end;
ERROR HY000: Wrong parameters for `t1`: missing 'PERIOD FOR SYSTEM_TIME'
alter table t1 rename column row_start to re;
ERROR 42S22: Unknown column 'row_start' in 't1'
alter table t1 add column rs timestamp(5) as row start, add column re timestamp(6) as row end, add period for system_time (rs,re);
ERROR 42000: Incorrect column specifier for column 'rs'
alter table t1 add column rs timestamp(6) as row start, add column re timestamp(6) as row end, add period for system_time (rs,re);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`x` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL,
`rs` timestamp(6) GENERATED ALWAYS AS ROW START,
`re` timestamp(6) GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`rs`, `re`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci WITH SYSTEM VERSIONING
select x, check_row_ts(rs, re) from t1 for system_time all order by x;
x check_row_ts(rs, re)
0 HISTORICAL ROW
1 HISTORICAL ROW
10 CURRENT ROW
11 CURRENT ROW
create or replace table t1 (x int) engine innodb with system versioning;
alter table t1 add column rs timestamp(6) as row start, add column re timestamp(6) as row end, add period for system_time (rs,re);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`x` int(11) DEFAULT NULL,
`rs` timestamp(6) GENERATED ALWAYS AS ROW START,
`re` timestamp(6) GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`rs`, `re`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci WITH SYSTEM VERSIONING
set @@system_versioning_alter_history= @old_system_versioning_alter_history;
drop table t1;
# End of 11.6 tests