Skip to content

Commit ea2f099

Browse files
committed
MDEV-28271 Assertion on TRUNCATE PARTITION for PARTITION BY SYSTEM_TIME
Like in MDEV-27217 vers_set_hist_part() for LIMIT depends on all partitions selected in read_partitions. That bugfix just disabled partition selection for DELETE with this check: if (table->pos_in_table_list && table->pos_in_table_list->partition_names) { return HA_ERR_PARTITION_LIST; } ALTER TABLE TRUNCATE PARTITION is a different story. First, it doesn't update pos_in_table_list->partition_names, but thd->lex->alter_info.partition_names. But we cannot depend on that since alter_info will be stale for DML. Second, we should not disable TRUNCATE PARTITION for that to be consistent with TRUNCATE TABLE behavior. Now we don't do vers_set_hist_part() for ALTER TABLE as this command is not DML, so it does not produce history.
1 parent add5137 commit ea2f099

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,5 +839,77 @@ p0 10
839839
p1 0
840840
pn 90
841841
drop table t1;
842+
#
843+
# MDEV-28271 Assertion on TRUNCATE PARTITION for PARTITION BY SYSTEM_TIME
844+
#
845+
create table t1 (x int) with system versioning
846+
partition by system_time limit 1 (
847+
partition p0 history,
848+
partition p1 history,
849+
partition pn current);
850+
insert into t1 values (0);
851+
update t1 set x= x + 1;
852+
update t1 set x= x + 1;
853+
update t1 set x= x + 1;
854+
update t1 set x= x + 1;
855+
select * from t1 partition (p0);
856+
x
857+
0
858+
1
859+
select * from t1 partition (p1);
860+
x
861+
2
862+
3
863+
select * from t1 partition (pn);
864+
x
865+
4
866+
# TRUNCATE TABLE deletes history and current data
867+
truncate table t1;
868+
select * from t1 partition (p0);
869+
x
870+
select * from t1 partition (p1);
871+
x
872+
select * from t1 partition (pn);
873+
x
874+
insert into t1 values (0);
875+
update t1 set x= x + 1;
876+
update t1 set x= x + 1;
877+
update t1 set x= x + 1;
878+
update t1 set x= x + 1;
879+
# TRUNCATE PARTITION ALL does the same
880+
alter table t1 truncate partition all;
881+
select * from t1 partition (p0);
882+
x
883+
select * from t1 partition (p1);
884+
x
885+
select * from t1 partition (pn);
886+
x
887+
insert into t1 values (0);
888+
update t1 set x= x + 1;
889+
update t1 set x= x + 1;
890+
update t1 set x= x + 1;
891+
update t1 set x= x + 1;
892+
# TRUNCATE PARTITION deletes data from HISTORY partition
893+
alter table t1 truncate partition p1;
894+
select * from t1 partition (p0);
895+
x
896+
0
897+
1
898+
select * from t1 partition (p1);
899+
x
900+
select * from t1 partition (pn);
901+
x
902+
4
903+
# or from CURRENT partition
904+
alter table t1 truncate partition pn;
905+
select * from t1 partition (p0);
906+
x
907+
0
908+
1
909+
select * from t1 partition (p1);
910+
x
911+
select * from t1 partition (pn);
912+
x
913+
drop table t1;
842914
# End of 10.3 tests
843915
set global innodb_stats_persistent= @save_persistent;

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,66 @@ from information_schema.partitions
822822
where table_name = 't1';
823823
# Cleanup
824824
drop table t1;
825+
826+
--echo #
827+
--echo # MDEV-28271 Assertion on TRUNCATE PARTITION for PARTITION BY SYSTEM_TIME
828+
--echo #
829+
create table t1 (x int) with system versioning
830+
partition by system_time limit 1 (
831+
partition p0 history,
832+
partition p1 history,
833+
partition pn current);
834+
835+
insert into t1 values (0);
836+
update t1 set x= x + 1;
837+
update t1 set x= x + 1;
838+
update t1 set x= x + 1;
839+
update t1 set x= x + 1;
840+
841+
select * from t1 partition (p0);
842+
select * from t1 partition (p1);
843+
select * from t1 partition (pn);
844+
845+
--echo # TRUNCATE TABLE deletes history and current data
846+
--disable_warnings
847+
truncate table t1;
848+
--enable_warnings
849+
select * from t1 partition (p0);
850+
select * from t1 partition (p1);
851+
select * from t1 partition (pn);
852+
853+
insert into t1 values (0);
854+
update t1 set x= x + 1;
855+
update t1 set x= x + 1;
856+
update t1 set x= x + 1;
857+
update t1 set x= x + 1;
858+
859+
--echo # TRUNCATE PARTITION ALL does the same
860+
alter table t1 truncate partition all;
861+
select * from t1 partition (p0);
862+
select * from t1 partition (p1);
863+
select * from t1 partition (pn);
864+
865+
insert into t1 values (0);
866+
update t1 set x= x + 1;
867+
update t1 set x= x + 1;
868+
update t1 set x= x + 1;
869+
update t1 set x= x + 1;
870+
871+
--echo # TRUNCATE PARTITION deletes data from HISTORY partition
872+
alter table t1 truncate partition p1;
873+
select * from t1 partition (p0);
874+
select * from t1 partition (p1);
875+
select * from t1 partition (pn);
876+
877+
--echo # or from CURRENT partition
878+
alter table t1 truncate partition pn;
879+
select * from t1 partition (p0);
880+
select * from t1 partition (p1);
881+
select * from t1 partition (pn);
882+
883+
drop table t1;
884+
825885
--echo # End of 10.3 tests
826886

827887
set global innodb_stats_persistent= @save_persistent;

sql/ha_partition.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,6 +4034,7 @@ int ha_partition::external_lock(THD *thd, int lock_type)
40344034
only for versioned DML. */
40354035
thd->lex->sql_command != SQLCOM_SELECT &&
40364036
thd->lex->sql_command != SQLCOM_INSERT_SELECT &&
4037+
thd->lex->sql_command != SQLCOM_ALTER_TABLE &&
40374038
(error= m_part_info->vers_set_hist_part(thd)))
40384039
goto err_handler;
40394040
}

0 commit comments

Comments
 (0)