Skip to content

Commit 7b48724

Browse files
committed
UPDATE FOR PERIOD OF: don't crash on multi-table views
1 parent 9718e37 commit 7b48724

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

mysql-test/suite/period/r/delete.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ id log
288288
create or replace view v as select * from t;
289289
delete from v for portion of p from '2000-01-01' to '2018-01-01';
290290
ERROR 42S02: 'v' is a view
291+
# View can't be used
292+
create or replace view v as select t.* from t, t as t1;
293+
delete from v for portion of p from '2000-01-01' to '2018-01-01';
294+
ERROR 42S02: 'v' is a view
291295
# auto_increment field overflow
292296
create or replace table t (id tinyint auto_increment primary key,
293297
s date, e date, period for apptime(s,e));

mysql-test/suite/period/r/update.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
200200
set t.id= t.id + 5' at line 1
201201
update t1 set x= (select id from t for portion of apptime from '2000-01-01' to '2018-01-01');
202202
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 'portion of apptime from '2000-01-01' to '2018-01-01')' at line 1
203+
# single-table views
204+
create or replace view v1 as select * from t where id<10;
205+
update v1 for portion of apptime from '2000-01-01' to '2018-01-01' set id= id + 5;
206+
ERROR 42S02: 'v1' is a view
207+
# multi-table views
208+
create or replace view v1 as select * from t, t1 where x=id;
209+
update v1 for portion of apptime from '2000-01-01' to '2018-01-01' set id= id + 5;
210+
ERROR 42S02: 'v1' is a view
203211
# SQL16: 14.14 <update statement: searched>, Syntax Rules, 7)a) iii-iv)
204212
# Let FROMVAL be <point in time 1>. FROMVAL shall not generally contain a
205213
# reference to a column of T or a <routine invocation>

mysql-test/suite/period/t/delete.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ create or replace view v as select * from t;
131131
--error ER_IT_IS_A_VIEW
132132
delete from v for portion of p from '2000-01-01' to '2018-01-01';
133133

134+
--echo # View can't be used
135+
create or replace view v as select t.* from t, t as t1;
136+
--error ER_IT_IS_A_VIEW
137+
delete from v for portion of p from '2000-01-01' to '2018-01-01';
134138

135139
--echo # auto_increment field overflow
136140
create or replace table t (id tinyint auto_increment primary key,

mysql-test/suite/period/t/update.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ update t for portion of apptime from '2000-01-01' to '2018-01-01', t1
8787
--error ER_PARSE_ERROR
8888
update t1 set x= (select id from t for portion of apptime from '2000-01-01' to '2018-01-01');
8989

90+
--echo # single-table views
91+
create or replace view v1 as select * from t where id<10;
92+
--error ER_IT_IS_A_VIEW
93+
update v1 for portion of apptime from '2000-01-01' to '2018-01-01' set id= id + 5;
94+
95+
--echo # multi-table views
96+
create or replace view v1 as select * from t, t1 where x=id;
97+
--error ER_IT_IS_A_VIEW
98+
update v1 for portion of apptime from '2000-01-01' to '2018-01-01' set id= id + 5;
99+
90100
--echo # SQL16: 14.14 <update statement: searched>, Syntax Rules, 7)a) iii-iv)
91101
--echo # Let FROMVAL be <point in time 1>. FROMVAL shall not generally contain a
92102
--echo # reference to a column of T or a <routine invocation>

sql/sql_update.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ int mysql_update(THD *thd,
384384
if (mysql_handle_derived(thd->lex, DT_INIT))
385385
DBUG_RETURN(1);
386386

387+
if (table_list->has_period() && table_list->is_view_or_derived())
388+
{
389+
my_error(ER_IT_IS_A_VIEW, MYF(0), table_list->table_name.str);
390+
DBUG_RETURN(TRUE);
391+
}
392+
387393
if (((update_source_table=unique_table(thd, table_list,
388394
table_list->next_global, 0)) ||
389395
table_list->is_multitable()))
@@ -1337,12 +1343,6 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
13371343

13381344
if (table_list->has_period())
13391345
{
1340-
if (table_list->is_view_or_derived())
1341-
{
1342-
my_error(ER_IT_IS_A_VIEW, MYF(0), table_list->table_name.str);
1343-
DBUG_RETURN(true);
1344-
}
1345-
13461346
*conds= select_lex->period_setup_conds(thd, table_list, *conds);
13471347
if (!*conds)
13481348
DBUG_RETURN(true);

0 commit comments

Comments
 (0)