summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2017-10-13 07:24:35 -0700
committerIgor Babaev <igor@askmonty.org>2017-10-13 07:24:54 -0700
commit2bab29ebba7a641d43a98737fd1c160971357cd4 (patch)
tree0f6c87a6b706e4e18847418341681bf52605c699 /sql/sql_select.cc
parent8be76a6a907ab858b4fdb5d525548aedfdb4ddf3 (diff)
downloadmariadb-git-2bab29ebba7a641d43a98737fd1c160971357cd4.tar.gz
Fixed the bug mdev-13135.
For each SELECT the list sj_nests is built by the function simplify_joins() when scanning different join nests. This function may be called several times for the same join nest. That's why before adding a new member to sj_nests it is necessary to check if it's already in the list. The code of simplify_joins() lacked this check and as a result it could cause memory overwright for some queries.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 720c0a22681..6e67bb11015 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -13349,10 +13349,23 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top,
nested_join= table->nested_join;
if (table->sj_on_expr && !in_sj)
{
- /*
- If this is a semi-join that is not contained within another semi-join,
- leave it intact (otherwise it is flattened)
- */
+ /*
+ If this is a semi-join that is not contained within another semi-join
+ leave it intact (otherwise it is flattened)
+ */
+ /*
+ Make sure that any semi-join appear in
+ the join->select_lex->sj_nests list only once
+ */
+ List_iterator_fast<TABLE_LIST> sj_it(join->select_lex->sj_nests);
+ TABLE_LIST *sj_nest;
+ while ((sj_nest= sj_it++))
+ {
+ if (table == sj_nest)
+ break;
+ }
+ if (sj_nest)
+ continue;
join->select_lex->sj_nests.push_back(table);
/*