summaryrefslogtreecommitdiff
path: root/sql/sql_cte.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2018-05-17 22:56:27 -0700
committerIgor Babaev <igor@askmonty.org>2018-05-17 22:58:21 -0700
commitde86997160ea5e02e7fc6eb877d5823e96b64523 (patch)
treed841fc4cad41d13437fbce025151b5b68cdeccd3 /sql/sql_cte.cc
parent52c98bf830cc14948f6a950961c77d64d20677a6 (diff)
downloadmariadb-git-de86997160ea5e02e7fc6eb877d5823e96b64523.tar.gz
MDEV-15581 Incorrect result (missing row) with UNION DISTINCT in anchor parts
The current code does not support recursive CTEs whose specifications contain a mix of ALL UNION and DISTINCT UNION operations. This patch catches such specifications and reports errors for them.
Diffstat (limited to 'sql/sql_cte.cc')
-rw-r--r--sql/sql_cte.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc
index cd2516c2beb..fdd6943af93 100644
--- a/sql/sql_cte.cc
+++ b/sql/sql_cte.cc
@@ -665,7 +665,6 @@ void With_element::move_anchors_ahead()
{
st_select_lex *next_sl;
st_select_lex *new_pos= spec->first_select();
- st_select_lex *UNINIT_VAR(last_sl);
new_pos->linkage= UNION_TYPE;
for (st_select_lex *sl= new_pos; sl; sl= next_sl)
{
@@ -673,6 +672,14 @@ void With_element::move_anchors_ahead()
if (is_anchor(sl))
{
sl->move_node(new_pos);
+ if (new_pos == spec->first_select())
+ {
+ enum sub_select_type type= new_pos->linkage;
+ new_pos->linkage= sl->linkage;
+ sl->linkage= type;
+ new_pos->with_all_modifier= sl->with_all_modifier;
+ sl->with_all_modifier= false;
+ }
new_pos= sl->next_select();
}
else if (!sq_rec_ref && no_rec_ref_on_top_level())
@@ -680,10 +687,7 @@ void With_element::move_anchors_ahead()
sq_rec_ref= find_first_sq_rec_ref_in_select(sl);
DBUG_ASSERT(sq_rec_ref != NULL);
}
- last_sl= sl;
}
- if (spec->union_distinct)
- spec->union_distinct= last_sl;
first_recursive= new_pos;
}