Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 830a84cc037..0e5630d2cf2 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -10238,8 +10238,8 @@ best_extension_by_limited_search(JOIN *join,
If we are searching for the execution plan of a materialized semi-join nest
then allowed_tables contains bits only for the tables from this nest.
*/
- allowed_current_tables= allowed_tables=
- (join->emb_sjm_nest->sj_inner_tables & remaining_tables);
+ allowed_tables= (join->emb_sjm_nest->sj_inner_tables & remaining_tables);
+ allowed_current_tables= join->get_allowed_nj_tables(idx) & remaining_tables;
}
else
{
@@ -17873,7 +17873,12 @@ table_map JOIN::get_allowed_nj_tables(uint idx)
TABLE_LIST *last_emb;
if (idx <= const_tables ||
!(last_emb= positions[idx-1].table->table->pos_in_table_list->embedding))
- return allowed_top_level_tables;
+ {
+ if (emb_sjm_nest)
+ return emb_sjm_nest->nested_join->direct_children_map;
+ else
+ return allowed_top_level_tables;
+ }
for (;last_emb && last_emb != emb_sjm_nest;
last_emb= last_emb->embedding)
@@ -17889,7 +17894,10 @@ table_map JOIN::get_allowed_nj_tables(uint idx)
}
}
// Return bitmap of tables not in any join nest
- return allowed_top_level_tables;
+ if (emb_sjm_nest)
+ return emb_sjm_nest->nested_join->direct_children_map;
+ else
+ return allowed_top_level_tables;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment