diff options
author | Sergei Golubchik <serg@mariadb.org> | 2019-02-16 15:00:59 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2019-02-21 14:57:10 +0100 |
commit | 7b48724dcca4064a272aac1ebe0e3ba061cc78c2 (patch) | |
tree | 1ce2575dac353da57d82fb2c93b55208974b4fca | |
parent | 9718e374a245091e1e9edc9b004525984eba16f1 (diff) | |
download | mariadb-git-7b48724dcca4064a272aac1ebe0e3ba061cc78c2.tar.gz |
UPDATE FOR PERIOD OF: don't crash on multi-table views
-rw-r--r-- | mysql-test/suite/period/r/delete.result | 4 | ||||
-rw-r--r-- | mysql-test/suite/period/r/update.result | 8 | ||||
-rw-r--r-- | mysql-test/suite/period/t/delete.test | 4 | ||||
-rw-r--r-- | mysql-test/suite/period/t/update.test | 10 | ||||
-rw-r--r-- | sql/sql_update.cc | 12 |
5 files changed, 32 insertions, 6 deletions
diff --git a/mysql-test/suite/period/r/delete.result b/mysql-test/suite/period/r/delete.result index c5333dcf39a..d2ead48e2e7 100644 --- a/mysql-test/suite/period/r/delete.result +++ b/mysql-test/suite/period/r/delete.result @@ -288,6 +288,10 @@ id log create or replace view v as select * from t; delete from v for portion of p from '2000-01-01' to '2018-01-01'; ERROR 42S02: 'v' is a view +# View can't be used +create or replace view v as select t.* from t, t as t1; +delete from v for portion of p from '2000-01-01' to '2018-01-01'; +ERROR 42S02: 'v' is a view # auto_increment field overflow create or replace table t (id tinyint auto_increment primary key, s date, e date, period for apptime(s,e)); diff --git a/mysql-test/suite/period/r/update.result b/mysql-test/suite/period/r/update.result index 6b6e8de3081..a9e6a735a03 100644 --- a/mysql-test/suite/period/r/update.result +++ b/mysql-test/suite/period/r/update.result @@ -200,6 +200,14 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp set t.id= t.id + 5' at line 1 update t1 set x= (select id from t for portion of apptime 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 'portion of apptime from '2000-01-01' to '2018-01-01')' at line 1 +# single-table views +create or replace view v1 as select * from t where id<10; +update v1 for portion of apptime from '2000-01-01' to '2018-01-01' set id= id + 5; +ERROR 42S02: 'v1' is a view +# multi-table views +create or replace view v1 as select * from t, t1 where x=id; +update v1 for portion of apptime from '2000-01-01' to '2018-01-01' set id= id + 5; +ERROR 42S02: 'v1' is a view # SQL16: 14.14 <update statement: searched>, Syntax Rules, 7)a) iii-iv) # Let FROMVAL be <point in time 1>. FROMVAL shall not generally contain a # reference to a column of T or a <routine invocation> diff --git a/mysql-test/suite/period/t/delete.test b/mysql-test/suite/period/t/delete.test index e4fc17decf2..c83da42bd6c 100644 --- a/mysql-test/suite/period/t/delete.test +++ b/mysql-test/suite/period/t/delete.test @@ -131,6 +131,10 @@ create or replace view v as select * from t; --error ER_IT_IS_A_VIEW delete from v for portion of p from '2000-01-01' to '2018-01-01'; +--echo # View can't be used +create or replace view v as select t.* from t, t as t1; +--error ER_IT_IS_A_VIEW +delete from v for portion of p from '2000-01-01' to '2018-01-01'; --echo # auto_increment field overflow create or replace table t (id tinyint auto_increment primary key, diff --git a/mysql-test/suite/period/t/update.test b/mysql-test/suite/period/t/update.test index c2616cfe4a8..2ec722c5be5 100644 --- a/mysql-test/suite/period/t/update.test +++ b/mysql-test/suite/period/t/update.test @@ -87,6 +87,16 @@ update t for portion of apptime from '2000-01-01' to '2018-01-01', t1 --error ER_PARSE_ERROR update t1 set x= (select id from t for portion of apptime from '2000-01-01' to '2018-01-01'); +--echo # single-table views +create or replace view v1 as select * from t where id<10; +--error ER_IT_IS_A_VIEW +update v1 for portion of apptime from '2000-01-01' to '2018-01-01' set id= id + 5; + +--echo # multi-table views +create or replace view v1 as select * from t, t1 where x=id; +--error ER_IT_IS_A_VIEW +update v1 for portion of apptime from '2000-01-01' to '2018-01-01' set id= id + 5; + --echo # SQL16: 14.14 <update statement: searched>, Syntax Rules, 7)a) iii-iv) --echo # Let FROMVAL be <point in time 1>. FROMVAL shall not generally contain a --echo # reference to a column of T or a <routine invocation> diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 50b294105f1..c4f11b1ab81 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -384,6 +384,12 @@ int mysql_update(THD *thd, if (mysql_handle_derived(thd->lex, DT_INIT)) DBUG_RETURN(1); + if (table_list->has_period() && table_list->is_view_or_derived()) + { + my_error(ER_IT_IS_A_VIEW, MYF(0), table_list->table_name.str); + DBUG_RETURN(TRUE); + } + if (((update_source_table=unique_table(thd, table_list, table_list->next_global, 0)) || table_list->is_multitable())) @@ -1337,12 +1343,6 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, if (table_list->has_period()) { - if (table_list->is_view_or_derived()) - { - my_error(ER_IT_IS_A_VIEW, MYF(0), table_list->table_name.str); - DBUG_RETURN(true); - } - *conds= select_lex->period_setup_conds(thd, table_list, *conds); if (!*conds) DBUG_RETURN(true); |