summaryrefslogtreecommitdiff
path: root/sql/sql_prepare.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2018-01-04 23:40:37 -0800
committerIgor Babaev <igor@askmonty.org>2018-01-05 08:30:02 -0800
commit0de565a56475e355eb77225981256348c698b9b6 (patch)
tree1afe6575573eb9708884e88d9b799b8f5efcf609 /sql/sql_prepare.cc
parent287d105398db726cc15c02dff26ce039cf03ded3 (diff)
downloadmariadb-git-0de565a56475e355eb77225981256348c698b9b6.tar.gz
Fixed mdev-14852 Fails to reopen temp table within standard CTE
If the specification of a CTE contains a reference to a temporary table then THD::open_temporary_table() must be called for this reference for any occurrence of the CTE in the query. By mistake this was done only for the first occurrences of CTEs. The patch fixes this problem in With_element::clone_parsed_spec(). It also moves there the call of check_dependencies_in_with_clauses() to its proper place before the call of check_table_access(). Additionally the patch optimizes the number of calls of the function check_dependencies_in_with_clauses().
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r--sql/sql_prepare.cc11
1 files changed, 3 insertions, 8 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index be78a76152e..390b70877f5 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1573,8 +1573,6 @@ static int mysql_test_select(Prepared_statement *stmt,
lex->select_lex.context.resolve_in_select_list= TRUE;
ulong privilege= lex->exchange ? SELECT_ACL | FILE_ACL : SELECT_ACL;
- if (check_dependencies_in_with_clauses(lex->with_clauses_list))
- goto error;
if (tables)
{
if (check_table_access(thd, privilege, tables, FALSE, UINT_MAX, FALSE))
@@ -1841,9 +1839,6 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
if (create_table_precheck(thd, tables, create_table))
DBUG_RETURN(TRUE);
- if (check_dependencies_in_with_clauses(lex->with_clauses_list))
- DBUG_RETURN(TRUE);
-
if (select_lex->item_list.elements)
{
/* Base table and temporary table are not in the same name space. */
@@ -2234,9 +2229,6 @@ static bool mysql_test_insert_select(Prepared_statement *stmt,
if (insert_precheck(stmt->thd, tables))
return 1;
- if (check_dependencies_in_with_clauses(lex->with_clauses_list))
- return 1;
-
/* store it, because mysql_insert_select_prepare_tester change it */
first_local_table= lex->select_lex.table_list.first;
DBUG_ASSERT(first_local_table != 0);
@@ -2339,6 +2331,9 @@ static bool check_prepared_statement(Prepared_statement *stmt)
if (tables)
thd->get_stmt_da()->opt_clear_warning_info(thd->query_id);
+ if (check_dependencies_in_with_clauses(thd->lex->with_clauses_list))
+ goto error;
+
if (sql_command_flags[sql_command] & CF_HA_CLOSE)
mysql_ha_rm_tables(thd, tables);