diff options
-rw-r--r-- | mysql-test/main/ps.result | 43 | ||||
-rw-r--r-- | mysql-test/main/ps.test | 46 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 13 |
3 files changed, 96 insertions, 6 deletions
diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result index 682c3e31be4..34a960005ad 100644 --- a/mysql-test/main/ps.result +++ b/mysql-test/main/ps.result @@ -5321,5 +5321,48 @@ DROP PROCEDURE p2; DROP PROCEDURE p1; DROP ROLE testrole; # +# MDEV-16992: prepare of CREATE TABLE, CREATE VIEW, DO, SET, CALL +# statements with CTE containing materialized derived +# (the bug is reproducible on 10.4) +# +prepare stmt from +"CREATE TABLE t1 AS + WITH cte(a) AS (SELECT * FROM (SELECT 1) AS t) SELECT * FROM cte;"; +execute stmt; +select * from t1; +a +1 +prepare stmt from +"CREATE VIEW v1 AS + WITH cte(a) AS (SELECT * FROM (SELECT 1) AS t) SELECT * FROM cte;"; +execute stmt; +select * from v1; +a +1 +prepare stmt from +"DO (SELECT 1 + FROM (WITH cte AS (SELECT * FROM (SELECT 1) AS t) + SELECT * FROM cte) AS tt);"; +execute stmt; +prepare stmt from +"SET @a = (SELECT 1 + FROM (WITH cte AS (SELECT * FROM (SELECT 1) AS t) + SELECT * FROM cte) AS t);"; +execute stmt; +create procedure p (i int) insert into t1 values(i); +prepare stmt from +"CALL p + ((SELECT 1 + FROM (WITH cte AS (SELECT * FROM (SELECT 1) AS t) + SELECT * FROM cte) AS tt));"; +execute stmt; +select * from t1; +a +1 +1 +drop procedure p; +drop view v1; +drop table t1; +# # End of 10.2 tests # diff --git a/mysql-test/main/ps.test b/mysql-test/main/ps.test index 79c08d62290..2b8a05094a6 100644 --- a/mysql-test/main/ps.test +++ b/mysql-test/main/ps.test @@ -4785,5 +4785,51 @@ DROP PROCEDURE p1; DROP ROLE testrole; --echo # +--echo # MDEV-16992: prepare of CREATE TABLE, CREATE VIEW, DO, SET, CALL +--echo # statements with CTE containing materialized derived +--echo # (the bug is reproducible on 10.4) +--echo # + +--enable_result_log + +prepare stmt from +"CREATE TABLE t1 AS + WITH cte(a) AS (SELECT * FROM (SELECT 1) AS t) SELECT * FROM cte;"; +execute stmt; +select * from t1; + +prepare stmt from +"CREATE VIEW v1 AS + WITH cte(a) AS (SELECT * FROM (SELECT 1) AS t) SELECT * FROM cte;"; +execute stmt; +select * from v1; + +prepare stmt from +"DO (SELECT 1 + FROM (WITH cte AS (SELECT * FROM (SELECT 1) AS t) + SELECT * FROM cte) AS tt);"; +execute stmt; + +prepare stmt from +"SET @a = (SELECT 1 + FROM (WITH cte AS (SELECT * FROM (SELECT 1) AS t) + SELECT * FROM cte) AS t);"; +execute stmt; + +create procedure p (i int) insert into t1 values(i); + +prepare stmt from +"CALL p + ((SELECT 1 + FROM (WITH cte AS (SELECT * FROM (SELECT 1) AS t) + SELECT * FROM cte) AS tt));"; +execute stmt; +select * from t1; + +drop procedure p; +drop view v1; +drop table t1; + +--echo # --echo # End of 10.2 tests --echo # diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index fd526f9a660..2ffecbab617 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1582,7 +1582,7 @@ static bool mysql_test_do_fields(Prepared_statement *stmt, DBUG_RETURN(TRUE); if (open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL, - DT_PREPARE | DT_CREATE)) + DT_INIT | DT_PREPARE | DT_CREATE)) DBUG_RETURN(TRUE); DBUG_RETURN(setup_fields(thd, Ref_ptr_array(), *values, COLUMNS_READ, 0, NULL, 0)); @@ -1614,7 +1614,7 @@ static bool mysql_test_set_fields(Prepared_statement *stmt, if ((tables && check_table_access(thd, SELECT_ACL, tables, FALSE, UINT_MAX, FALSE)) || open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL, - DT_PREPARE | DT_CREATE)) + DT_INIT | DT_PREPARE | DT_CREATE)) goto error; while ((var= it++)) @@ -1651,7 +1651,8 @@ static bool mysql_test_call_fields(Prepared_statement *stmt, if ((tables && check_table_access(thd, SELECT_ACL, tables, FALSE, UINT_MAX, FALSE)) || - open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL, DT_PREPARE)) + open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL, + DT_INIT | DT_PREPARE)) goto err; while ((item= it++)) @@ -1777,7 +1778,7 @@ static bool mysql_test_create_table(Prepared_statement *stmt) if (open_normal_and_derived_tables(stmt->thd, lex->query_tables, MYSQL_OPEN_FORCE_SHARED_MDL, - DT_PREPARE | DT_CREATE)) + DT_INIT | DT_PREPARE | DT_CREATE)) DBUG_RETURN(TRUE); select_lex->context.resolve_in_select_list= TRUE; @@ -1798,7 +1799,7 @@ static bool mysql_test_create_table(Prepared_statement *stmt) */ if (open_normal_and_derived_tables(stmt->thd, lex->query_tables, MYSQL_OPEN_FORCE_SHARED_MDL, - DT_PREPARE)) + DT_INIT | DT_PREPARE)) DBUG_RETURN(TRUE); } @@ -2025,7 +2026,7 @@ static bool mysql_test_create_view(Prepared_statement *stmt) lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW; if (open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL, - DT_PREPARE)) + DT_INIT | DT_PREPARE)) goto err; res= select_like_stmt_test(stmt, 0, 0); |