From 8ba06032aea45c9a7d587b60d3a783f265726bd7 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Tue, 19 Dec 2017 15:12:11 +0300 Subject: [PATCH] MDEV-14684 Assertion `table' failed in mysql_delete SQL: disable TRUNCATE table_name TO statement for VIEWs --- mysql-test/suite/versioning/r/truncate.result | 12 ++++++++++++ mysql-test/suite/versioning/t/truncate.test | 14 ++++++++++++++ sql/share/errmsg-utf8.txt | 3 +++ sql/sql_delete.cc | 9 ++++++++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/versioning/r/truncate.result b/mysql-test/suite/versioning/r/truncate.result index d01b2b2481b..63388f85d60 100644 --- a/mysql-test/suite/versioning/r/truncate.result +++ b/mysql-test/suite/versioning/r/truncate.result @@ -43,4 +43,16 @@ partition p0 history, partition pn current); truncate table t to system_time current_timestamp; ERROR 42000: The used command is not allowed with this MariaDB version +create or replace table t (i int) with system versioning; +truncate t to system_time now(); +create or replace view v as select * from t; +truncate v to system_time now(); +ERROR HY000: TRUNCATE table_name TO doesn't work with VIEWs +create or replace table t (i int); +truncate t to system_time now(); +ERROR HY000: System versioning required: t +create or replace view v as select * from t; +truncate v to system_time now(); +ERROR HY000: TRUNCATE table_name TO doesn't work with VIEWs drop table t; +drop view v; diff --git a/mysql-test/suite/versioning/t/truncate.test b/mysql-test/suite/versioning/t/truncate.test index a33d9af83d9..e732414f826 100644 --- a/mysql-test/suite/versioning/t/truncate.test +++ b/mysql-test/suite/versioning/t/truncate.test @@ -40,4 +40,18 @@ partition by system_time ( --error ER_NOT_ALLOWED_COMMAND truncate table t to system_time current_timestamp; +create or replace table t (i int) with system versioning; +truncate t to system_time now(); +create or replace view v as select * from t; +--error ER_VERS_TRUNCATE_TO_VIEW +truncate v to system_time now(); + +create or replace table t (i int); +--error ER_VERSIONING_REQUIRED +truncate t to system_time now(); +create or replace view v as select * from t; +--error ER_VERS_TRUNCATE_TO_VIEW +truncate v to system_time now(); + drop table t; +drop view v; diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index fdb717c3366..44a681cc044 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7931,3 +7931,6 @@ ER_VERS_ALREADY_VERSIONED WARN_VERS_TRT_EXPERIMENTAL eng "Transaction-based system versioning is EXPERIMENTAL and is subject to change in future." + +ER_VERS_TRUNCATE_TO_VIEW + eng "TRUNCATE table_name TO doesn't work with VIEWs" diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 9c535e2124a..fcd5708863a 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -312,6 +312,12 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, bool truncate_history= table_list->vers_conditions; if (truncate_history) { + if (table_list->is_view_or_derived()) + { + my_error(ER_VERS_TRUNCATE_TO_VIEW, MYF(0)); + DBUG_RETURN(true); + } + TABLE *table= table_list->table; DBUG_ASSERT(table); @@ -328,7 +334,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, DBUG_RETURN(TRUE); // trx_sees() in InnoDB reads sys_trx_start - if (!table->versioned(VERS_TIMESTAMP)) { + if (!table->versioned(VERS_TIMESTAMP)) + { DBUG_ASSERT(table_list->vers_conditions.type == SYSTEM_TIME_BEFORE); bitmap_set_bit(table->read_set, table->vers_end_field()->field_index); }