Skip to content

Commit

Permalink
MDEV-14684 Assertion `table' failed in mysql_delete
Browse files Browse the repository at this point in the history
SQL: disable TRUNCATE table_name TO statement for VIEWs
  • Loading branch information
kevgs committed Dec 19, 2017
1 parent 04bed58 commit 8ba0603
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions mysql-test/suite/versioning/r/truncate.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 14 additions & 0 deletions mysql-test/suite/versioning/t/truncate.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 3 additions & 0 deletions sql/share/errmsg-utf8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 8 additions & 1 deletion sql/sql_delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down

0 comments on commit 8ba0603

Please sign in to comment.