Skip to content

Commit 8ba0603

Browse files
authored
MDEV-14684 Assertion `table' failed in mysql_delete
SQL: disable TRUNCATE table_name TO statement for VIEWs
1 parent 04bed58 commit 8ba0603

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ partition p0 history,
4343
partition pn current);
4444
truncate table t to system_time current_timestamp;
4545
ERROR 42000: The used command is not allowed with this MariaDB version
46+
create or replace table t (i int) with system versioning;
47+
truncate t to system_time now();
48+
create or replace view v as select * from t;
49+
truncate v to system_time now();
50+
ERROR HY000: TRUNCATE table_name TO doesn't work with VIEWs
51+
create or replace table t (i int);
52+
truncate t to system_time now();
53+
ERROR HY000: System versioning required: t
54+
create or replace view v as select * from t;
55+
truncate v to system_time now();
56+
ERROR HY000: TRUNCATE table_name TO doesn't work with VIEWs
4657
drop table t;
58+
drop view v;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,18 @@ partition by system_time (
4040
--error ER_NOT_ALLOWED_COMMAND
4141
truncate table t to system_time current_timestamp;
4242

43+
create or replace table t (i int) with system versioning;
44+
truncate t to system_time now();
45+
create or replace view v as select * from t;
46+
--error ER_VERS_TRUNCATE_TO_VIEW
47+
truncate v to system_time now();
48+
49+
create or replace table t (i int);
50+
--error ER_VERSIONING_REQUIRED
51+
truncate t to system_time now();
52+
create or replace view v as select * from t;
53+
--error ER_VERS_TRUNCATE_TO_VIEW
54+
truncate v to system_time now();
55+
4356
drop table t;
57+
drop view v;

sql/share/errmsg-utf8.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7931,3 +7931,6 @@ ER_VERS_ALREADY_VERSIONED
79317931

79327932
WARN_VERS_TRT_EXPERIMENTAL
79337933
eng "Transaction-based system versioning is EXPERIMENTAL and is subject to change in future."
7934+
7935+
ER_VERS_TRUNCATE_TO_VIEW
7936+
eng "TRUNCATE table_name TO doesn't work with VIEWs"

sql/sql_delete.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
312312
bool truncate_history= table_list->vers_conditions;
313313
if (truncate_history)
314314
{
315+
if (table_list->is_view_or_derived())
316+
{
317+
my_error(ER_VERS_TRUNCATE_TO_VIEW, MYF(0));
318+
DBUG_RETURN(true);
319+
}
320+
315321
TABLE *table= table_list->table;
316322
DBUG_ASSERT(table);
317323

@@ -328,7 +334,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
328334
DBUG_RETURN(TRUE);
329335

330336
// trx_sees() in InnoDB reads sys_trx_start
331-
if (!table->versioned(VERS_TIMESTAMP)) {
337+
if (!table->versioned(VERS_TIMESTAMP))
338+
{
332339
DBUG_ASSERT(table_list->vers_conditions.type == SYSTEM_TIME_BEFORE);
333340
bitmap_set_bit(table->read_set, table->vers_end_field()->field_index);
334341
}

0 commit comments

Comments
 (0)