=== modified file 'mysql-test/r/create.result' --- mysql-test/r/create.result 2014-01-29 13:37:17 +0000 +++ mysql-test/r/create.result 2014-03-17 09:18:32 +0000 @@ -2580,6 +2580,55 @@ a b 1 1 drop table t1; # +# WL#5576 Prohibit CREATE TABLE ... SELECT to modify other tables +# +create function f() +returns int +begin +insert into t2 values(1); +return 1; +end| +# +# 1. The function updates a base table +# +create table t2(c1 int); +create table t1 select f(); +ERROR HY000: Can't update table 't2' while 't1' is being created. +create temporary table t1 select f(); +ERROR HY000: Can't update table 't2' while 't1' is being created. +drop table t2; +# +# 2. The function updates a view which derives from a base table +# +create table t3(c1 int); +create view t2 as select c1 from t3; +create table t1 select f(); +ERROR HY000: Can't update table 't2' while 't1' is being created. +create temporary table t1 select f(); +ERROR HY000: Can't update table 't2' while 't1' is being created. +drop view t2; +# +# 3. The function updates a view which derives from two base tables +# +create table t4(c1 int); +create view t2 as select t3.c1 as c1 from t3, t4; +create table t1 select f(); +ERROR HY000: Can't update table 't2' while 't1' is being created. +create temporary table t1 select f(); +ERROR HY000: Can't update table 't2' while 't1' is being created. +drop view t2; +drop tables t3, t4; +# +# 4. The function updates a view which selects a constant number +# +create view t2 as select 1; +create table t1 select f(); +ERROR HY000: Can't update table 't2' while 't1' is being created. +create temporary table t1 select f(); +ERROR HY000: Can't update table 't2' while 't1' is being created. +drop view t2; +drop function f; +# # Checking that CREATE IF NOT EXISTS is not blocked by running SELECT # create table t1 (a int, b int) engine=myisam; === modified file 'mysql-test/t/create.test' --- mysql-test/t/create.test 2014-01-29 13:37:17 +0000 +++ mysql-test/t/create.test 2014-03-17 09:17:30 +0000 @@ -1996,6 +1996,72 @@ select * from t1; drop table t1; --echo # +--echo # WL#5576 Prohibit CREATE TABLE ... SELECT to modify other tables +--echo # + +delimiter |; +create function f() +returns int +begin +insert into t2 values(1); +return 1; +end| +delimiter ;| + +--echo # +--echo # 1. The function updates a base table +--echo # +create table t2(c1 int); + +--error ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT +create table t1 select f(); +--error ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT +create temporary table t1 select f(); + + +drop table t2; + +--echo # +--echo # 2. The function updates a view which derives from a base table +--echo # +create table t3(c1 int); +create view t2 as select c1 from t3; + +--error ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT +create table t1 select f(); +--error ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT +create temporary table t1 select f(); + +drop view t2; + +--echo # +--echo # 3. The function updates a view which derives from two base tables +--echo # +create table t4(c1 int); +create view t2 as select t3.c1 as c1 from t3, t4; + +--error ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT +create table t1 select f(); +--error ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT +create temporary table t1 select f(); + +drop view t2; +drop tables t3, t4; + +--echo # +--echo # 4. The function updates a view which selects a constant number +--echo # +create view t2 as select 1; + +--error ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT +create table t1 select f(); +--error ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT +create temporary table t1 select f(); + +drop view t2; +drop function f; + +--echo # --echo # Checking that CREATE IF NOT EXISTS is not blocked by running SELECT --echo #