Skip to content

Commit

Permalink
MDEV-22596: DELETE FOR PORTION does not obey "Expression in FOR PORTI…
Browse files Browse the repository at this point in the history
…ON OF must be constant" limitation, data can be easily lost

DELETE...FOR PORTION OF... statement accepts non-constant
FROM...TO clause. This contradicts the documentation and
is inconsistent with the behavior of UPDATE statement.
Thus, we add a validation that checks if a given deletion
period is specified by constant.
  • Loading branch information
nayuta-yanagisawa authored and FooBarrior committed Oct 15, 2020
1 parent 8a884a9 commit 5d4599f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mysql-test/suite/period/r/delete.result
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ delete from t for portion of othertime from '2000-01-01' to '2018-01-01';
ERROR HY000: Period `othertime` is not found in table
delete from t for portion of system_time from '2000-01-01' to '2018-01-01';
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'of system_time from '2000-01-01' to '2018-01-01'' at line 1
# MDEV-22596 DELETE FOR PORTION does not obey
# "Expression in FOR PORTION OF must be constant" limitation, data can be easily lost
delete from t for portion of apptime from s to e;
ERROR HY000: Expression in FOR PORTION OF must be constant
create or replace table t (id int, str text, s date, e date,
period for apptime(s,e));
insert into t values(1, 'data', '1999-01-01', '2018-12-12');
Expand Down
5 changes: 5 additions & 0 deletions mysql-test/suite/period/t/delete.test
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ delete from t for portion of othertime from '2000-01-01' to '2018-01-01';
--error ER_PARSE_ERROR
delete from t for portion of system_time from '2000-01-01' to '2018-01-01';

--echo # MDEV-22596 DELETE FOR PORTION does not obey
--echo # "Expression in FOR PORTION OF must be constant" limitation, data can be easily lost
--error ER_NOT_CONSTANT_EXPRESSION
delete from t for portion of apptime from s to e;

create or replace table t (id int, str text, s date, e date,
period for apptime(s,e));

Expand Down
10 changes: 10 additions & 0 deletions sql/sql_delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
if (mysql_prepare_delete(thd, table_list, &conds, &delete_while_scanning))
DBUG_RETURN(TRUE);

if (table_list->has_period())
{
if (!table_list->period_conditions.start.item->const_item()
|| !table_list->period_conditions.end.item->const_item())
{
my_error(ER_NOT_CONSTANT_EXPRESSION, MYF(0), "FOR PORTION OF");
DBUG_RETURN(true);
}
}

if (delete_history)
table->vers_write= false;

Expand Down

0 comments on commit 5d4599f

Please sign in to comment.