Skip to content

Commit ddc416c

Browse files
committed
MDEV-20077 Warning on full history partition is delayed until next DML statement
Moved LIMIT warning from vers_set_hist_part() to new call vers_check_limit() at table unlock phase. At that point read_partitions bitmap is already pruned by DML code (see prune_partitions(), find_used_partitions()) so we have to set corresponding bits for working history partition. Also we don't do my_error(ME_WARNING|ME_ERROR_LOG), because at that point it doesn't update warnings number, so command reports 0 warnings (but warning list is still updated). Instead we do push_warning_printf() and sql_print_warning() separately. Under LOCK TABLES external_lock(F_UNLCK) is not executed. There is start_stmt(), but no corresponding "stop_stmt()". So for that mode we call vers_check_limit() directly from close_thread_tables(). Test result has been changed according to new LIMIT and warning printing algorithm. For convenience all LIMIT warnings are marked with "You see warning above ^". TODO MDEV-20345 fixed. Now vers_history_generating() contains fine-grained list of DML-commands that can generate history (and TODO mechanism worked well).
1 parent ea2f099 commit ddc416c

File tree

9 files changed

+530
-49
lines changed

9 files changed

+530
-49
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ partition pn current);
6565
insert into t values (1);
6666
update t set a= 2;
6767
update t set a= 3;
68+
Warnings:
69+
Warning 4114 Versioned table `test`.`t`: partition `p1` is full, add more HISTORY partitions
70+
# You see warning above ^
6871
delete history from t;
6972
select * from t for system_time all;
7073
a

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

Lines changed: 240 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ x
244244
6
245245
delete from t1 where x < 4;
246246
delete from t1;
247+
Warnings:
248+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
249+
# You see warning above ^
247250
select * from t1 partition (p0);
248251
x
249252
1
@@ -255,12 +258,11 @@ x
255258
5
256259
6
257260
insert into t1 values (7), (8);
258-
Warnings:
259-
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
260261
### warn about full partition
261262
delete from t1;
262263
Warnings:
263264
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
265+
# You see warning above ^
264266
select * from t1 partition (p1) order by x;
265267
x
266268
4
@@ -320,20 +322,26 @@ x
320322
### warn about full partition
321323
delete from t1 where x < 3;
322324
delete from t1;
325+
Warnings:
326+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
327+
# You see warning above ^
323328
delete from t1;
329+
Warnings:
330+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
331+
# You see warning above ^ (no matter if nothing was deleted)
324332
select * from t1 partition (p0sp0);
325333
x
326334
1
327-
3
328-
5
329335
select * from t1 partition (p0sp1);
330336
x
331337
2
332-
4
333338
select * from t1 partition (p1sp0);
334339
x
340+
3
341+
5
335342
select * from t1 partition (p1sp1);
336343
x
344+
4
337345
create or replace table t1 (
338346
a bigint,
339347
row_start SYS_DATATYPE as row start invisible,
@@ -415,7 +423,13 @@ partition p1 history,
415423
partition p2 history,
416424
partition pn current);
417425
delete from t1 where x = 1;
426+
Warnings:
427+
Warning 4114 Versioned table `test`.`t1`: partition `p2` is full, add more HISTORY partitions
428+
# You see warning above ^
418429
delete from t1 where x = 2;
430+
Warnings:
431+
Warning 4114 Versioned table `test`.`t1`: partition `p2` is full, add more HISTORY partitions
432+
# You see warning above ^
419433
# MDEV-14923 Assertion upon INSERT into locked versioned partitioned table
420434
create or replace table t1 (x int) with system versioning
421435
partition by system_time (partition p1 history, partition pn current);
@@ -577,9 +591,13 @@ create or replace table t1 (x int) with system versioning partition by system_ti
577591
lock tables t1 write;
578592
insert into t1 values (0), (1), (2), (3);
579593
delete from t1 where x < 3;
594+
Warnings:
595+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
596+
# You see warning above ^
580597
delete from t1;
581598
Warnings:
582599
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
600+
# You see warning above ^
583601
unlock tables;
584602
#
585603
# MDEV-20336 Assertion bitmap_is_set(read_partitions) upon SELECT FOR UPDATE from versioned table
@@ -680,6 +698,9 @@ partition by system_time limit 1
680698
insert into t1 values (null);
681699
update t1 set f= 'foo';
682700
update t1 set f= 'bar';
701+
Warnings:
702+
Warning 4114 Versioned table `test`.`t1`: partition `p2` is full, add more HISTORY partitions
703+
# You see warning above ^
683704
create or replace view v1 as select * from t1 for system_time all;
684705
update v1 set f= '';
685706
ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
@@ -846,23 +867,20 @@ create table t1 (x int) with system versioning
846867
partition by system_time limit 1 (
847868
partition p0 history,
848869
partition p1 history,
870+
partition p2 history, # p2 just disables warning about p1 partition full
849871
partition pn current);
850872
insert into t1 values (0);
851873
update t1 set x= x + 1;
852874
update t1 set x= x + 1;
853-
update t1 set x= x + 1;
854-
update t1 set x= x + 1;
855875
select * from t1 partition (p0);
856876
x
857877
0
858-
1
859878
select * from t1 partition (p1);
860879
x
861-
2
862-
3
880+
1
863881
select * from t1 partition (pn);
864882
x
865-
4
883+
2
866884
# TRUNCATE TABLE deletes history and current data
867885
truncate table t1;
868886
select * from t1 partition (p0);
@@ -874,8 +892,6 @@ x
874892
insert into t1 values (0);
875893
update t1 set x= x + 1;
876894
update t1 set x= x + 1;
877-
update t1 set x= x + 1;
878-
update t1 set x= x + 1;
879895
# TRUNCATE PARTITION ALL does the same
880896
alter table t1 truncate partition all;
881897
select * from t1 partition (p0);
@@ -887,29 +903,235 @@ x
887903
insert into t1 values (0);
888904
update t1 set x= x + 1;
889905
update t1 set x= x + 1;
890-
update t1 set x= x + 1;
891-
update t1 set x= x + 1;
892906
# TRUNCATE PARTITION deletes data from HISTORY partition
893907
alter table t1 truncate partition p1;
894908
select * from t1 partition (p0);
895909
x
896910
0
897-
1
898911
select * from t1 partition (p1);
899912
x
900913
select * from t1 partition (pn);
901914
x
902-
4
915+
2
903916
# or from CURRENT partition
904917
alter table t1 truncate partition pn;
905918
select * from t1 partition (p0);
906919
x
907920
0
908-
1
909921
select * from t1 partition (p1);
910922
x
911923
select * from t1 partition (pn);
912924
x
913925
drop table t1;
926+
#
927+
# MDEV-20077 Warning on full history partition is delayed until next DML statement
928+
#
929+
# DELETE
930+
create table t1 (x int) with system versioning
931+
partition by system_time limit 100 (
932+
partition p0 history,
933+
partition p1 history,
934+
partition pn current);
935+
insert into t1 select seq from seq_0_to_200;
936+
# p0 is filled with 100 records (no warnings):
937+
delete from t1 where x <= 99;
938+
# p1 is filled with 1 + 100 records (warning is printed):
939+
delete from t1 where x <= 100;
940+
delete from t1;
941+
Warnings:
942+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
943+
# You see warning above ^
944+
select count(*) from t1 partition (p0);
945+
count(*)
946+
100
947+
select count(*) from t1 partition (p1);
948+
count(*)
949+
101
950+
drop table t1;
951+
# DELETE under LOCK TABLES
952+
create table t1 (x int) with system versioning
953+
partition by system_time limit 100 (
954+
partition p0 history,
955+
partition p1 history,
956+
partition pn current);
957+
insert into t1 select seq from seq_0_to_200;
958+
lock tables t1 write;
959+
# (LOCK TABLES) p0 is filled with 100 records (no warnings):
960+
delete from t1 where x <= 99;
961+
# (LOCK TABLES) p1 is filled with 1 + 100 records (warning is printed):
962+
delete from t1 where x <= 100;
963+
delete from t1;
964+
Warnings:
965+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
966+
# You see warning above ^
967+
unlock tables;
968+
select count(*) from t1 partition (p0);
969+
count(*)
970+
100
971+
select count(*) from t1 partition (p1);
972+
count(*)
973+
101
974+
drop table t1;
975+
# DELETE multitable
976+
create table t1 (x int) with system versioning
977+
partition by system_time limit 100 (
978+
partition p0 history,
979+
partition p1 history,
980+
partition pn current);
981+
create table t2 (y int);
982+
insert into t1 select seq from seq_0_to_200;
983+
insert into t2 select seq from seq_0_to_3;
984+
delete t1, t2 from t1 join t2 where x < 50 and y = 0;
985+
delete t1, t2 from t1 join t2 where x < 100 and y = 1;
986+
delete t1, t2 from t1 join t2 where x < 150 and y = 2;
987+
delete t1, t2 from t1 join t2;
988+
Warnings:
989+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
990+
# You see warning above ^
991+
select count(*) from t1 partition (p0);
992+
count(*)
993+
100
994+
select count(*) from t1 partition (p1);
995+
count(*)
996+
101
997+
drop table t1;
998+
# UDPATE
999+
create table t1 (x int) with system versioning
1000+
partition by system_time limit 100 (
1001+
partition p0 history,
1002+
partition p1 history,
1003+
partition pn current);
1004+
insert into t1 select seq from seq_0_to_49;
1005+
update t1 set x= x + 1;
1006+
update t1 set x= x + 1;
1007+
update t1 set x= x + 1;
1008+
update t1 set x= x + 1;
1009+
Warnings:
1010+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
1011+
# You see warning above ^
1012+
select count(*) from t1 partition (p0);
1013+
count(*)
1014+
100
1015+
select count(*) from t1 partition (p1);
1016+
count(*)
1017+
100
1018+
drop tables t1, t2;
1019+
# UPDATE multitable
1020+
create table t1 (x int) with system versioning
1021+
partition by system_time limit 100 (
1022+
partition p0 history,
1023+
partition p1 history,
1024+
partition pn current);
1025+
create table t2 (y int);
1026+
insert into t1 select seq from seq_0_to_49;
1027+
insert into t2 values (5);
1028+
update t1, t2 set x= x + 1;
1029+
update t1, t2 set x= x + 1;
1030+
update t1, t2 set x= x + 1;
1031+
update t1, t2 set x= x + 1;
1032+
Warnings:
1033+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
1034+
# You see warning above ^
1035+
select count(*) from t1 partition (p0);
1036+
count(*)
1037+
100
1038+
select count(*) from t1 partition (p1);
1039+
count(*)
1040+
100
1041+
drop tables t1, t2;
1042+
# INSERT .. ON DUPLICATE KEY UPDATE (ODKU)
1043+
create table t1 (x int primary key) with system versioning
1044+
partition by system_time limit 100 (
1045+
partition p0 history,
1046+
partition p1 history,
1047+
partition pn current);
1048+
insert into t1 select seq from seq_0_to_100;
1049+
delete from t1 where x <= 99;
1050+
insert into t1 values (100) on duplicate key update x= 400;
1051+
select count(*) from t1 partition (p0);
1052+
count(*)
1053+
100
1054+
select count(*) from t1 partition (p1);
1055+
count(*)
1056+
1
1057+
drop table t1;
1058+
# INSERT .. SELECT .. ON DUPLICATE KEY UPDATE (ODKU)
1059+
create table t1 (x int primary key) with system versioning
1060+
partition by system_time limit 100 (
1061+
partition p0 history,
1062+
partition p1 history,
1063+
partition pn current);
1064+
create table t2 (y int);
1065+
insert into t2 values (100);
1066+
insert into t1 select seq from seq_0_to_100;
1067+
delete from t1 where x <= 99;
1068+
insert into t1 select * from t2 on duplicate key update x= 500;
1069+
select count(*) from t1 partition (p0);
1070+
count(*)
1071+
100
1072+
select count(*) from t1 partition (p1);
1073+
count(*)
1074+
1
1075+
drop tables t1, t2;
1076+
# REPLACE
1077+
create table t1 (x int primary key) with system versioning
1078+
partition by system_time limit 100 (
1079+
partition p0 history,
1080+
partition p1 history,
1081+
partition pn current);
1082+
insert into t1 select seq from seq_0_to_100;
1083+
delete from t1 where x < 99;
1084+
replace t1 values (100);
1085+
replace t1 values (100);
1086+
select count(*) from t1 partition (p0);
1087+
count(*)
1088+
100
1089+
select count(*) from t1 partition (p1);
1090+
count(*)
1091+
1
1092+
drop table t1;
1093+
# LOAD DATA .. REPLACE
1094+
create table t1 (x int primary key) with system versioning
1095+
partition by system_time limit 100 (
1096+
partition p0 history,
1097+
partition p1 history,
1098+
partition pn current);
1099+
insert into t1 select seq from seq_0_to_49;
1100+
select x into outfile 'MDEV-20077.data' from t1;
1101+
load data infile 'MDEV-20077.data' replace into table t1 (x);
1102+
load data infile 'MDEV-20077.data' replace into table t1 (x);
1103+
load data infile 'MDEV-20077.data' replace into table t1 (x);
1104+
load data infile 'MDEV-20077.data' replace into table t1 (x);
1105+
Warnings:
1106+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
1107+
# You see warning above ^
1108+
select count(*) from t1 partition (p0);
1109+
count(*)
1110+
100
1111+
select count(*) from t1 partition (p1);
1112+
count(*)
1113+
100
1114+
drop table t1;
1115+
# REPLACE .. SELECT
1116+
create table t1 (x int primary key) with system versioning
1117+
partition by system_time limit 100 (
1118+
partition p0 history,
1119+
partition p1 history,
1120+
partition pn current);
1121+
insert into t1 select seq from seq_0_to_49;
1122+
replace t1 select * from t1;
1123+
replace t1 select * from t1;
1124+
replace t1 select * from t1;
1125+
replace t1 select * from t1;
1126+
Warnings:
1127+
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
1128+
# You see warning above ^
1129+
select count(*) from t1 partition (p0);
1130+
count(*)
1131+
100
1132+
select count(*) from t1 partition (p1);
1133+
count(*)
1134+
100
1135+
drop table t1;
9141136
# End of 10.3 tests
9151137
set global innodb_stats_persistent= @save_persistent;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ partition by system_time limit 1 (
6565
insert into t values (1);
6666
update t set a= 2;
6767
update t set a= 3;
68+
--echo # You see warning above ^
6869
delete history from t;
6970
select * from t for system_time all;
7071

0 commit comments

Comments
 (0)