Skip to content

Commit

Permalink
MDEV-13436 PREPARE doesn't work as expected & throws errors but MySQL…
Browse files Browse the repository at this point in the history
… is working fine

Now we allow derived in the from clause of subqueries so set
flag which prevent optimisation of subqueries during view
creation before derived processing so subquery will be
correctly printed in the view .frm.
  • Loading branch information
sanja-byelkin committed Sep 11, 2017
1 parent 2425f2a commit 6b5c0ef
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
23 changes: 23 additions & 0 deletions mysql-test/r/view.result
Original file line number Diff line number Diff line change
Expand Up @@ -6624,5 +6624,28 @@ drop table procViewTable;
use test;
drop database bugTest;
#
# MDEV-13436: PREPARE doesn't work as expected & throws errors but
# MySQL is working fine
#
create table t1 (a int);
insert into t1 values (1),(2);
SET @sql_query = "
CREATE VIEW v1 AS
SELECT * FROM (
SELECT CASE WHEN 1 IN (SELECT a from t1 where a < 2) THEN TRUE END AS testcase
) testalias
";
PREPARE stmt FROM @sql_query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
show create view v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `testalias`.`testcase` AS `testcase` from (select case when 1 in (select `test`.`t1`.`a` from `test`.`t1` where `test`.`t1`.`a` < 2) then 1 end AS `testcase`) `testalias` latin1 latin1_swedish_ci
SELECT * FROM v1;
testcase
1
drop view v1;
drop table t1;
#
# End of 10.2 tests
#
21 changes: 21 additions & 0 deletions mysql-test/t/view.test
Original file line number Diff line number Diff line change
Expand Up @@ -6344,6 +6344,27 @@ drop table procViewTable;
use test;
drop database bugTest;

--echo #
--echo # MDEV-13436: PREPARE doesn't work as expected & throws errors but
--echo # MySQL is working fine
--echo #

create table t1 (a int);
insert into t1 values (1),(2);
SET @sql_query = "
CREATE VIEW v1 AS
SELECT * FROM (
SELECT CASE WHEN 1 IN (SELECT a from t1 where a < 2) THEN TRUE END AS testcase
) testalias
";
PREPARE stmt FROM @sql_query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
show create view v1;
SELECT * FROM v1;
drop view v1;
drop table t1;

--echo #
--echo # End of 10.2 tests
--echo #
2 changes: 1 addition & 1 deletion sql/sql_prepare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2097,11 +2097,11 @@ static bool mysql_test_create_view(Prepared_statement *stmt)
if (thd->open_temporary_tables(tables))
goto err;

lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
if (open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL,
DT_PREPARE))
goto err;

lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
res= select_like_stmt_test(stmt, 0, 0);

err:
Expand Down

0 comments on commit 6b5c0ef

Please sign in to comment.