Skip to content

Commit 0076dce

Browse files
committed
MDEV-18727 improve DML operation of System Versioning
MDEV-18957 UPDATE with LIMIT clause is wrong for versioned partitioned tables UPDATE, DELETE: replace linear search of current/historical records with vers_setup_conds(). Additional DML cases in view.test
1 parent a145442 commit 0076dce

19 files changed

+271
-87
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Basic + delete from view
12
create or replace table t1(
23
XNo int unsigned,
34
sys_start SYS_DATATYPE as row start invisible,
@@ -44,6 +45,7 @@ XNo_vt1
4445
5
4546
drop view vt1;
4647
drop table t1;
48+
# Check sys_start, sys_end
4749
create or replace table t1(
4850
x int,
4951
sys_start SYS_DATATYPE as row start invisible,
@@ -59,6 +61,7 @@ select x = 1 as A, sys_start = @sys_start as B, sys_end > sys_start as C from t1
5961
A B C
6062
1 1 1
6163
drop table t1;
64+
# Multi-delete
6265
create or replace table t1(
6366
x int,
6467
y int,
@@ -103,9 +106,6 @@ t2_x_all
103106
14
104107
drop table t1;
105108
drop table t2;
106-
# Basic + delete from view
107-
# Check sys_start, sys_end
108-
# Multi-delete
109109
# Update + delete
110110
create or replace table t1 (x int) with system versioning;
111111
insert into t1 values (1);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,20 @@ execute immediate 'select * from t1 for update';
566566
pk
567567
drop view v1;
568568
drop tables t, t1, t2, t3, t4;
569+
#
570+
# MDEV-18957 UPDATE with LIMIT clause is wrong for versioned partitioned tables
571+
#
572+
create or replace table t1 (
573+
x int,
574+
a varchar(255)
575+
) with system versioning partition by system_time (partition p1 history, partition pn current);
576+
insert into t1 (x) values (1), (2), (3), (4);
577+
update t1 set a= 'foo' limit 3;
578+
update t1 set a= 'bar' limit 4;
579+
select * from t1;
580+
x a
581+
1 bar
582+
2 bar
583+
3 bar
584+
4 bar
585+
drop table t1;

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

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ select * from vt1;
6464
x
6565
1
6666
2
67-
# VIEW with parameters [#151]
67+
# VIEW with parameters [tempesta-tech/mariadb#151]
6868
create or replace table t1 (x int) with system versioning;
6969
create or replace view vt1(c) as select x from t1;
7070
show create view vt1;
7171
View Create View character_set_client collation_connection
7272
vt1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vt1` AS select `t1`.`x` AS `c` from `t1` latin1 latin1_swedish_ci
73-
# VIEW over JOIN of versioned tables [#153]
73+
# VIEW over JOIN of versioned tables [tempesta-tech/mariadb#153]
7474
create or replace table t1 (a int) with system versioning;
7575
create or replace table t2 (b int) with system versioning;
7676
insert into t1 values (1);
@@ -82,7 +82,7 @@ a b
8282
create or replace view vt12 as select * from t1 for system_time as of timestamp ('0-0-0') cross join t2;
8383
select * from vt12;
8484
a b
85-
# VIEW improvements [#183]
85+
# VIEW improvements [tempesta-tech/mariadb#183]
8686
create or replace table t3 (x int);
8787
create or replace view vt1 as select * from t1, t2, t3;
8888
show create view vt1;
@@ -96,12 +96,12 @@ create or replace view vt1 as select a, t2.row_end as endo from t3, t1, t2;
9696
show create view vt1;
9797
View Create View character_set_client collation_connection
9898
vt1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vt1` AS select `t1`.`a` AS `a`,`t2`.`row_end` AS `endo` from ((`t3` join `t1`) join `t2`) latin1 latin1_swedish_ci
99-
# VIEW over UNION [#269]
99+
# VIEW over UNION [tempesta-tech/mariadb#269]
100100
create or replace view vt1 as select * from t1 union select * from t1;
101101
select * from vt1;
102102
a
103103
1
104-
# VIEW over UNION with non-versioned [#393]
104+
# VIEW over UNION with non-versioned [tempesta-tech/mariadb#393]
105105
create or replace table t2 (a int);
106106
create or replace view vt1 as select * from t1 union select * from t2;
107107
select * from vt1;
@@ -123,10 +123,10 @@ drop tables t1, t2;
123123
#
124124
# MDEV-15146 SQLError[4122]: View is not system versioned
125125
#
126-
create table t1 (a int) with system versioning;
126+
create or replace table t1 (a int) with system versioning;
127127
insert t1 values (1),(2);
128128
set @a=now(6);
129-
create view v1 as select * from t1;
129+
create or replace view v1 as select * from t1;
130130
delete from t1;
131131
select * from v1;
132132
a
@@ -149,3 +149,67 @@ View Create View character_set_client collation_connection
149149
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` FOR SYSTEM_TIME AS OF current_timestamp() - interval 6 second latin1 latin1_swedish_ci
150150
drop view v1, vt1, vt12;
151151
drop tables t1, t3;
152+
#
153+
# MDEV-18727 improve DML operation of System Versioning
154+
#
155+
create or replace table t1 (
156+
x int,
157+
row_start SYS_DATATYPE as row start invisible,
158+
row_end SYS_DATATYPE as row end invisible,
159+
period for system_time (row_start, row_end)
160+
) with system versioning;
161+
insert into t1 values (1), (2);
162+
create or replace view v1 as select * from t1 where x > 1;
163+
update v1 set x= x + 1;
164+
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
165+
x check_row(row_start, row_end)
166+
1 CURRENT ROW
167+
2 HISTORICAL ROW
168+
3 CURRENT ROW
169+
insert v1 values (4);
170+
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
171+
x check_row(row_start, row_end)
172+
1 CURRENT ROW
173+
2 HISTORICAL ROW
174+
3 CURRENT ROW
175+
4 CURRENT ROW
176+
delete from v1 where x < 4;
177+
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
178+
x check_row(row_start, row_end)
179+
1 CURRENT ROW
180+
2 HISTORICAL ROW
181+
3 HISTORICAL ROW
182+
4 CURRENT ROW
183+
# multi-update
184+
create or replace table t2 like t1;
185+
insert into t2 values (1), (2);
186+
create or replace view v2 as select * from t2 where x > 1;
187+
update v1, v2 set v1.x= v1.x + 1, v2.x= v2.x + 1 where v1.x = v2.x + 2;
188+
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
189+
x check_row(row_start, row_end)
190+
1 CURRENT ROW
191+
2 HISTORICAL ROW
192+
3 HISTORICAL ROW
193+
4 HISTORICAL ROW
194+
5 CURRENT ROW
195+
select *, check_row(row_start, row_end) from t2 for system_time all order by x;
196+
x check_row(row_start, row_end)
197+
1 CURRENT ROW
198+
2 HISTORICAL ROW
199+
3 CURRENT ROW
200+
# multi-delete
201+
delete v1, v2 from v1 join v2 where v1.x = v2.x + 2;
202+
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
203+
x check_row(row_start, row_end)
204+
1 CURRENT ROW
205+
2 HISTORICAL ROW
206+
3 HISTORICAL ROW
207+
4 HISTORICAL ROW
208+
5 HISTORICAL ROW
209+
select *, check_row(row_start, row_end) from t2 for system_time all order by x;
210+
x check_row(row_start, row_end)
211+
1 CURRENT ROW
212+
2 HISTORICAL ROW
213+
3 HISTORICAL ROW
214+
drop view v1, v2;
215+
drop tables t1, t2;

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
source suite/versioning/engines.inc;
22
source suite/versioning/common.inc;
33

4+
--echo # Basic + delete from view
45
replace_result $sys_datatype_expl SYS_DATATYPE;
56
eval create or replace table t1(
67
XNo int unsigned,
@@ -31,7 +32,7 @@ select XNo as XNo_vt1 from vt1;
3132
drop view vt1;
3233
drop table t1;
3334

34-
35+
--echo # Check sys_start, sys_end
3536
replace_result $sys_datatype_expl SYS_DATATYPE;
3637
eval create or replace table t1(
3738
x int,
@@ -47,6 +48,7 @@ select * from t1;
4748
select x = 1 as A, sys_start = @sys_start as B, sys_end > sys_start as C from t1 for system_time all;
4849
drop table t1;
4950

51+
--echo # Multi-delete
5052
replace_result $sys_datatype_expl SYS_DATATYPE;
5153
eval create or replace table t1(
5254
x int,
@@ -69,12 +71,6 @@ select x as t2_x_all from t2 for system_time all;
6971
drop table t1;
7072
drop table t2;
7173

72-
--echo # Basic + delete from view
73-
74-
--echo # Check sys_start, sys_end
75-
76-
--echo # Multi-delete
77-
7874
--echo # Update + delete
7975
create or replace table t1 (x int) with system versioning;
8076
insert into t1 values (1);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,4 +517,18 @@ execute immediate 'select * from t1 for update';
517517
drop view v1;
518518
drop tables t, t1, t2, t3, t4;
519519

520+
--echo #
521+
--echo # MDEV-18957 UPDATE with LIMIT clause is wrong for versioned partitioned tables
522+
--echo #
523+
create or replace table t1 (
524+
x int,
525+
a varchar(255)
526+
) with system versioning partition by system_time (partition p1 history, partition pn current);
527+
528+
insert into t1 (x) values (1), (2), (3), (4);
529+
update t1 set a= 'foo' limit 3;
530+
update t1 set a= 'bar' limit 4;
531+
select * from t1;
532+
drop table t1;
533+
520534
--source suite/versioning/common_finish.inc

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

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ prepare stmt from @tmp; execute stmt; drop prepare stmt;
5252

5353
select * from vt1;
5454

55-
--echo # VIEW with parameters [#151]
55+
--echo # VIEW with parameters [tempesta-tech/mariadb#151]
5656
create or replace table t1 (x int) with system versioning;
5757
create or replace view vt1(c) as select x from t1;
5858
--replace_result 18446744073709551615 MAX_RESULT "TIMESTAMP'2038-01-19 03:14:07.999999'" MAX_RESULT
5959
show create view vt1;
6060

61-
--echo # VIEW over JOIN of versioned tables [#153]
61+
--echo # VIEW over JOIN of versioned tables [tempesta-tech/mariadb#153]
6262
create or replace table t1 (a int) with system versioning;
6363
create or replace table t2 (b int) with system versioning;
6464
insert into t1 values (1);
@@ -68,7 +68,7 @@ select * from vt12;
6868
create or replace view vt12 as select * from t1 for system_time as of timestamp ('0-0-0') cross join t2;
6969
select * from vt12;
7070

71-
--echo # VIEW improvements [#183]
71+
--echo # VIEW improvements [tempesta-tech/mariadb#183]
7272
create or replace table t3 (x int);
7373
create or replace view vt1 as select * from t1, t2, t3;
7474
--replace_result 18446744073709551615 MAX_RESULT "TIMESTAMP'2038-01-19 03:14:07.999999'" MAX_RESULT
@@ -80,11 +80,11 @@ create or replace view vt1 as select a, t2.row_end as endo from t3, t1, t2;
8080
--replace_result 18446744073709551615 MAX_RESULT "TIMESTAMP'2038-01-19 03:14:07.999999'" MAX_RESULT
8181
show create view vt1;
8282

83-
--echo # VIEW over UNION [#269]
83+
--echo # VIEW over UNION [tempesta-tech/mariadb#269]
8484
create or replace view vt1 as select * from t1 union select * from t1;
8585
select * from vt1;
8686

87-
--echo # VIEW over UNION with non-versioned [#393]
87+
--echo # VIEW over UNION with non-versioned [tempesta-tech/mariadb#393]
8888
create or replace table t2 (a int);
8989
create or replace view vt1 as select * from t1 union select * from t2;
9090
select * from vt1;
@@ -104,10 +104,10 @@ drop tables t1, t2;
104104
--echo #
105105
--echo # MDEV-15146 SQLError[4122]: View is not system versioned
106106
--echo #
107-
create table t1 (a int) with system versioning;
107+
create or replace table t1 (a int) with system versioning;
108108
insert t1 values (1),(2);
109109
set @a=now(6);
110-
create view v1 as select * from t1;
110+
create or replace view v1 as select * from t1;
111111
delete from t1;
112112
select * from v1;
113113
select * from v1 for system_time as of @a;
@@ -124,4 +124,37 @@ show create view v1;
124124
drop view v1, vt1, vt12;
125125
drop tables t1, t3;
126126

127+
--echo #
128+
--echo # MDEV-18727 improve DML operation of System Versioning
129+
--echo #
130+
--replace_result $sys_datatype_expl SYS_DATATYPE
131+
eval create or replace table t1 (
132+
x int,
133+
row_start $sys_datatype_expl as row start invisible,
134+
row_end $sys_datatype_expl as row end invisible,
135+
period for system_time (row_start, row_end)
136+
) with system versioning;
137+
insert into t1 values (1), (2);
138+
create or replace view v1 as select * from t1 where x > 1;
139+
update v1 set x= x + 1;
140+
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
141+
insert v1 values (4);
142+
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
143+
delete from v1 where x < 4;
144+
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
145+
--echo # multi-update
146+
create or replace table t2 like t1;
147+
insert into t2 values (1), (2);
148+
create or replace view v2 as select * from t2 where x > 1;
149+
update v1, v2 set v1.x= v1.x + 1, v2.x= v2.x + 1 where v1.x = v2.x + 2;
150+
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
151+
select *, check_row(row_start, row_end) from t2 for system_time all order by x;
152+
--echo # multi-delete
153+
delete v1, v2 from v1 join v2 where v1.x = v2.x + 2;
154+
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
155+
select *, check_row(row_start, row_end) from t2 for system_time all order by x;
156+
157+
drop view v1, v2;
158+
drop tables t1, t2;
159+
127160
--source suite/versioning/common_finish.inc

sql/ha_partition.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4538,7 +4538,7 @@ int ha_partition::delete_row(const uchar *buf)
45384538
or last historical partition, but DELETE HISTORY can delete from any
45394539
historical partition. So, skip the check in this case.
45404540
*/
4541-
if (!thd->lex->vers_conditions.is_set()) // if not DELETE HISTORY
4541+
if (!thd->lex->vers_conditions.delete_history)
45424542
{
45434543
uint32 part_id;
45444544
error= get_part_for_buf(buf, m_rec0, m_part_info, &part_id);

sql/mysqld.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ enum vers_system_time_t
189189
SYSTEM_TIME_AS_OF,
190190
SYSTEM_TIME_FROM_TO,
191191
SYSTEM_TIME_BETWEEN,
192-
SYSTEM_TIME_BEFORE,
192+
SYSTEM_TIME_BEFORE, // used for DELETE HISTORY ... BEFORE
193+
SYSTEM_TIME_HISTORY, // used for DELETE HISTORY
193194
SYSTEM_TIME_ALL
194195
};
195196

0 commit comments

Comments
 (0)