summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2021-11-17 13:55:54 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2021-11-17 13:55:54 +0200
commit9962cda52722b77c2a7e0314bbaa2e4f963f55c1 (patch)
tree576d56bc2ddf7f644ce56c4a1ef27ca59cc42290 /sql
parent7ea12742d30be7b56120f1bf66d91f777b1da450 (diff)
parented0a224b3d42423699d977c338e3da05fccafaf2 (diff)
downloadmariadb-git-9962cda52722b77c2a7e0314bbaa2e4f963f55c1.tar.gz
Merge 10.2 into 10.3
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_cte.cc57
1 files changed, 34 insertions, 23 deletions
diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc
index fa7011b7554..9acdf2278ac 100644
--- a/sql/sql_cte.cc
+++ b/sql/sql_cte.cc
@@ -1036,6 +1036,15 @@ st_select_lex_unit *With_element::clone_parsed_spec(LEX *old_lex,
lex_start(thd);
lex->clone_spec_offset= unparsed_spec_offset;
lex->with_cte_resolution= true;
+ /*
+ There's no need to add SPs/SFs referenced in the clone to the global
+ list of the SPs/SFs used in the query as they were added when the first
+ reference to the cloned CTE was parsed. Yet the recursive call of the
+ parser must to know that they were already included into the list.
+ */
+ lex->sroutines= old_lex->sroutines;
+ lex->sroutines_list_own_last= old_lex->sroutines_list_own_last;
+ lex->sroutines_list_own_elements= old_lex->sroutines_list_own_elements;
/*
The specification of a CTE is to be parsed as a regular query.
@@ -1082,6 +1091,29 @@ st_select_lex_unit *With_element::clone_parsed_spec(LEX *old_lex,
goto err;
/*
+ The unit of the specification that just has been parsed is included
+ as a slave of the select that contained in its from list the table
+ reference for which the unit has been created.
+ */
+ lex->unit.include_down(with_table->select_lex);
+ lex->unit.set_slave(with_select);
+ lex->unit.cloned_from= spec;
+
+ /*
+ Now all references to the CTE defined outside of the cloned specification
+ has to be resolved. Additionally if old_lex->only_cte_resolution == false
+ for the table references that has not been resolved requests for mdl_locks
+ has to be set.
+ */
+ lex->only_cte_resolution= old_lex->only_cte_resolution;
+ if (lex->resolve_references_to_cte(lex->query_tables,
+ lex->query_tables_last))
+ {
+ res= NULL;
+ goto err;
+ }
+
+ /*
The global chain of TABLE_LIST objects created for the specification that
just has been parsed is added to such chain that contains the reference
to the CTE whose specification is parsed right after the TABLE_LIST object
@@ -1105,32 +1137,11 @@ st_select_lex_unit *With_element::clone_parsed_spec(LEX *old_lex,
old_lex->query_tables_last= lex->query_tables_last;
}
}
+ old_lex->sroutines_list_own_last= lex->sroutines_list_own_last;
+ old_lex->sroutines_list_own_elements= lex->sroutines_list_own_elements;
res= &lex->unit;
res->with_element= this;
- /*
- The unit of the specification that just has been parsed is included
- as a slave of the select that contained in its from list the table
- reference for which the unit has been created.
- */
- lex->unit.include_down(with_table->select_lex);
- lex->unit.set_slave(with_select);
- lex->unit.cloned_from= spec;
-
- /*
- Now all references to the CTE defined outside of the cloned specification
- has to be resolved. Additionally if old_lex->only_cte_resolution == false
- for the table references that has not been resolved requests for mdl_locks
- has to be set.
- */
- lex->only_cte_resolution= old_lex->only_cte_resolution;
- if (lex->resolve_references_to_cte(lex->query_tables,
- lex->query_tables_last))
- {
- res= NULL;
- goto err;
- }
-
last_clone_select= lex->all_selects_list;
while (last_clone_select->next_select_in_list())
last_clone_select= last_clone_select->next_select_in_list();