Commit 9ed8d364 authored by Aleksey Midenkov's avatar Aleksey Midenkov

MDEV-17554 history partitioning cleanups

* Fixed missed warning on condition boundary
* REORGANIZE cases
* vers_utils.h removed
* test cases cleanup
parent 8ed646f0
call mtr.add_suppression("need more HISTORY partitions");
create table t (a int);
delete history from t before system_time now();
ERROR HY000: Table `t` is not system-versioned
......@@ -56,16 +57,15 @@ select * from t for system_time all;
a
drop procedure truncate_sp;
# Truncate partitioned
create or replace table t (a int)
with system versioning
partition by system_time limit 1 (
partition p0 history,
partition p1 history,
partition pn current);
create or replace table t (a int) with system versioning
partition by system_time limit 1 partitions 3;
insert into t values (1);
update t set a= 2;
update t set a= 3;
delete history from t;
Warnings:
Warning 4114 Versioned table `test`.`t`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions
# The above warning is one command late (MDEV-20345) ^^^
select * from t for system_time all;
a
3
......
......@@ -121,6 +121,28 @@ select x from t1;
x
1
2
# rename works
create or replace table t1 (x int) with system versioning
partition by system_time;
alter table t1 reorganize partition p0 into
(partition custom_name history);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`x` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME
(PARTITION `custom_name` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
# merge and split doesn't (MDEV-19938)
create or replace table t1 (x int) with system versioning
partition by system_time partitions 3;
Warnings:
Warning 4115 Maybe missing parameters: no rotation condition for multiple HISTORY partitions.
alter table t1 reorganize partition p0, p1 into (partition p00 history);
ERROR HY000: REORGANIZE PARTITION can only be used to reorganize partitions not to change their numbers
alter table t1 reorganize partition p1 into (partition p1 history, partition p2 history);
ERROR HY000: REORGANIZE PARTITION can only be used to reorganize partitions not to change their numbers
# Bug tempesta-tech/mariadb#260: incorrect IB partitioning warning
create or replace table t1 (x int)
with system versioning
......@@ -267,13 +289,6 @@ x
6
7
8
### Assertion in ALTER on warning from partitioning LIMIT [#446]
create or replace table t1 (x int) with system versioning;
insert into t1 values (1), (2);
delete from t1;
alter table t1 partition by system_time limit 1 (
partition p1 history,
partition pn current);
## rotation by INTERVAL
create or replace table t1 (x int)
with system versioning
......@@ -282,6 +297,47 @@ ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL'
create table t1 (i int) with system versioning
partition by system_time interval 6 day limit 98;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'limit 98' at line 2
create or replace table t1 (pk int) with system versioning
partition by system_time interval 10 year partitions 3;
ERROR 22003: TIMESTAMP value is out of range in 'INTERVAL'
# INTERVAL and ALTER TABLE
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour;
set @ts=(select partition_description from information_schema.partitions
where table_schema='test' and table_name='t1' and partition_name='p0');
alter table t1 add column b int;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p0 1 SYSTEM_TIME 00:00:00.000000
pn 2 SYSTEM_TIME NULL
Warnings:
Warning 1292 Incorrect time value: 'CURRENT'
alter table t1 add partition (partition p1 history, partition p2 history);
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p0 1 SYSTEM_TIME 00:00:00.000000
p1 2 SYSTEM_TIME 01:00:00.000000
p2 3 SYSTEM_TIME 02:00:00.000000
pn 4 SYSTEM_TIME NULL
Warnings:
Warning 1292 Incorrect time value: 'CURRENT'
alter table t1 drop partition p0;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p1 1 SYSTEM_TIME 01:00:00.000000
p2 2 SYSTEM_TIME 02:00:00.000000
pn 3 SYSTEM_TIME NULL
Warnings:
Warning 1292 Incorrect time value: 'CURRENT'
alter table t1 drop partition p2;
ERROR HY000: Can only drop oldest partitions when rotating by INTERVAL
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p1 1 SYSTEM_TIME 01:00:00.000000
p2 2 SYSTEM_TIME 02:00:00.000000
pn 3 SYSTEM_TIME NULL
Warnings:
Warning 1292 Incorrect time value: 'CURRENT'
## Subpartitions
create or replace table t1 (x int)
with system versioning
......@@ -302,34 +358,34 @@ x
delete from t1 where x < 3;
delete from t1;
delete from t1;
Warnings:
Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions
select * from t1 partition (p0sp0);
x
1
3
5
select * from t1 partition (p0sp1);
x
2
4
select * from t1 partition (p1sp0);
x
3
5
select * from t1 partition (p1sp1);
x
create or replace table t1 (
a bigint,
row_start SYS_DATATYPE as row start invisible,
row_end SYS_DATATYPE as row end invisible,
period for system_time(row_start, row_end))
4
# check implicit sys fields for implicit engine of partitioned table
create or replace table t1 (a bigint)
with system versioning
partition by range (a)
(partition p0 values less than (20) engine innodb,
partition p1 values less than maxvalue engine innodb);
insert into t1 values (1);
select * from t1 partition (p0);
a
1
# check for partition engine
create or replace table t1 (
f_int1 integer default 0,
row_start SYS_DATATYPE as row start invisible,
row_end SYS_DATATYPE as row end invisible,
period for system_time(row_start, row_end)
f_int1 integer default 0
) with system versioning
partition by range(f_int1)
subpartition by hash(f_int1)
......@@ -337,14 +393,27 @@ subpartition by hash(f_int1)
(subpartition subpart11 storage engine = 'innodb',
subpartition subpart12 storage engine = 'innodb'));
insert into t1 values (1);
select * from t1 partition (part1);
f_int1
1
#
# Assertion in ALTER on warning from partitioning LIMIT [#446]
#
create or replace table t1 (x int) with system versioning;
insert into t1 values (1), (2);
delete from t1;
alter table t1 partition by system_time limit 1 (
partition p1 history,
partition pn current);
#
# MDEV-14649 Assertion `t->mysql_col_len == 8' failed in row_insert_for_mysql
#
create or replace table t1 (i int) engine=innodb partition by key(i);
alter table t1
add column row_start SYS_DATATYPE as row start invisible,
add column row_end SYS_DATATYPE as row end invisible,
add period for system_time(row_start, row_end),
add system versioning;
alter table t1 add system versioning;
insert into t1 values();
#
# MDEV-14722 Assertion in ha_commit_trans for sub-statement
#
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day;
create or replace table t2 (f int);
......@@ -354,7 +423,9 @@ where table_name = 't1' into @a;
Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
insert into t2 values (1);
#
# MDEV-14740 Locking assertion for system_time partitioning
#
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 week;
create or replace table t2 (f int);
......@@ -363,14 +434,18 @@ for each row select count(*) from t1 into @a;
Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
insert into t2 values (1);
#
# MDEV-14747 ALTER PARTITION BY SYSTEM_TIME after LOCK TABLES
#
create or replace table t1 (x int) with system versioning;
lock table t1 write;
alter table t1 partition by system_time interval 1 week (
partition p1 history,
partition pn current);
unlock tables;
#
# MDEV-14748 Assertion in ha_myisammrg::attach_children()
#
create or replace table t1 (x int) engine=myisam with system versioning
partition by system_time interval 1 month (partition p1 history, partition pn current);
create or replace table t2 (x int) engine=myisam;
......@@ -379,7 +454,9 @@ create or replace table t4 (x int) engine=myisam;
create or replace trigger tr after insert on t4 for each row insert into t2
( select x from t3 ) union ( select x from t1 );
insert into t4 values (1);
#
# MDEV-14821 Assertion failure
#
create or replace table t1 (x int) with system versioning;
insert into t1 values (0), (1);
update t1 set x= x + 1;
......@@ -389,7 +466,11 @@ partition p2 history,
partition pn current);
delete from t1 where x = 1;
delete from t1 where x = 2;
Warnings:
Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p2`) is out of LIMIT, need more HISTORY partitions
#
# MDEV-14923 Assertion upon INSERT into locked versioned partitioned table
#
create or replace table t1 (x int) with system versioning
partition by system_time;
lock table t1 write;
......@@ -397,46 +478,6 @@ alter table t1 add partition (partition p0 history);
ERROR HY000: Duplicate partition name p0
insert into t1 values (1);
unlock tables;
create or replace table t1 (pk int) with system versioning
partition by system_time interval 10 year partitions 3;
ERROR 22003: TIMESTAMP value is out of range in 'INTERVAL'
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour;
set @ts=(select partition_description from information_schema.partitions
where table_schema='test' and table_name='t1' and partition_name='p0');
alter table t1 add column b int;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p0 1 SYSTEM_TIME 00:00:00.000000
pn 2 SYSTEM_TIME NULL
Warnings:
Warning 1292 Incorrect time value: 'CURRENT'
alter table t1 add partition (partition p1 history, partition p2 history);
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p0 1 SYSTEM_TIME 00:00:00.000000
p1 2 SYSTEM_TIME 01:00:00.000000
p2 3 SYSTEM_TIME 02:00:00.000000
pn 4 SYSTEM_TIME NULL
Warnings:
Warning 1292 Incorrect time value: 'CURRENT'
alter table t1 drop partition p0;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p1 1 SYSTEM_TIME 01:00:00.000000
p2 2 SYSTEM_TIME 02:00:00.000000
pn 3 SYSTEM_TIME NULL
Warnings:
Warning 1292 Incorrect time value: 'CURRENT'
alter table t1 drop partition p2;
ERROR HY000: Can only drop oldest partitions when rotating by INTERVAL
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p1 1 SYSTEM_TIME 01:00:00.000000
p2 2 SYSTEM_TIME 02:00:00.000000
pn 3 SYSTEM_TIME NULL
Warnings:
Warning 1292 Incorrect time value: 'CURRENT'
#
# MDEV-15103 Assertion in ha_partition::part_records() for updating VIEW
#
......@@ -452,7 +493,9 @@ create or replace table t (a int) with system versioning
partition by system_time;
alter table t drop system versioning;
ERROR HY000: Can not DROP SYSTEM VERSIONING for table `t` partitioned BY SYSTEM_TIME
#
# MDEV-15191 Assertion `bit < (map)->n_bits' failed in bitmap_is_set upon INSERT
#
create or replace table t1 (i int) with system versioning;
insert into t1 values (1), (2);
update t1 set i= 3;
......@@ -461,14 +504,18 @@ lock table t1 write;
alter table t1 add partition (partition p2 history);
insert into t1 values (4);
unlock tables;
#
# MDEV-15036 Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' in Diagnostics_area::set_ok_status or unexpected ER_RANGE_NOT_INCREASING_ERROR
#
create or replace table t1 (a int) with system versioning
partition by system_time limit 2 partitions 4;
insert into t1 values (1),(2),(3);
update t1 set a = 4;
delete from t1;
delete from t1 where a is not null;
#
# MDEV-14823 Wrong error message upon selecting from a system_time partition
#
create or replace table t1 (i int) with system versioning partition by system_time limit 10;
select * from t1 partition (p0) for system_time all;
ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query
......@@ -480,7 +527,9 @@ ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical qu
call sp;
ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query
drop procedure sp;
#
# MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
#
create or replace table t1 (pk int primary key)
engine=myisam
with system versioning
......
......@@ -2,6 +2,8 @@
--source include/have_partition.inc
--source suite/versioning/engines.inc
call mtr.add_suppression("need more HISTORY partitions");
create table t (a int);
--error ER_VERS_NOT_VERSIONED
delete history from t before system_time now();
......@@ -56,16 +58,13 @@ select * from t for system_time all;
drop procedure truncate_sp;
--echo # Truncate partitioned
create or replace table t (a int)
with system versioning
partition by system_time limit 1 (
partition p0 history,
partition p1 history,
partition pn current);
create or replace table t (a int) with system versioning
partition by system_time limit 1 partitions 3;
insert into t values (1);
update t set a= 2;
update t set a= 3;
delete history from t;
--echo # The above warning is one command late (MDEV-20345) ^^^
select * from t for system_time all;
--echo # VIEW
......
......@@ -123,6 +123,23 @@ alter table t1 drop partition p0;
select x from t1;
--echo # rename works
create or replace table t1 (x int) with system versioning
partition by system_time;
alter table t1 reorganize partition p0 into
(partition custom_name history);
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
--echo # merge and split doesn't (MDEV-19938)
create or replace table t1 (x int) with system versioning
partition by system_time partitions 3;
--error ER_REORG_HASH_ONLY_ON_SAME_NO
alter table t1 reorganize partition p0, p1 into (partition p00 history);
--error ER_REORG_HASH_ONLY_ON_SAME_NO
alter table t1 reorganize partition p1 into (partition p1 history, partition p2 history);
--echo # Bug tempesta-tech/mariadb#260: incorrect IB partitioning warning
create or replace table t1 (x int)
with system versioning
......@@ -224,13 +241,6 @@ insert into t1 values (7), (8);
delete from t1;
select * from t1 partition (p1) order by x;
--echo ### Assertion in ALTER on warning from partitioning LIMIT [#446]
create or replace table t1 (x int) with system versioning;
insert into t1 values (1), (2);
delete from t1;
alter table t1 partition by system_time limit 1 (
partition p1 history,
partition pn current);
--echo ## rotation by INTERVAL
--error ER_PART_WRONG_VALUE
......@@ -242,6 +252,28 @@ partition by system_time interval 0 second partitions 3;
create table t1 (i int) with system versioning
partition by system_time interval 6 day limit 98;
--error ER_DATA_OUT_OF_RANGE
create or replace table t1 (pk int) with system versioning
partition by system_time interval 10 year partitions 3;
--echo # INTERVAL and ALTER TABLE
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour;
set @ts=(select partition_description from information_schema.partitions
where table_schema='test' and table_name='t1' and partition_name='p0');
alter table t1 add column b int;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
alter table t1 add partition (partition p1 history, partition p2 history);
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
alter table t1 drop partition p0;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
--error ER_VERS_DROP_PARTITION_INTERVAL
alter table t1 drop partition p2;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
--echo ## Subpartitions
create or replace table t1 (x int)
with system versioning
......@@ -262,24 +294,18 @@ select * from t1 partition (p0sp1);
select * from t1 partition (p1sp0);
select * from t1 partition (p1sp1);
--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table t1 (
a bigint,
row_start $sys_datatype_expl as row start invisible,
row_end $sys_datatype_expl as row end invisible,
period for system_time(row_start, row_end))
--echo # check implicit sys fields for implicit engine of partitioned table
create or replace table t1 (a bigint)
with system versioning
partition by range (a)
(partition p0 values less than (20) engine innodb,
partition p1 values less than maxvalue engine innodb);
insert into t1 values (1);
select * from t1 partition (p0);
--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table t1 (
f_int1 integer default 0,
row_start $sys_datatype_expl as row start invisible,
row_end $sys_datatype_expl as row end invisible,
period for system_time(row_start, row_end)
--echo # check for partition engine
create or replace table t1 (
f_int1 integer default 0
) with system versioning
partition by range(f_int1)
subpartition by hash(f_int1)
......@@ -287,17 +313,28 @@ subpartition by hash(f_int1)
(subpartition subpart11 storage engine = 'innodb',
subpartition subpart12 storage engine = 'innodb'));
insert into t1 values (1);
select * from t1 partition (part1);
--echo #
--echo # Assertion in ALTER on warning from partitioning LIMIT [#446]
--echo #
create or replace table t1 (x int) with system versioning;
insert into t1 values (1), (2);
delete from t1;
alter table t1 partition by system_time limit 1 (
partition p1 history,
partition pn current);
--echo #
--echo # MDEV-14649 Assertion `t->mysql_col_len == 8' failed in row_insert_for_mysql
--echo #
create or replace table t1 (i int) engine=innodb partition by key(i);
--replace_result $sys_datatype_expl SYS_DATATYPE
eval alter table t1
add column row_start $sys_datatype_expl as row start invisible,
add column row_end $sys_datatype_expl as row end invisible,
add period for system_time(row_start, row_end),
add system versioning;
alter table t1 add system versioning;
insert into t1 values();
--echo #
--echo # MDEV-14722 Assertion in ha_commit_trans for sub-statement
--echo #
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day;
create or replace table t2 (f int);
......@@ -306,7 +343,9 @@ for each row select table_rows from information_schema.tables
where table_name = 't1' into @a;
insert into t2 values (1);
--echo #
--echo # MDEV-14740 Locking assertion for system_time partitioning
--echo #
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 week;
create or replace table t2 (f int);
......@@ -314,7 +353,9 @@ create or replace trigger tr before insert on t2
for each row select count(*) from t1 into @a;
insert into t2 values (1);
--echo #
--echo # MDEV-14747 ALTER PARTITION BY SYSTEM_TIME after LOCK TABLES
--echo #
create or replace table t1 (x int) with system versioning;
lock table t1 write;
alter table t1 partition by system_time interval 1 week (
......@@ -322,7 +363,9 @@ alter table t1 partition by system_time interval 1 week (
partition pn current);
unlock tables;
--echo #
--echo # MDEV-14748 Assertion in ha_myisammrg::attach_children()
--echo #
create or replace table t1 (x int) engine=myisam with system versioning
partition by system_time interval 1 month (partition p1 history, partition pn current);
create or replace table t2 (x int) engine=myisam;
......@@ -332,17 +375,22 @@ create or replace trigger tr after insert on t4 for each row insert into t2
( select x from t3 ) union ( select x from t1 );
insert into t4 values (1);
--echo #
--echo # MDEV-14821 Assertion failure
--echo #
create or replace table t1 (x int) with system versioning;
insert into t1 values (0), (1);
update t1 set x= x + 1;
alter table t1 partition by system_time limit 1 (
partition p1 history,
partition p2 history,
partition pn current);delete from t1 where x = 1;
partition pn current);
delete from t1 where x = 1;
delete from t1 where x = 2;
--echo #
--echo # MDEV-14923 Assertion upon INSERT into locked versioned partitioned table
--echo #
create or replace table t1 (x int) with system versioning
partition by system_time;
lock table t1 write;
......@@ -351,27 +399,6 @@ alter table t1 add partition (partition p0 history);
insert into t1 values (1);
unlock tables;
--error ER_DATA_OUT_OF_RANGE
create or replace table t1 (pk int) with system versioning
partition by system_time interval 10 year partitions 3;
# INTERVAL and ALTER TABLE
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour;
set @ts=(select partition_description from information_schema.partitions
where table_schema='test' and table_name='t1' and partition_name='p0');
alter table t1 add column b int;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
alter table t1 add partition (partition p1 history, partition p2 history);
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
alter table t1 drop partition p0;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
--error ER_VERS_DROP_PARTITION_INTERVAL
alter table t1 drop partition p2;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
--echo #
--echo # MDEV-15103 Assertion in ha_partition::part_records() for updating VIEW
--echo #
......@@ -389,7 +416,9 @@ partition by system_time;
--error ER_DROP_VERSIONING_SYSTEM_TIME_PARTITION
alter table t drop system versioning;
--echo #
--echo # MDEV-15191 Assertion `bit < (map)->n_bits' failed in bitmap_is_set upon INSERT
--echo #
create or replace table t1 (i int) with system versioning;
insert into t1 values (1), (2);
update t1 set i= 3;
......@@ -399,7 +428,9 @@ alter table t1 add partition (partition p2 history);
insert into t1 values (4);
unlock tables;
--echo #
--echo # MDEV-15036 Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' in Diagnostics_area::set_ok_status or unexpected ER_RANGE_NOT_INCREASING_ERROR
--echo #
create or replace table t1 (a int) with system versioning
partition by system_time limit 2 partitions 4;
insert into t1 values (1),(2),(3);
......@@ -407,7 +438,9 @@ update t1 set a = 4;
delete from t1;
delete from t1 where a is not null;
--echo #
--echo # MDEV-14823 Wrong error message upon selecting from a system_time partition
--echo #
create or replace table t1 (i int) with system versioning partition by system_time limit 10;
--error ER_VERS_QUERY_IN_PARTITION
select * from t1 partition (p0) for system_time all;
......@@ -420,7 +453,9 @@ call sp;
call sp;
drop procedure sp;
--echo #
--echo # MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
--echo #
create or replace table t1 (pk int primary key)
engine=myisam
with system versioning
......
......@@ -22,7 +22,8 @@
#include "sql_plugin.h" // st_plugin_int
#include "sql_class.h"
#include "item.h"
#include "vers_utils.h"
#include "table.h"
#include "vers_string.h"
/* System Versioning: TRT_TRX_ID(), TRT_COMMIT_ID(), TRT_BEGIN_TS(), TRT_COMMIT_TS(), TRT_ISO_LEVEL() */
template <TR_table::field_id_t TRT_FIELD>
......
......@@ -32,9 +32,10 @@
#include "sql_parse.h"
#include "sql_acl.h" // *_ACL
#include "sql_base.h" // fill_record
#include "sql_statistics.h" // vers_stat_end
#include "vers_utils.h"
#include "lock.h"
#include "table.h"
#include "sql_class.h"
#include "vers_string.h"
#ifdef WITH_PARTITION_STORAGE_ENGINE
#include "ha_partition.h"
......@@ -196,49 +197,6 @@ bool partition_info::set_named_partition_bitmap(const char *part_name, size_t le
}
/**
Prune away partitions not mentioned in the PARTITION () clause,
if used.
@param table_list Table list pointing to table to prune.
@return Operation status
@retval false Success
@retval true Failure
*/
bool partition_info::set_read_partitions(List<char> *partition_names)
{
DBUG_ENTER("partition_info::set_read_partitions");
if (!partition_names || !partition_names->elements)
{
DBUG_RETURN(true);
}
uint num_names= partition_names->elements;
List_iterator<char> partition_names_it(*partition_names);
uint i= 0;
/*
TODO: When adding support for FK in partitioned tables, the referenced
table must probably lock all partitions for read, and also write depending
of ON DELETE/UPDATE.
*/
bitmap_clear_all(&read_partitions);
/* No check for duplicate names or overlapping partitions/subpartitions. */
DBUG_PRINT("info", ("Searching through partition_name_hash"));
do
{
char *part_name= partition_names_it++;
if (add_named_partition(part_name, strlen(part_name)))
DBUG_RETURN(true);
} while (++i < num_names);
DBUG_RETURN(false);
}
/**
Prune away partitions not mentioned in the PARTITION () clause,
if used.
......@@ -849,6 +807,15 @@ bool partition_info::has_unique_name(partition_element *element)
DBUG_RETURN(TRUE);
}
/**
@brief Switch history partition according limit or interval
@note
vers_info->limit Limit by number of partition records
vers_info->interval Limit by fixed time interval
vers_info->hist_part (out) Working history partition
*/
void partition_info::vers_set_hist_part(THD *thd)
{
if (vers_info->limit)
......@@ -867,7 +834,7 @@ void partition_info::vers_set_hist_part(THD *thd)
vers_info->hist_part= next;
records= next_records;
}
if (records > vers_info->limit)
if (records >= vers_info->limit)
{
if (next == vers_info->now_part)
{
......@@ -904,49 +871,6 @@ void partition_info::vers_set_hist_part(THD *thd)
}
bool partition_info::vers_setup_expression(THD * thd, uint32 alter_add)
{
if (!table->versioned())
{
// frm must be corrupted, normally CREATE/ALTER TABLE checks for that
my_error(ER_FILE_CORRUPT, MYF(0), table->s->path.str);
return true;
}
DBUG_ASSERT(part_type == VERSIONING_PARTITION);
DBUG_ASSERT(table->versioned(VERS_TIMESTAMP));
if (!alter_add)
{
Field *row_end= table->vers_end_field();
// needed in handle_list_of_fields()
row_end->flags|= GET_FIXED_FIELDS_FLAG;
Name_resolution_context *context= &thd->lex->current_select->context;
Item *row_end_item= new (thd->mem_root) Item_field(thd, context, row_end);
Item *row_end_ts= new (thd->mem_root) Item_func_unix_timestamp(thd, row_end_item);
set_part_expr(thd, row_end_ts, false);
}
if (alter_add)
{
List_iterator<partition_element> it(partitions);
partition_element *el;
for(uint32 id= 0; ((el= it++)); id++)
{
DBUG_ASSERT(el->type != partition_element::CONVENTIONAL);
/* Newly added element is inserted before AS_OF_NOW. */
if (el->id == UINT_MAX32 || el->type == partition_element::CURRENT)
{
el->id= id;
if (el->type == partition_element::CURRENT)
break;
}
}
}
return false;
}
/*
Check that the partition/subpartition is setup to use the correct
storage engine
......@@ -1424,9 +1348,8 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type,
if (add_or_reorg_part)
{
if (unlikely(part_type == VERSIONING_PARTITION &&
vers_setup_expression(thd, add_or_reorg_part->partitions.elements)))
goto end;
if (part_type == VERSIONING_PARTITION && add_or_reorg_part->partitions.elements)
vers_update_el_ids();
if (check_constants(thd, this))
goto end;
}
......
......@@ -385,11 +385,9 @@ class partition_info : public Sql_alloc
uint start_no);
char *create_default_subpartition_name(THD *thd, uint subpart_no,
const char *part_name);
// FIXME: prune_partition_bitmaps() is duplicate of set_read_partitions()
bool prune_partition_bitmaps(List<String> *partition_names);
bool prune_partition_bitmaps(List<String> *partition_names); // set_read_partitions() in 8.0
bool add_named_partition(const char *part_name, size_t length);
public:
bool set_read_partitions(List<char> *partition_names);
bool has_unique_name(partition_element *element);
bool field_in_partition_expr(Field *field) const;
......@@ -404,7 +402,8 @@ class partition_info : public Sql_alloc
return !limit;
}
void vers_set_hist_part(THD *thd);
bool vers_setup_expression(THD *thd, uint32 alter_add= 0); /* Stage 1. */
bool vers_fix_field_list(THD *thd);
void vers_update_el_ids();
partition_element *get_partition(uint part_id)
{
List_iterator<partition_element> it(partitions);
......@@ -445,4 +444,60 @@ void init_all_partitions_iterator(partition_info *part_info,
part_iter->get_next= get_next_partition_id_range;
}
/**
@brief Update part_field_list by row_end field name
@returns true on error; false on success
*/
inline
bool partition_info::vers_fix_field_list(THD * thd)
{
if (!table->versioned())
{
// frm must be corrupted, normally CREATE/ALTER TABLE checks for that
my_error(ER_FILE_CORRUPT, MYF(0), table->s->path.str);
return true;
}
DBUG_ASSERT(part_type == VERSIONING_PARTITION);
DBUG_ASSERT(table->versioned(VERS_TIMESTAMP));
Field *row_end= table->vers_end_field();
// needed in handle_list_of_fields()
row_end->flags|= GET_FIXED_FIELDS_FLAG;
Name_resolution_context *context= &thd->lex->current_select->context;
Item *row_end_item= new (thd->mem_root) Item_field(thd, context, row_end);
Item *row_end_ts= new (thd->mem_root) Item_func_unix_timestamp(thd, row_end_item);
set_part_expr(thd, row_end_ts, false);
return false;
}
/**
@brief Update partition_element's id
@returns true on error; false on success
*/
inline
void partition_info::vers_update_el_ids()
{
DBUG_ASSERT(part_type == VERSIONING_PARTITION);
DBUG_ASSERT(table->versioned(VERS_TIMESTAMP));
List_iterator<partition_element> it(partitions);
partition_element *el;
for(uint32 id= 0; ((el= it++)); id++)
{
DBUG_ASSERT(el->type != partition_element::CONVENTIONAL);
/* Newly added element is inserted before AS_OF_NOW. */
if (el->id == UINT_MAX32 || el->type == partition_element::CURRENT)
{
el->id= id;
if (el->type == partition_element::CURRENT)
break;
}
}
}
#endif /* PARTITION_INFO_INCLUDED */
......@@ -2013,7 +2013,7 @@ bool fix_partition_func(THD *thd, TABLE *table, bool is_create_table_ind)
else
{
if (part_info->part_type == VERSIONING_PARTITION &&
part_info->vers_setup_expression(thd))
part_info->vers_fix_field_list(thd))
goto end;
if (unlikely(fix_fields_part_func(thd, part_info->part_expr,
table, FALSE, is_create_table_ind)))
......
#ifndef VERS_UTILS_INCLUDED
#define VERS_UTILS_INCLUDED
#include "table.h"
#include "sql_class.h"
#include "vers_string.h"
#endif // VERS_UTILS_INCLUDED
......@@ -2033,7 +2033,6 @@ static bool srv_task_execute()
}
/** Do the actual purge operation.
@param[in,out] n_total_purged total number of purged pages
@return length of history list before the last purge batch. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment