| 1 |
create table t (id int, s date, e date, period for apptime(s,e)); |
| 2 |
insert into t values(1, '1999-01-01', '2018-12-12'); |
| 3 |
insert into t values(1, '1999-01-01', '2017-01-01'); |
| 4 |
insert into t values(1, '2017-01-01', '2019-01-01'); |
| 5 |
insert into t values(2, '1998-01-01', '2018-12-12'); |
| 6 |
insert into t values(3, '1997-01-01', '2015-01-01'); |
| 7 |
insert into t values(4, '2016-01-01', '2020-01-01'); |
| 8 |
insert into t values(5, '2010-01-01', '2015-01-01'); |
| 9 |
create or replace table t1 (id int, s date, e date, period for apptime(s,e)); |
| 10 |
insert t1 select * from t; |
| 11 |
create or replace table t2 (id int, s date, e date, period for apptime(s,e)); |
| 12 |
insert t2 select * from t; |
| 13 |
update t for portion of apptime from '2000-01-01' to '2018-01-01' |
| 14 |
set id=id + 6; |
| 15 |
select * from t; |
| 16 |
id s e |
| 17 |
1 1999-01-01 2000-01-01 |
| 18 |
1 1999-01-01 2000-01-01 |
| 19 |
1 2018-01-01 2018-12-12 |
| 20 |
1 2018-01-01 2019-01-01 |
| 21 |
10 2016-01-01 2018-01-01 |
| 22 |
11 2010-01-01 2015-01-01 |
| 23 |
2 1998-01-01 2000-01-01 |
| 24 |
2 2018-01-01 2018-12-12 |
| 25 |
3 1997-01-01 2000-01-01 |
| 26 |
4 2018-01-01 2020-01-01 |
| 27 |
7 2000-01-01 2017-01-01 |
| 28 |
7 2000-01-01 2018-01-01 |
| 29 |
7 2017-01-01 2018-01-01 |
| 30 |
8 2000-01-01 2018-01-01 |
| 31 |
9 2000-01-01 2015-01-01 |
| 32 |
# Check triggers |
| 33 |
create or replace table log_tbl(id int auto_increment primary key, log text) engine=myisam; |
| 34 |
create or replace procedure log(s text) |
| 35 |
insert into log_tbl(log) values(s); |
| 36 |
create trigger tr1upd_t1 before update on t1 |
| 37 |
for each row call log(CONCAT('>UPD: ', old.id, ", ", old.s, ", ", old.e, ' -> ', new.id, ", ", new.s, ", ", new.e)); |
| 38 |
create trigger tr2upd_t1 after update on t1 |
| 39 |
for each row call log(CONCAT('<UPD: ', old.id, ", ", old.s, ", ", old.e, ' -> ', new.id, ", ", new.s, ", ", new.e)); |
| 40 |
create trigger tr1del_t1 before delete on t1 |
| 41 |
for each row call log(CONCAT('>DEL: ', old.id, ", ", old.s, ", ", old.e)); |
| 42 |
create trigger tr2del_t1 after delete on t1 |
| 43 |
for each row call log(CONCAT('<DEL: ', old.id, ", ", old.s, ", ", old.e)); |
| 44 |
create trigger tr1ins_t1 before insert on t1 |
| 45 |
for each row call log(CONCAT('>INS: ', new.id, ", ", new.s, ", ", new.e)); |
| 46 |
create trigger tr2ins_t1 after insert on t1 |
| 47 |
for each row call log(CONCAT('<INS: ', new.id, ", ", new.s, ", ", new.e)); |
| 48 |
update t1 for portion of apptime from '2000-01-01' to '2018-01-01' |
| 49 |
set id=id + 6; |
| 50 |
select * from t1; |
| 51 |
id s e |
| 52 |
1 1999-01-01 2000-01-01 |
| 53 |
1 1999-01-01 2000-01-01 |
| 54 |
1 2018-01-01 2018-12-12 |
| 55 |
1 2018-01-01 2019-01-01 |
| 56 |
10 2016-01-01 2018-01-01 |
| 57 |
11 2010-01-01 2015-01-01 |
| 58 |
2 1998-01-01 2000-01-01 |
| 59 |
2 2018-01-01 2018-12-12 |
| 60 |
3 1997-01-01 2000-01-01 |
| 61 |
4 2018-01-01 2020-01-01 |
| 62 |
7 2000-01-01 2017-01-01 |
| 63 |
7 2000-01-01 2018-01-01 |
| 64 |
7 2017-01-01 2018-01-01 |
| 65 |
8 2000-01-01 2018-01-01 |
| 66 |
9 2000-01-01 2015-01-01 |
| 67 |
select * from log_tbl order by id; |
| 68 |
id log |
| 69 |
1 >UPD: 1, 1999-01-01, 2018-12-12 -> 7, 2000-01-01, 2018-01-01 |
| 70 |
2 >INS: 1, 1999-01-01, 2000-01-01 |
| 71 |
3 <INS: 1, 1999-01-01, 2000-01-01 |
| 72 |
4 >INS: 1, 2018-01-01, 2018-12-12 |
| 73 |
5 <INS: 1, 2018-01-01, 2018-12-12 |
| 74 |
6 <UPD: 1, 1999-01-01, 2018-12-12 -> 7, 2000-01-01, 2018-01-01 |
| 75 |
7 >UPD: 1, 1999-01-01, 2017-01-01 -> 7, 2000-01-01, 2017-01-01 |
| 76 |
8 >INS: 1, 1999-01-01, 2000-01-01 |
| 77 |
9 <INS: 1, 1999-01-01, 2000-01-01 |
| 78 |
10 <UPD: 1, 1999-01-01, 2017-01-01 -> 7, 2000-01-01, 2017-01-01 |
| 79 |
11 >UPD: 1, 2017-01-01, 2019-01-01 -> 7, 2017-01-01, 2018-01-01 |
| 80 |
12 >INS: 1, 2018-01-01, 2019-01-01 |
| 81 |
13 <INS: 1, 2018-01-01, 2019-01-01 |
| 82 |
14 <UPD: 1, 2017-01-01, 2019-01-01 -> 7, 2017-01-01, 2018-01-01 |
| 83 |
15 >UPD: 2, 1998-01-01, 2018-12-12 -> 8, 2000-01-01, 2018-01-01 |
| 84 |
16 >INS: 2, 1998-01-01, 2000-01-01 |
| 85 |
17 <INS: 2, 1998-01-01, 2000-01-01 |
| 86 |
18 >INS: 2, 2018-01-01, 2018-12-12 |
| 87 |
19 <INS: 2, 2018-01-01, 2018-12-12 |
| 88 |
20 <UPD: 2, 1998-01-01, 2018-12-12 -> 8, 2000-01-01, 2018-01-01 |
| 89 |
21 >UPD: 3, 1997-01-01, 2015-01-01 -> 9, 2000-01-01, 2015-01-01 |
| 90 |
22 >INS: 3, 1997-01-01, 2000-01-01 |
| 91 |
23 <INS: 3, 1997-01-01, 2000-01-01 |
| 92 |
24 <UPD: 3, 1997-01-01, 2015-01-01 -> 9, 2000-01-01, 2015-01-01 |
| 93 |
25 >UPD: 4, 2016-01-01, 2020-01-01 -> 10, 2016-01-01, 2018-01-01 |
| 94 |
26 >INS: 4, 2018-01-01, 2020-01-01 |
| 95 |
27 <INS: 4, 2018-01-01, 2020-01-01 |
| 96 |
28 <UPD: 4, 2016-01-01, 2020-01-01 -> 10, 2016-01-01, 2018-01-01 |
| 97 |
29 >UPD: 5, 2010-01-01, 2015-01-01 -> 11, 2010-01-01, 2015-01-01 |
| 98 |
30 <UPD: 5, 2010-01-01, 2015-01-01 -> 11, 2010-01-01, 2015-01-01 |
| 99 |
# INSERT trigger only also works |
| 100 |
create or replace table log_tbl(id int auto_increment primary key, log text) engine=myisam; |
| 101 |
create or replace procedure log(s text) |
| 102 |
insert into log_tbl(log) values(s); |
| 103 |
create trigger tr1upd_t2 before update on t2 |
| 104 |
for each row call log(CONCAT('>UPD: ', old.id, ", ", old.s, ", ", old.e, ' -> ', new.id, ", ", new.s, ", ", new.e)); |
| 105 |
create trigger tr2upd_t2 after update on t2 |
| 106 |
for each row call log(CONCAT('<UPD: ', old.id, ", ", old.s, ", ", old.e, ' -> ', new.id, ", ", new.s, ", ", new.e)); |
| 107 |
create trigger tr1del_t2 before delete on t2 |
| 108 |
for each row call log(CONCAT('>DEL: ', old.id, ", ", old.s, ", ", old.e)); |
| 109 |
create trigger tr2del_t2 after delete on t2 |
| 110 |
for each row call log(CONCAT('<DEL: ', old.id, ", ", old.s, ", ", old.e)); |
| 111 |
create trigger tr1ins_t2 before insert on t2 |
| 112 |
for each row call log(CONCAT('>INS: ', new.id, ", ", new.s, ", ", new.e)); |
| 113 |
create trigger tr2ins_t2 after insert on t2 |
| 114 |
for each row call log(CONCAT('<INS: ', new.id, ", ", new.s, ", ", new.e)); |
| 115 |
drop trigger tr1upd_t2; |
| 116 |
drop trigger tr2upd_t2; |
| 117 |
update t2 for portion of apptime from '2000-01-01' to '2018-01-01' |
| 118 |
set id=id + 6; |
| 119 |
select * from t2; |
| 120 |
id s e |
| 121 |
1 1999-01-01 2000-01-01 |
| 122 |
1 1999-01-01 2000-01-01 |
| 123 |
1 2018-01-01 2018-12-12 |
| 124 |
1 2018-01-01 2019-01-01 |
| 125 |
10 2016-01-01 2018-01-01 |
| 126 |
11 2010-01-01 2015-01-01 |
| 127 |
2 1998-01-01 2000-01-01 |
| 128 |
2 2018-01-01 2018-12-12 |
| 129 |
3 1997-01-01 2000-01-01 |
| 130 |
4 2018-01-01 2020-01-01 |
| 131 |
7 2000-01-01 2017-01-01 |
| 132 |
7 2000-01-01 2018-01-01 |
| 133 |
7 2017-01-01 2018-01-01 |
| 134 |
8 2000-01-01 2018-01-01 |
| 135 |
9 2000-01-01 2015-01-01 |
| 136 |
select * from log_tbl order by id; |
| 137 |
id log |
| 138 |
1 >INS: 1, 1999-01-01, 2000-01-01 |
| 139 |
2 <INS: 1, 1999-01-01, 2000-01-01 |
| 140 |
3 >INS: 1, 2018-01-01, 2018-12-12 |
| 141 |
4 <INS: 1, 2018-01-01, 2018-12-12 |
| 142 |
5 >INS: 1, 1999-01-01, 2000-01-01 |
| 143 |
6 <INS: 1, 1999-01-01, 2000-01-01 |
| 144 |
7 >INS: 1, 2018-01-01, 2019-01-01 |
| 145 |
8 <INS: 1, 2018-01-01, 2019-01-01 |
| 146 |
9 >INS: 2, 1998-01-01, 2000-01-01 |
| 147 |
10 <INS: 2, 1998-01-01, 2000-01-01 |
| 148 |
11 >INS: 2, 2018-01-01, 2018-12-12 |
| 149 |
12 <INS: 2, 2018-01-01, 2018-12-12 |
| 150 |
13 >INS: 3, 1997-01-01, 2000-01-01 |
| 151 |
14 <INS: 3, 1997-01-01, 2000-01-01 |
| 152 |
15 >INS: 4, 2018-01-01, 2020-01-01 |
| 153 |
16 <INS: 4, 2018-01-01, 2020-01-01 |
| 154 |
select * from t for portion of apptime from 0 to 1 for system_time all; |
| 155 |
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 'portion of apptime from 0 to 1 for system_time all' at line 1 |
| 156 |
update t for portion of apptime from 0 to 1 for system_time all set id=1; |
| 157 |
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 'system_time all set id=1' at line 1 |
| 158 |
# Modifying period start/end fields is forbidden. |
| 159 |
# SQL16: 14.14 <update statement: searched>, Syntax Rules, 7)a)ii) |
| 160 |
# Neither BSTARTCOL nor BENDCOL shall be an explicit <object column> |
| 161 |
# contained in the <set clause list>. |
| 162 |
update t for portion of apptime from '2000-01-01' to '2018-01-01' |
| 163 |
set id= id + 6, s=subdate(s, 5), e=adddate(e, 5); |
| 164 |
ERROR HY000: Column `s` used in period `apptime` specified in update SET list |
| 165 |
# Precision timestamps |
| 166 |
create or replace table t (id int, s timestamp(5), e timestamp(5), |
| 167 |
period for apptime(s,e)); |
| 168 |
insert into t values(1, '1999-01-01', '2018-12-12'); |
| 169 |
insert into t values(1, '1999-01-01', '2017-01-01'); |
| 170 |
update t for portion of apptime from '2000-01-01 00:00:00.00015' |
| 171 |
to '2018-01-01 12:34:56.31415' |
| 172 |
set id= id + 5; |
| 173 |
select * from t; |
| 174 |
id s e |
| 175 |
1 1999-01-01 00:00:00.00000 2000-01-01 00:00:00.00015 |
| 176 |
1 1999-01-01 00:00:00.00000 2000-01-01 00:00:00.00015 |
| 177 |
1 2018-01-01 12:34:56.31415 2018-12-12 00:00:00.00000 |
| 178 |
6 2000-01-01 00:00:00.00015 2017-01-01 00:00:00.00000 |
| 179 |
6 2000-01-01 00:00:00.00015 2018-01-01 12:34:56.31415 |
| 180 |
# Strings |
| 181 |
create or replace table t (id int, str text, s date, e date, |
| 182 |
period for apptime(s,e)); |
| 183 |
insert into t values(1, 'data', '1999-01-01', '2018-12-12'); |
| 184 |
insert into t values(1, 'other data', '1999-01-01', '2018-12-12'); |
| 185 |
update t for portion of apptime from '2000-01-01' to '2018-01-01' |
| 186 |
set id= id + 5; |
| 187 |
select * from t; |
| 188 |
id str s e |
| 189 |
1 data 1999-01-01 2000-01-01 |
| 190 |
1 data 2018-01-01 2018-12-12 |
| 191 |
1 other data 1999-01-01 2000-01-01 |
| 192 |
1 other data 2018-01-01 2018-12-12 |
| 193 |
6 data 2000-01-01 2018-01-01 |
| 194 |
6 other data 2000-01-01 2018-01-01 |
| 195 |
# multi-table UPDATE is impossible |
| 196 |
create or replace table t1(x int); |
| 197 |
update t for portion of apptime from '2000-01-01' to '2018-01-01', t1 |
| 198 |
set t.id= t.id + 5; |
| 199 |
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 ' t1 |
| 200 |
set t.id= t.id + 5' at line 1 |
| 201 |
update t1 set x= (select id from t for portion of apptime from '2000-01-01' to '2018-01-01'); |
| 202 |
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 'portion of apptime from '2000-01-01' to '2018-01-01')' at line 1 |
| 203 |
# single-table views |
| 204 |
create or replace view v1 as select * from t where id<10; |
| 205 |
update v1 for portion of apptime from '2000-01-01' to '2018-01-01' set id= id + 5; |
| 206 |
ERROR 42S02: 'v1' is a view |
| 207 |
# multi-table views |
| 208 |
create or replace view v1 as select * from t, t1 where x=id; |
| 209 |
update v1 for portion of apptime from '2000-01-01' to '2018-01-01' set id= id + 5; |
| 210 |
ERROR 42S02: 'v1' is a view |
| 211 |
# SQL16: 14.14 <update statement: searched>, Syntax Rules, 7)a) iii-iv) |
| 212 |
# Let FROMVAL be <point in time 1>. FROMVAL shall not generally contain a |
| 213 |
# reference to a column of T or a <routine invocation> |
| 214 |
# whose subject routine is an SQL-invoked routine that |
| 215 |
# is possibly non-deterministic or that possibly modifies SQL-data. |
| 216 |
# ...Same for <point in time 2> (TOVAL) |
| 217 |
update t for portion of apptime from 5*(5+s) to 1 set t.id= t.id + 5; |
| 218 |
ERROR HY000: Expression in FOR PORTION OF must be constant |
| 219 |
update t for portion of apptime from 1 to e set t.id= t.id + 5; |
| 220 |
ERROR HY000: Expression in FOR PORTION OF must be constant |
| 221 |
set @s= '2000-01-01'; |
| 222 |
set @e= '2018-01-01'; |
| 223 |
create or replace function f() returns date return @e; |
| 224 |
create or replace function g() returns date not deterministic return @e; |
| 225 |
create or replace function h() returns date deterministic return @e; |
| 226 |
update t for portion of apptime from @s to f() set t.id= t.id + 5; |
| 227 |
ERROR HY000: Expression in FOR PORTION OF must be constant |
| 228 |
update t for portion of apptime from @s to g() set t.id= t.id + 5; |
| 229 |
ERROR HY000: Expression in FOR PORTION OF must be constant |
| 230 |
# success |
| 231 |
update t for portion of apptime from @s to h() set t.id= t.id + 5; |
| 232 |
update t for portion of apptime from (select s from t2 limit 1) to h() set t.id= t.id + 5; |
| 233 |
ERROR HY000: Expression in FOR PORTION OF must be constant |
| 234 |
# auto_inrement field is updated |
| 235 |
create or replace table t (id int primary key auto_increment, x int, |
| 236 |
s date, e date, period for apptime(s, e)); |
| 237 |
insert into t values (default, 1, '1999-01-01', '2018-12-12'); |
| 238 |
update t for portion of apptime from '2000-01-01' to '2018-01-01' set x= x + 5; |
| 239 |
select * from t; |
| 240 |
id x s e |
| 241 |
1 6 2000-01-01 2018-01-01 |
| 242 |
2 1 1999-01-01 2000-01-01 |
| 243 |
3 1 2018-01-01 2018-12-12 |
| 244 |
truncate t; |
| 245 |
insert into t values (default, 1, '1999-01-01', '2018-12-12'); |
| 246 |
update t for portion of apptime from '2000-01-01' to '2018-01-01' set x= 1; |
| 247 |
select * from t; |
| 248 |
id x s e |
| 249 |
1 1 2000-01-01 2018-01-01 |
| 250 |
2 1 1999-01-01 2000-01-01 |
| 251 |
3 1 2018-01-01 2018-12-12 |
| 252 |
# generated columns are updated |
| 253 |
create or replace table t (x int, s date, e date, |
| 254 |
xs date as (s) stored, xe date as (e) stored, |
| 255 |
period for apptime(s, e)); |
| 256 |
insert into t values(1, '1999-01-01', '2018-12-12', default, default); |
| 257 |
select * from t; |
| 258 |
x s e xs xe |
| 259 |
1 1999-01-01 2018-12-12 1999-01-01 2018-12-12 |
| 260 |
update t for portion of apptime from '2000-01-01' to '2018-01-01' set x= x + 5; |
| 261 |
select *, xs=s and xe=e from t; |
| 262 |
x s e xs xe xs=s and xe=e |
| 263 |
1 1999-01-01 2000-01-01 1999-01-01 2000-01-01 1 |
| 264 |
1 2018-01-01 2018-12-12 2018-01-01 2018-12-12 1 |
| 265 |
6 2000-01-01 2018-01-01 2000-01-01 2018-01-01 1 |
| 266 |
# MDEV-18921 Server crashes in bitmap_bits_set or bitmap_is_set upon |
| 267 |
# UPDATE IGNORE .. FOR PORTION with binary logging |
| 268 |
create or replace table t1 (f int, s date, e date, period for app(s,e)); |
| 269 |
insert into t1 values (1,'2016-09-21','2019-06-14'); |
| 270 |
update ignore t1 for portion of app from '2019-03-13' to '2019-03-14' set f = 1; |
| 271 |
drop table t,t1,t2,log_tbl; |
| 272 |
drop view v1; |
| 273 |
drop function f; |
| 274 |
drop function g; |
| 275 |
drop function h; |
| 276 |
drop procedure log; |
| 277 |
# |
| 278 |
# MDEV-21471 ER_CRASHED_ON_USAGE upon UPDATE FOR PORTION on Aria table |
| 279 |
# |
| 280 |
create table t1 (s date, e date, period for app(s,e), f varchar(8)) engine=aria row_format=fixed; |
| 281 |
insert into t1 values ('2024-05-13','2026-03-25','foo'); |
| 282 |
update t1 for portion of app from '2024-04-02' to '2026-03-15' set f = 'bar'; |
| 283 |
drop table t1; |
| 284 |
# MDEV-19130 Assertion |
| 285 |
# `next_insert_id >= auto_inc_interval_for_cur_row.minimum()' |
| 286 |
# failed in handler::update_auto_increment after error 167 |
| 287 |
create table t1 (id int auto_increment, f int, s datetime, e datetime, period for p(s,e), primary key(id)); |
| 288 |
insert into t1 (s,e) values ('1994-01-06','2004-11-30'),('1994-06-21','1997-06-20'); |
| 289 |
update ignore t1 set id = 2429681664; |
| 290 |
Warnings: |
| 291 |
Warning 1264 Out of range value for column 'id' at row 1 |
| 292 |
Warning 1264 Out of range value for column 'id' at row 2 |
| 293 |
update ignore t1 for portion of p from '1995-07-06' to '2009-01-12' set f = 1; |
| 294 |
drop table t1; |
| 295 |
# |
| 296 |
# MDEV-22805 SIGSEGV in check_fields on UPDATE (optimized builds) | Assertion `thd->lex->sql_command == SQLCOM_UPDATE' failed. |
| 297 |
# |
| 298 |
CREATE TABLE t1 (a INT, b DATE, c DATE, PERIOD FOR APPTIME(b, c)); |
| 299 |
INSERT INTO t1 VALUES(1, '1999-01-01', '2018-12-12'); |
| 300 |
UPDATE t1 FOR PORTION OF APPTIME FROM (SELECT '1999-01-01' FROM t1 WHERE a=2) TO '2018-01-01' SET a = 100; |
| 301 |
ERROR 42000: This version of MariaDB doesn't yet support 'updating and querying the same temporal periods table' |
| 302 |
set @tmp= "UPDATE t1 FOR PORTION OF APPTIME FROM (SELECT '1999-01-01' FROM t1 WHERE a=2) TO '2018-01-01' SET a = 100"; |
| 303 |
execute immediate @tmp; |
| 304 |
ERROR 42000: This version of MariaDB doesn't yet support 'updating and querying the same temporal periods table' |
| 305 |
CREATE VIEW v1 AS SELECT * FROM t1; |
| 306 |
UPDATE v1 FOR PORTION OF APPTIME FROM (SELECT '1999-01-01' FROM t1 WHERE a=2) TO '2018-01-01' SET a = 100; |
| 307 |
ERROR 42S02: 'v1' is a view |
| 308 |
DROP VIEW v1; |
| 309 |
DROP TABLE t1; |