summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMithun C Y <mithun.c.y@oracle.com>2015-08-17 15:23:47 +0530
committerMithun C Y <mithun.c.y@oracle.com>2015-08-17 15:23:47 +0530
commit557a57f3a23c486fbe12b66306ab7adffd609677 (patch)
treee3cc8becc48966c611b7a3b1ff03bc1e5da194db
parentf3dce250f45b3a02a30743b2c0928f8aaf132e88 (diff)
downloadmariadb-git-557a57f3a23c486fbe12b66306ab7adffd609677.tar.gz
Bug #21350175: SUBQUERIES IN PROCEDURE CLAUSE OF SELECT STATEMENT CAUSES SERVER FAILURES.
Analysis : ========== During JOIN::prepare of sub-query which creates the derived tables we call setup_procedure. Here we call fix_fields for parameters of procedure clause. Calling setup_procedure at this point may cause issue. If sub-query is one of parameter being fixed it might lead to complicated dependencies on derived tables being prepared. SOLUTION : ========== In 5.6 with WL#6242, we have made procedure clause parameters can only be NUM, so sub-queries are not allowed as parameters. So in 5.5 we can block sub-queries in procedure clause parameters. This eliminates above conflicting dependencies.
-rw-r--r--mysql-test/r/subselect.result2
-rw-r--r--mysql-test/t/subselect.test2
-rw-r--r--sql/sql_yacc.yy12
3 files changed, 14 insertions, 2 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 49cf73677b1..aec8e07e071 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -75,7 +75,7 @@ SELECT 1 FROM (SELECT 1 as a) b WHERE 1 IN (SELECT (SELECT a));
select (SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE(1));
ERROR HY000: Incorrect usage of PROCEDURE and subquery
SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE((SELECT 1));
-ERROR HY000: Incorrect parameters to procedure 'ANALYSE'
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT 1))' at line 1
SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NULL;
ERROR 42S22: Unknown column 'a' in 'field list'
SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NOT NULL;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index aec0db59843..a5a4b2b5c32 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -30,7 +30,7 @@ SELECT 1 IN (SELECT 1);
SELECT 1 FROM (SELECT 1 as a) b WHERE 1 IN (SELECT (SELECT a));
-- error ER_WRONG_USAGE
select (SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE(1));
--- error ER_WRONG_PARAMETERS_TO_PROCEDURE
+-- error ER_PARSE_ERROR
SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE((SELECT 1));
-- error ER_BAD_FIELD_ERROR
SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NULL;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index d9a32f2dd35..991fa390e22 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -9373,8 +9373,20 @@ procedure_clause:
if (add_proc_to_list(lex->thd, item))
MYSQL_YYABORT;
Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
+
+ /*
+ PROCEDURE CLAUSE cannot handle subquery as one of its parameter,
+ so set expr_allows_subselect as false to disallow any subqueries
+ further. Reset expr_allows_subselect back to true once the
+ parameters are reduced.
+ */
+ Lex->expr_allows_subselect= false;
}
'(' procedure_list ')'
+ {
+ /* Subqueries are allowed from now.*/
+ Lex->expr_allows_subselect= true;
+ }
;
procedure_list: