diff options
author | unknown <bell@sanja.is.com.ua> | 2005-09-01 22:42:37 +0300 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2005-09-01 22:42:37 +0300 |
commit | a8fc85cbe338787214be1afc91e5760c6b81632a (patch) | |
tree | d788943a464c45d6c90828c3d67021e7b0e2d4b9 | |
parent | a2d8ab0bb5fe8edaaea8637bf8d9d78548dd5a21 (diff) | |
parent | eb7c4ff2dbcfcc0292dcd1ff577b1d203463834c (diff) | |
download | mariadb-git-a8fc85cbe338787214be1afc91e5760c6b81632a.tar.gz |
Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-5.0
into sanja.is.com.ua:/home/bell/mysql/bk/work-bug3-5.0
BitKeeper/etc/config:
Auto merged
mysql-test/r/view.result:
Auto merged
mysql-test/t/view.test:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_delete.cc:
Auto merged
sql/sql_insert.cc:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_update.cc:
Auto merged
sql/sql_view.cc:
Auto merged
sql/table.h:
Auto merged
-rw-r--r-- | mysql-test/r/lowercase_view.result | 98 | ||||
-rw-r--r-- | mysql-test/r/view.result | 82 | ||||
-rw-r--r-- | mysql-test/t/lowercase_view.test | 68 | ||||
-rw-r--r-- | mysql-test/t/view.test | 86 | ||||
-rw-r--r-- | sql/mysql_priv.h | 3 | ||||
-rw-r--r-- | sql/share/errmsg.txt | 2 | ||||
-rw-r--r-- | sql/sql_base.cc | 58 | ||||
-rw-r--r-- | sql/sql_delete.cc | 21 | ||||
-rw-r--r-- | sql/sql_insert.cc | 5 | ||||
-rw-r--r-- | sql/sql_parse.cc | 18 | ||||
-rw-r--r-- | sql/sql_update.cc | 23 | ||||
-rw-r--r-- | sql/sql_view.cc | 7 | ||||
-rw-r--r-- | sql/table.cc | 2 | ||||
-rw-r--r-- | sql/table.h | 2 |
14 files changed, 287 insertions, 188 deletions
diff --git a/mysql-test/r/lowercase_view.result b/mysql-test/r/lowercase_view.result index 37252c6dde7..1baf3246c13 100644 --- a/mysql-test/r/lowercase_view.result +++ b/mysql-test/r/lowercase_view.result @@ -16,103 +16,103 @@ create view v1Aa as select * from t1aA; create view v2aA as select * from v1aA; create view v3Aa as select v2Aa.col1 from v2aA,t2Aa where v2Aa.col1 = t2aA.col1; update v2aA set col1 = (select max(col1) from v1Aa); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v1Aa' prevents operation UPDATE on table 'v2aA'. update v2Aa set col1 = (select max(col1) from t1Aa); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v2Aa' prevents operation UPDATE on table 'v2Aa'. update v2aA set col1 = (select max(col1) from v2Aa); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: You can't specify target table 'v2aA' for update in FROM clause update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from v1aA) where v2aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v1aA' prevents operation UPDATE on table 'v2aA'. update t1aA,t2Aa set t1Aa.col1 = (select max(col1) from v1Aa) where t1aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't1aa' for update in FROM clause +ERROR HY000: The definition of table 'v1Aa' prevents operation UPDATE on table 't1aA'. update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from v1aA) where v1Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v1aa' for update in FROM clause +ERROR HY000: You can't specify target table 'v1aA' for update in FROM clause update t2Aa,v2Aa set v2aA.col1 = (select max(col1) from v1aA) where v2Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't2aa' for update in FROM clause +ERROR HY000: The definition of table 'v1aA' prevents operation UPDATE on table 't2Aa'. update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from v1Aa) where t1Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't2aa' for update in FROM clause +ERROR HY000: The definition of table 'v1Aa' prevents operation UPDATE on table 't2Aa'. update t2Aa,v1aA set v1Aa.col1 = (select max(col1) from v1aA) where v1Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't2aa' for update in FROM clause +ERROR HY000: The definition of table 'v1aA' prevents operation UPDATE on table 't2Aa'. update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from t1aA) where v2aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v2aA' prevents operation UPDATE on table 'v2aA'. update t1Aa,t2Aa set t1aA.col1 = (select max(col1) from t1Aa) where t1aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't1aa' for update in FROM clause +ERROR HY000: You can't specify target table 't1Aa' for update in FROM clause update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from t1Aa) where v1aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v1aa' for update in FROM clause +ERROR HY000: The definition of table 'v1aA' prevents operation UPDATE on table 'v1aA'. update t2Aa,v2Aa set v2aA.col1 = (select max(col1) from t1aA) where v2Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't2aa' for update in FROM clause +ERROR HY000: You can't specify target table 't2Aa' for update in FROM clause update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from t1Aa) where t1aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't2aa' for update in FROM clause +ERROR HY000: You can't specify target table 't2Aa' for update in FROM clause update t2Aa,v1Aa set v1aA.col1 = (select max(col1) from t1Aa) where v1Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't2aa' for update in FROM clause +ERROR HY000: You can't specify target table 't2Aa' for update in FROM clause update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from v2aA) where v2Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: You can't specify target table 'v2aA' for update in FROM clause update t1aA,t2Aa set t1Aa.col1 = (select max(col1) from v2aA) where t1aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't1aa' for update in FROM clause +ERROR HY000: The definition of table 'v2aA' prevents operation UPDATE on table 't1aA'. update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from v2Aa) where v1aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v1aa' for update in FROM clause +ERROR HY000: The definition of table 'v2Aa' prevents operation UPDATE on table 'v1aA'. update t2Aa,v2aA set v2Aa.col1 = (select max(col1) from v2aA) where v2Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't2aa' for update in FROM clause +ERROR HY000: The definition of table 'v2aA' prevents operation UPDATE on table 't2Aa'. update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from v2aA) where t1Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't2aa' for update in FROM clause +ERROR HY000: The definition of table 'v2aA' prevents operation UPDATE on table 't2Aa'. update t2Aa,v1Aa set v1aA.col1 = (select max(col1) from v2Aa) where v1Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't2aa' for update in FROM clause +ERROR HY000: The definition of table 'v2Aa' prevents operation UPDATE on table 't2Aa'. update v3aA set v3Aa.col1 = (select max(col1) from v1aA); -ERROR HY000: You can't specify target table 'v3aa' for update in FROM clause +ERROR HY000: The definition of table 'v1aA' prevents operation UPDATE on table 'v3aA'. update v3aA set v3Aa.col1 = (select max(col1) from t1aA); -ERROR HY000: You can't specify target table 'v3aa' for update in FROM clause +ERROR HY000: The definition of table 'v3aA' prevents operation UPDATE on table 'v3aA'. update v3aA set v3Aa.col1 = (select max(col1) from v2aA); -ERROR HY000: You can't specify target table 'v3aa' for update in FROM clause +ERROR HY000: The definition of table 'v2aA' prevents operation UPDATE on table 'v3aA'. update v3aA set v3Aa.col1 = (select max(col1) from v3aA); -ERROR HY000: You can't specify target table 'v3aa' for update in FROM clause +ERROR HY000: You can't specify target table 'v3aA' for update in FROM clause delete from v2Aa where col1 = (select max(col1) from v1Aa); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v1Aa' prevents operation DELETE on table 'v2Aa'. delete from v2aA where col1 = (select max(col1) from t1Aa); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v2aA' prevents operation DELETE on table 'v2aA'. delete from v2Aa where col1 = (select max(col1) from v2aA); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: You can't specify target table 'v2Aa' for update in FROM clause delete v2Aa from v2aA,t2Aa where (select max(col1) from v1aA) > 0 and v2Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v1aA' prevents operation DELETE on table 'v2aA'. delete t1aA from t1Aa,t2Aa where (select max(col1) from v1Aa) > 0 and t1aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't1aa' for update in FROM clause +ERROR HY000: The definition of table 'v1Aa' prevents operation DELETE on table 't1Aa'. delete v1aA from v1Aa,t2Aa where (select max(col1) from v1aA) > 0 and v1Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v1aa' for update in FROM clause +ERROR HY000: You can't specify target table 'v1Aa' for update in FROM clause delete v2aA from v2Aa,t2Aa where (select max(col1) from t1Aa) > 0 and v2aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v2Aa' prevents operation DELETE on table 'v2Aa'. delete t1aA from t1Aa,t2Aa where (select max(col1) from t1aA) > 0 and t1Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't1aa' for update in FROM clause +ERROR HY000: You can't specify target table 't1Aa' for update in FROM clause delete v1aA from v1Aa,t2Aa where (select max(col1) from t1aA) > 0 and v1aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v1aa' for update in FROM clause +ERROR HY000: The definition of table 'v1Aa' prevents operation DELETE on table 'v1Aa'. delete v2Aa from v2aA,t2Aa where (select max(col1) from v2Aa) > 0 and v2aA.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: You can't specify target table 'v2aA' for update in FROM clause delete t1Aa from t1aA,t2Aa where (select max(col1) from v2Aa) > 0 and t1Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 't1aa' for update in FROM clause +ERROR HY000: The definition of table 'v2Aa' prevents operation DELETE on table 't1aA'. delete v1Aa from v1aA,t2Aa where (select max(col1) from v2aA) > 0 and v1Aa.col1 = t2aA.col1; -ERROR HY000: You can't specify target table 'v1aa' for update in FROM clause +ERROR HY000: The definition of table 'v2aA' prevents operation DELETE on table 'v1aA'. insert into v2Aa values ((select max(col1) from v1aA)); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v1aA' prevents operation INSERT on table 'v2Aa'. insert into t1aA values ((select max(col1) from v1Aa)); -ERROR HY000: You can't specify target table 't1aa' for update in FROM clause +ERROR HY000: The definition of table 'v1Aa' prevents operation INSERT on table 't1aA'. insert into v2aA values ((select max(col1) from v1aA)); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v1aA' prevents operation INSERT on table 'v2aA'. insert into v2Aa values ((select max(col1) from t1Aa)); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v2Aa' prevents operation INSERT on table 'v2Aa'. insert into t1aA values ((select max(col1) from t1Aa)); -ERROR HY000: You can't specify target table 't1aa' for update in FROM clause +ERROR HY000: You can't specify target table 't1aA' for update in FROM clause insert into v2aA values ((select max(col1) from t1aA)); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: The definition of table 'v2aA' prevents operation INSERT on table 'v2aA'. insert into v2Aa values ((select max(col1) from v2aA)); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: You can't specify target table 'v2Aa' for update in FROM clause insert into t1Aa values ((select max(col1) from v2Aa)); -ERROR HY000: You can't specify target table 't1aa' for update in FROM clause +ERROR HY000: The definition of table 'v2Aa' prevents operation INSERT on table 't1Aa'. insert into v2aA values ((select max(col1) from v2Aa)); -ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause +ERROR HY000: You can't specify target table 'v2aA' for update in FROM clause insert into v3Aa (col1) values ((select max(col1) from v1Aa)); -ERROR HY000: You can't specify target table 'v3aa' for update in FROM clause +ERROR HY000: The definition of table 'v1Aa' prevents operation INSERT on table 'v3Aa'. insert into v3aA (col1) values ((select max(col1) from t1aA)); -ERROR HY000: You can't specify target table 'v3aa' for update in FROM clause +ERROR HY000: The definition of table 'v3aA' prevents operation INSERT on table 'v3aA'. insert into v3Aa (col1) values ((select max(col1) from v2aA)); -ERROR HY000: You can't specify target table 'v3aa' for update in FROM clause +ERROR HY000: The definition of table 'v2aA' prevents operation INSERT on table 'v3Aa'. drop view v3aA,v2Aa,v1aA; drop table t1Aa,t2Aa; create table t1Aa (col1 int); diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 2b71a58482f..a544fb4b020 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -875,29 +875,29 @@ create view v1 as select * from t1; create view v2 as select * from v1; create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1; update v2 set col1 = (select max(col1) from v1); -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v2'. update v2 set col1 = (select max(col1) from t1); -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v2'. update v2 set col1 = (select max(col1) from v2); ERROR HY000: You can't specify target table 'v2' for update in FROM clause update v2,t2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1; -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v2'. update t1,t2 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1; -ERROR HY000: You can't specify target table 't1' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't1'. update v1,t2 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1; ERROR HY000: You can't specify target table 'v1' for update in FROM clause update t2,v2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1; -ERROR HY000: You can't specify target table 't2' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't2'. update t2,t1 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1; -ERROR HY000: You can't specify target table 't2' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't2'. update t2,v1 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1; -ERROR HY000: You can't specify target table 't2' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't2'. update v2,t2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1; -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v2'. update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1; ERROR HY000: You can't specify target table 't1' for update in FROM clause update v1,t2 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1; -ERROR HY000: You can't specify target table 'v1' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v1'. update t2,v2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1; ERROR HY000: You can't specify target table 't2' for update in FROM clause update t2,t1 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1; @@ -907,73 +907,73 @@ ERROR HY000: You can't specify target table 't2' for update in FROM clause update v2,t2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1; ERROR HY000: You can't specify target table 'v2' for update in FROM clause update t1,t2 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1; -ERROR HY000: You can't specify target table 't1' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't1'. update v1,t2 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1; -ERROR HY000: You can't specify target table 'v1' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v1'. update t2,v2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1; -ERROR HY000: You can't specify target table 't2' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't2'. update t2,t1 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1; -ERROR HY000: You can't specify target table 't2' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't2'. update t2,v1 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1; -ERROR HY000: You can't specify target table 't2' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't2'. update v3 set v3.col1 = (select max(col1) from v1); -ERROR HY000: You can't specify target table 'v3' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v3'. update v3 set v3.col1 = (select max(col1) from t1); -ERROR HY000: You can't specify target table 'v3' for update in FROM clause +ERROR HY000: The definition of table 'v3' prevents operation UPDATE on table 'v3'. update v3 set v3.col1 = (select max(col1) from v2); -ERROR HY000: You can't specify target table 'v3' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v3'. update v3 set v3.col1 = (select max(col1) from v3); ERROR HY000: You can't specify target table 'v3' for update in FROM clause delete from v2 where col1 = (select max(col1) from v1); -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 'v2'. delete from v2 where col1 = (select max(col1) from t1); -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 'v2'. delete from v2 where col1 = (select max(col1) from v2); ERROR HY000: You can't specify target table 'v2' for update in FROM clause delete v2 from v2,t2 where (select max(col1) from v1) > 0 and v2.col1 = t2.col1; -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 'v2'. delete t1 from t1,t2 where (select max(col1) from v1) > 0 and t1.col1 = t2.col1; -ERROR HY000: You can't specify target table 't1' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 't1'. delete v1 from v1,t2 where (select max(col1) from v1) > 0 and v1.col1 = t2.col1; ERROR HY000: You can't specify target table 'v1' for update in FROM clause delete v2 from v2,t2 where (select max(col1) from t1) > 0 and v2.col1 = t2.col1; -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 'v2'. delete t1 from t1,t2 where (select max(col1) from t1) > 0 and t1.col1 = t2.col1; ERROR HY000: You can't specify target table 't1' for update in FROM clause delete v1 from v1,t2 where (select max(col1) from t1) > 0 and v1.col1 = t2.col1; -ERROR HY000: You can't specify target table 'v1' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 'v1'. delete v2 from v2,t2 where (select max(col1) from v2) > 0 and v2.col1 = t2.col1; ERROR HY000: You can't specify target table 'v2' for update in FROM clause delete t1 from t1,t2 where (select max(col1) from v2) > 0 and t1.col1 = t2.col1; -ERROR HY000: You can't specify target table 't1' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 't1'. delete v1 from v1,t2 where (select max(col1) from v2) > 0 and v1.col1 = t2.col1; -ERROR HY000: You can't specify target table 'v1' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 'v1'. insert into v2 values ((select max(col1) from v1)); -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'v2'. insert into t1 values ((select max(col1) from v1)); -ERROR HY000: You can't specify target table 't1' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 't1'. insert into v2 values ((select max(col1) from v1)); -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'v2'. insert into v2 values ((select max(col1) from t1)); -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v2'. insert into t1 values ((select max(col1) from t1)); ERROR HY000: You can't specify target table 't1' for update in FROM clause insert into v2 values ((select max(col1) from t1)); -ERROR HY000: You can't specify target table 'v2' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v2'. insert into v2 values ((select max(col1) from v2)); ERROR HY000: You can't specify target table 'v2' for update in FROM clause insert into t1 values ((select max(col1) from v2)); -ERROR HY000: You can't specify target table 't1' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 't1'. insert into v2 values ((select max(col1) from v2)); ERROR HY000: You can't specify target table 'v2' for update in FROM clause insert into v3 (col1) values ((select max(col1) from v1)); -ERROR HY000: You can't specify target table 'v3' for update in FROM clause +ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'v3'. insert into v3 (col1) values ((select max(col1) from t1)); -ERROR HY000: You can't specify target table 'v3' for update in FROM clause +ERROR HY000: The definition of table 'v3' prevents operation INSERT on table 'v3'. insert into v3 (col1) values ((select max(col1) from v2)); -ERROR HY000: You can't specify target table 'v3' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v3'. insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from v2)); -ERROR HY000: You can't specify target table 'v3' for update in FROM clause +ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v3'. insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2)); insert into mysql.time_zone values ('', (select CONVERT_TZ('20050101000000','UTC','MET') from t2)); ERROR 23000: Column 'Use_leap_seconds' cannot be null @@ -1332,7 +1332,7 @@ insert into v3 values (30); ERROR HY000: The target table v3 of the INSERT is not updatable create view v4 as select * from v2 where 20 < (select (s1) from t1); insert into v4 values (30); -ERROR HY000: You can't specify target table 'v4' for update in FROM clause +ERROR HY000: The target table v4 of the INSERT is not updatable drop view v4, v3, v2, v1; drop table t1; create table t1 (a int); @@ -1935,6 +1935,16 @@ SELECT * FROM v1; SUBSTRING_INDEX("dkjhgd:kjhdjh", ":", 1) dkjhgd drop view v1; +create table t1 (f59 int, f60 int, f61 int); +insert into t1 values (19,41,32); +create view v1 as select f59, f60 from t1 where f59 in +(select f59 from t1); +update v1 set f60=2345; +ERROR HY000: The target table v1 of the UPDATE is not updatable +update t1 set f60=(select max(f60) from v1); +ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't1'. +drop view v1; +drop table t1; create table t1 (s1 int); create view v1 as select var_samp(s1) from t1; show create view v1; diff --git a/mysql-test/t/lowercase_view.test b/mysql-test/t/lowercase_view.test index b39223f71d5..846c828fb09 100644 --- a/mysql-test/t/lowercase_view.test +++ b/mysql-test/t/lowercase_view.test @@ -23,29 +23,29 @@ create table t2aA (col1 int); create view v1Aa as select * from t1aA; create view v2aA as select * from v1aA; create view v3Aa as select v2Aa.col1 from v2aA,t2Aa where v2Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 update v2aA set col1 = (select max(col1) from v1Aa); --- error 1093 +-- error 1423 update v2Aa set col1 = (select max(col1) from t1Aa); -- error 1093 update v2aA set col1 = (select max(col1) from v2Aa); --- error 1093 +-- error 1423 update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from v1aA) where v2aA.col1 = t2aA.col1; --- error 1093 +-- error 1423 update t1aA,t2Aa set t1Aa.col1 = (select max(col1) from v1Aa) where t1aA.col1 = t2aA.col1; -- error 1093 update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from v1aA) where v1Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 update t2Aa,v2Aa set v2aA.col1 = (select max(col1) from v1aA) where v2Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from v1Aa) where t1Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 update t2Aa,v1aA set v1Aa.col1 = (select max(col1) from v1aA) where v1Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from t1aA) where v2aA.col1 = t2aA.col1; -- error 1093 update t1Aa,t2Aa set t1aA.col1 = (select max(col1) from t1Aa) where t1aA.col1 = t2aA.col1; --- error 1093 +-- error 1423 update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from t1Aa) where v1aA.col1 = t2aA.col1; -- error 1093 update t2Aa,v2Aa set v2aA.col1 = (select max(col1) from t1aA) where v2Aa.col1 = t2aA.col1; @@ -55,71 +55,71 @@ update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from t1Aa) where t1aA.col1 = update t2Aa,v1Aa set v1aA.col1 = (select max(col1) from t1Aa) where v1Aa.col1 = t2aA.col1; -- error 1093 update v2aA,t2Aa set v2Aa.col1 = (select max(col1) from v2aA) where v2Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 update t1aA,t2Aa set t1Aa.col1 = (select max(col1) from v2aA) where t1aA.col1 = t2aA.col1; --- error 1093 +-- error 1423 update v1aA,t2Aa set v1Aa.col1 = (select max(col1) from v2Aa) where v1aA.col1 = t2aA.col1; --- error 1093 +-- error 1423 update t2Aa,v2aA set v2Aa.col1 = (select max(col1) from v2aA) where v2Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 update t2Aa,t1Aa set t1aA.col1 = (select max(col1) from v2aA) where t1Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 update t2Aa,v1Aa set v1aA.col1 = (select max(col1) from v2Aa) where v1Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 update v3aA set v3Aa.col1 = (select max(col1) from v1aA); --- error 1093 +-- error 1423 update v3aA set v3Aa.col1 = (select max(col1) from t1aA); --- error 1093 +-- error 1423 update v3aA set v3Aa.col1 = (select max(col1) from v2aA); -- error 1093 update v3aA set v3Aa.col1 = (select max(col1) from v3aA); --- error 1093 +-- error 1423 delete from v2Aa where col1 = (select max(col1) from v1Aa); --- error 1093 +-- error 1423 delete from v2aA where col1 = (select max(col1) from t1Aa); -- error 1093 delete from v2Aa where col1 = (select max(col1) from v2aA); --- error 1093 +-- error 1423 delete v2Aa from v2aA,t2Aa where (select max(col1) from v1aA) > 0 and v2Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 delete t1aA from t1Aa,t2Aa where (select max(col1) from v1Aa) > 0 and t1aA.col1 = t2aA.col1; -- error 1093 delete v1aA from v1Aa,t2Aa where (select max(col1) from v1aA) > 0 and v1Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 delete v2aA from v2Aa,t2Aa where (select max(col1) from t1Aa) > 0 and v2aA.col1 = t2aA.col1; -- error 1093 delete t1aA from t1Aa,t2Aa where (select max(col1) from t1aA) > 0 and t1Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 delete v1aA from v1Aa,t2Aa where (select max(col1) from t1aA) > 0 and v1aA.col1 = t2aA.col1; -- error 1093 delete v2Aa from v2aA,t2Aa where (select max(col1) from v2Aa) > 0 and v2aA.col1 = t2aA.col1; --- error 1093 +-- error 1423 delete t1Aa from t1aA,t2Aa where (select max(col1) from v2Aa) > 0 and t1Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 delete v1Aa from v1aA,t2Aa where (select max(col1) from v2aA) > 0 and v1Aa.col1 = t2aA.col1; --- error 1093 +-- error 1423 insert into v2Aa values ((select max(col1) from v1aA)); --- error 1093 +-- error 1423 insert into t1aA values ((select max(col1) from v1Aa)); --- error 1093 +-- error 1423 insert into v2aA values ((select max(col1) from v1aA)); --- error 1093 +-- error 1423 insert into v2Aa values ((select max(col1) from t1Aa)); -- error 1093 insert into t1aA values ((select max(col1) from t1Aa)); --- error 1093 +-- error 1423 insert into v2aA values ((select max(col1) from t1aA)); -- error 1093 insert into v2Aa values ((select max(col1) from v2aA)); --- error 1093 +-- error 1423 insert into t1Aa values ((select max(col1) from v2Aa)); -- error 1093 insert into v2aA values ((select max(col1) from v2Aa)); --- error 1093 +-- error 1423 insert into v3Aa (col1) values ((select max(col1) from v1Aa)); --- error 1093 +-- error 1423 insert into v3aA (col1) values ((select max(col1) from t1aA)); --- error 1093 +-- error 1423 insert into v3Aa (col1) values ((select max(col1) from v2aA)); drop view v3aA,v2Aa,v1aA; drop table t1Aa,t2Aa; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index c4180ab5969..61170c7118a 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -827,29 +827,29 @@ create table t2 (col1 int); create view v1 as select * from t1; create view v2 as select * from v1; create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1; --- error 1093 +-- error 1423 update v2 set col1 = (select max(col1) from v1); --- error 1093 +-- error 1423 update v2 set col1 = (select max(col1) from t1); -- error 1093 update v2 set col1 = (select max(col1) from v2); --- error 1093 +-- error 1423 update v2,t2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1; --- error 1093 +-- error 1423 update t1,t2 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1; -- error 1093 update v1,t2 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1; --- error 1093 +-- error 1423 update t2,v2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1; --- error 1093 +-- error 1423 update t2,t1 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1; --- error 1093 +-- error 1423 update t2,v1 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1; --- error 1093 +-- error 1423 update v2,t2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1; -- error 1093 update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1; --- error 1093 +-- error 1423 update v1,t2 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1; -- error 1093 update t2,v2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1; @@ -859,74 +859,74 @@ update t2,t1 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1; update t2,v1 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1; -- error 1093 update v2,t2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1; --- error 1093 +-- error 1423 update t1,t2 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1; --- error 1093 +-- error 1423 update v1,t2 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1; --- error 1093 +-- error 1423 update t2,v2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1; --- error 1093 +-- error 1423 update t2,t1 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1; --- error 1093 +-- error 1423 update t2,v1 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1; --- error 1093 +-- error 1423 update v3 set v3.col1 = (select max(col1) from v1); --- error 1093 +-- error 1423 update v3 set v3.col1 = (select max(col1) from t1); --- error 1093 +-- error 1423 update v3 set v3.col1 = (select max(col1) from v2); -- error 1093 update v3 set v3.col1 = (select max(col1) from v3); --- error 1093 +-- error 1423 delete from v2 where col1 = (select max(col1) from v1); --- error 1093 +-- error 1423 delete from v2 where col1 = (select max(col1) from t1); -- error 1093 delete from v2 where col1 = (select max(col1) from v2); --- error 1093 +-- error 1423 delete v2 from v2,t2 where (select max(col1) from v1) > 0 and v2.col1 = t2.col1; --- error 1093 +-- error 1423 delete t1 from t1,t2 where (select max(col1) from v1) > 0 and t1.col1 = t2.col1; -- error 1093 delete v1 from v1,t2 where (select max(col1) from v1) > 0 and v1.col1 = t2.col1; --- error 1093 +-- error 1423 delete v2 from v2,t2 where (select max(col1) from t1) > 0 and v2.col1 = t2.col1; -- error 1093 delete t1 from t1,t2 where (select max(col1) from t1) > 0 and t1.col1 = t2.col1; --- error 1093 +-- error 1423 delete v1 from v1,t2 where (select max(col1) from t1) > 0 and v1.col1 = t2.col1; -- error 1093 delete v2 from v2,t2 where (select max(col1) from v2) > 0 and v2.col1 = t2.col1; --- error 1093 +-- error 1423 delete t1 from t1,t2 where (select max(col1) from v2) > 0 and t1.col1 = t2.col1; --- error 1093 +-- error 1423 delete v1 from v1,t2 where (select max(col1) from v2) > 0 and v1.col1 = t2.col1; --- error 1093 +-- error 1423 insert into v2 values ((select max(col1) from v1)); --- error 1093 +-- error 1423 insert into t1 values ((select max(col1) from v1)); --- error 1093 +-- error 1423 insert into v2 values ((select max(col1) from v1)); --- error 1093 +-- error 1423 insert into v2 values ((select max(col1) from t1)); -- error 1093 insert into t1 values ((select max(col1) from t1)); --- error 1093 +-- error 1423 insert into v2 values ((select max(col1) from t1)); -- error 1093 insert into v2 values ((select max(col1) from v2)); --- error 1093 +-- error 1423 insert into t1 values ((select max(col1) from v2)); -- error 1093 insert into v2 values ((select max(col1) from v2)); --- error 1093 +-- error 1423 insert into v3 (col1) values ((select max(col1) from v1)); --- error 1093 +-- error 1423 insert into v3 (col1) values ((select max(col1) from t1)); --- error 1093 +-- error 1423 insert into v3 (col1) values ((select max(col1) from v2)); #check with TZ tables in list --- error 1093 +-- error 1423 insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from v2)); insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2)); -- error 1048 @@ -1242,7 +1242,7 @@ create view v3 as select * from t1 where 20 < (select (s1) from v2); -- error 1288 insert into v3 values (30); create view v4 as select * from v2 where 20 < (select (s1) from t1); --- error 1093 +-- error 1288 insert into v4 values (30); drop view v4, v3, v2, v1; drop table t1; @@ -1761,6 +1761,20 @@ SELECT * FROM v1; drop view v1; # +# hide underlying tables names in case of imposibility to update (BUG#10773) +# +create table t1 (f59 int, f60 int, f61 int); +insert into t1 values (19,41,32); +create view v1 as select f59, f60 from t1 where f59 in + (select f59 from t1); +-- error 1288 +update v1 set f60=2345; +-- error 1423 +update t1 set f60=(select max(f60) from v1); +drop view v1; +drop table t1; + +# # Using var_samp with view (BUG#10651) # create table t1 (s1 int); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 7e21a19bd66..63f3eb1eec1 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -897,6 +897,9 @@ void add_join_on(TABLE_LIST *b,Item *expr); void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields); bool add_proc_to_list(THD *thd, Item *item); TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find); +void update_non_unique_table_error(TABLE_LIST *update, + const char *operation, + TABLE_LIST *duplicate); SQL_SELECT *make_select(TABLE *head, table_map const_tables, table_map read_tables, COND *conds, diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index b49b7248021..81e953e3a5d 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5399,3 +5399,5 @@ ER_DATETIME_FUNCTION_OVERFLOW 22008 eng "Datetime function: %-.32s field overflow" ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG eng "Can't update table '%-.64s' in stored function/trigger because it is already used by statement which invoked this stored function/trigger." +ER_VIEW_PREVENT_UPDATE + eng "The definition of table '%-.64s' prevents operation %s on table '%-.64s'." diff --git a/sql/sql_base.cc b/sql/sql_base.cc index b8b96f14205..1f9ecd6e0f1 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -774,6 +774,60 @@ TABLE_LIST* unique_table(TABLE_LIST *table, TABLE_LIST *table_list) } +/* + Issue correct error message in case we found 2 duplicate tables which + prevent some update operation + + SYNOPSIS + update_non_unique_table_error() + update table which we try to update + operation name of update operation + duplicate duplicate table which we found + + NOTE: + here we hide view underlying tables if we have them +*/ + +void update_non_unique_table_error(TABLE_LIST *update, + const char *operation, + TABLE_LIST *duplicate) +{ + update= update->top_table(); + duplicate= duplicate->top_table(); + if (!update->view || !duplicate->view || + update->view == duplicate->view || + update->view_name.length != duplicate->view_name.length || + update->view_db.length != duplicate->view_db.length || + my_strcasecmp(table_alias_charset, + update->view_name.str, duplicate->view_name.str) != 0 || + my_strcasecmp(table_alias_charset, + update->view_db.str, duplicate->view_db.str) != 0) + { + /* + it is not the same view repeated (but it can be parts of the same copy + of view), so we have to hide underlying tables. + */ + if (update->view) + { + if (update->view == duplicate->view) + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), update->alias, operation); + else + my_error(ER_VIEW_PREVENT_UPDATE, MYF(0), + (duplicate->view ? duplicate->alias : update->alias), + operation, update->alias); + return; + } + if (duplicate->view) + { + my_error(ER_VIEW_PREVENT_UPDATE, MYF(0), duplicate->alias, operation, + update->alias); + return; + } + } + my_error(ER_UPDATE_TABLE_USED, MYF(0), update->alias); +} + + TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name) { char key[MAX_DBKEY_LENGTH]; @@ -4173,9 +4227,7 @@ bool setup_tables(THD *thd, Name_resolution_context *context, { TABLE *table= table_list->table; if (first_select_table && - (table_list->belong_to_view ? - table_list->belong_to_view : - table_list) == first_select_table) + table_list->top_table() == first_select_table) { /* new counting for SELECT of INSERT ... SELECT command */ first_select_table= 0; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 4e86e3972c2..7fb9f9eccdd 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -332,10 +332,13 @@ bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE"); DBUG_RETURN(TRUE); } - if (unique_table(table_list, table_list->next_global)) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name); - DBUG_RETURN(TRUE); + TABLE_LIST *duplicate; + if ((duplicate= unique_table(table_list, table_list->next_global))) + { + update_non_unique_table_error(table_list, "DELETE", duplicate); + DBUG_RETURN(TRUE); + } } select_lex->fix_prepare_information(thd, conds); DBUG_RETURN(FALSE); @@ -418,11 +421,15 @@ bool mysql_multi_delete_prepare(THD *thd) Check that table from which we delete is not used somewhere inside subqueries/view. */ - if (unique_table(target_tbl->correspondent_table, lex->query_tables)) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), - target_tbl->correspondent_table->table_name); - DBUG_RETURN(TRUE); + TABLE_LIST *duplicate; + if ((duplicate= unique_table(target_tbl->correspondent_table, + lex->query_tables))) + { + update_non_unique_table_error(target_tbl->correspondent_table, + "DELETE", duplicate); + DBUG_RETURN(TRUE); + } } } DBUG_RETURN(FALSE); diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 93c9991418d..43a23dd31f0 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -917,9 +917,10 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, if (!select_insert) { Item *fake_conds= 0; - if (unique_table(table_list, table_list->next_global)) + TABLE_LIST *duplicate; + if ((duplicate= unique_table(table_list, table_list->next_global))) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name); + update_non_unique_table_error(table_list, "INSERT", duplicate); DBUG_RETURN(TRUE); } select_lex->fix_prepare_information(thd, &fake_conds); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 923a00decae..f572b1d9122 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2855,12 +2855,15 @@ mysql_execute_command(THD *thd) Is table which we are changing used somewhere in other parts of query */ - if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && - unique_table(create_table, select_tables)) + if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE)) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table->table_name); - res= 1; - goto end_with_restart_wait; + TABLE_LIST *duplicate; + if ((duplicate= unique_table(create_table, select_tables))) + { + update_non_unique_table_error(create_table, "CREATE", duplicate); + res= 1; + goto end_with_restart_wait; + } } /* If we create merge table, we have to test tables in merge, too */ if (lex->create_info.used_fields & HA_CREATE_USED_UNION) @@ -2870,9 +2873,10 @@ mysql_execute_command(THD *thd) tab; tab= tab->next_local) { - if (unique_table(tab, select_tables)) + TABLE_LIST *duplicate; + if ((duplicate= unique_table(tab, select_tables))) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), tab->table_name); + update_non_unique_table_error(tab, "CREATE", duplicate); res= 1; goto end_with_restart_wait; } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index b596420692a..42c06d478be 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -566,10 +566,14 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, DBUG_RETURN(TRUE); /* Check that we are not using table that we are updating in a sub select */ - if (unique_table(table_list, table_list->next_global)) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name); - DBUG_RETURN(TRUE); + TABLE_LIST *duplicate; + if ((duplicate= unique_table(table_list, table_list->next_global))) + { + update_non_unique_table_error(table_list, "UPDATE", duplicate); + my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name); + DBUG_RETURN(TRUE); + } } select_lex->fix_prepare_information(thd, conds); DBUG_RETURN(FALSE); @@ -779,7 +783,7 @@ bool mysql_multi_update_prepare(THD *thd) { TABLE *table= tl->table; TABLE_LIST *tlist; - if (!(tlist= tl->belong_to_view ? tl->belong_to_view : tl)->derived) + if (!(tlist= tl->top_table())->derived) { tlist->grant.want_privilege= (SELECT_ACL & ~tlist->grant.privilege); @@ -788,11 +792,14 @@ bool mysql_multi_update_prepare(THD *thd) DBUG_PRINT("info", ("table: %s want_privilege: %u", tl->alias, (uint) table->grant.want_privilege)); if (tl->lock_type != TL_READ && - tl->lock_type != TL_READ_NO_INSERT && - unique_table(tl, table_list)) + tl->lock_type != TL_READ_NO_INSERT) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name); - DBUG_RETURN(TRUE); + TABLE_LIST *duplicate; + if ((duplicate= unique_table(tl, table_list))) + { + update_non_unique_table_error(table_list, "UPDATE", duplicate); + DBUG_RETURN(TRUE); + } } } diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 8269c16916a..4f87706be17 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -774,9 +774,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table) } if (!res && !thd->is_fatal_error) { - TABLE_LIST *top_view= (table->belong_to_view ? - table->belong_to_view : - table); + TABLE_LIST *top_view= table->top_table(); TABLE_LIST *view_tables= lex->query_tables; TABLE_LIST *view_tables_tail= 0; TABLE_LIST *tbl; @@ -1145,8 +1143,7 @@ bool check_key_in_view(THD *thd, TABLE_LIST *view) thd->lex->select_lex.select_limit == 0) DBUG_RETURN(FALSE); /* it is normal table or query without LIMIT */ table= view->table; - if (view->belong_to_view) - view= view->belong_to_view; + view= view->top_table(); trans= view->field_translation; key_info_end= (key_info= table->key_info)+ table->s->keys; diff --git a/sql/table.cc b/sql/table.cc index 66fccec9c24..40f30dc15d8 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -2056,7 +2056,7 @@ int st_table_list::view_check_option(THD *thd, bool ignore_failure) { if (check_option && check_option->val_int() == 0) { - TABLE_LIST *view= (belong_to_view ? belong_to_view : this); + TABLE_LIST *view= top_table(); if (ignore_failure) { push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, diff --git a/sql/table.h b/sql/table.h index c9095ad48f6..d7c14e1938a 100644 --- a/sql/table.h +++ b/sql/table.h @@ -602,6 +602,8 @@ typedef struct st_table_list st_table_list *first_leaf_for_name_resolution(); st_table_list *last_leaf_for_name_resolution(); bool is_leaf_for_name_resolution(); + inline st_table_list *top_table() + { return belong_to_view ? belong_to_view : this; } inline bool prepare_check_option(THD *thd) { bool res= FALSE; |