diff options
Diffstat (limited to 'sql/sql_cte.h')
-rw-r--r-- | sql/sql_cte.h | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/sql/sql_cte.h b/sql/sql_cte.h index 4cec1240d1f..e0fbd79803b 100644 --- a/sql/sql_cte.h +++ b/sql/sql_cte.h @@ -393,10 +393,24 @@ public: bool add_with_element(With_element *elem); /* Add this with clause to the list of with clauses used in the statement */ - void add_to_list(With_clause ** &last_next) + void add_to_list(With_clause **ptr, With_clause ** &last_next) { - *last_next= this; - last_next= &this->next_with_clause; + if (embedding_with_clause) + { + /* + An embedded with clause is always placed before the embedding one + in the list of with clauses used in the query. + */ + while (*ptr != embedding_with_clause) + ptr= &(*ptr)->next_with_clause; + *ptr= this; + next_with_clause= embedding_with_clause; + } + else + { + *last_next= this; + last_next= &this->next_with_clause; + } } st_select_lex_unit *get_owner() { return owner; } |