Commit 2ea5096c authored by Sergey Petrunya's avatar Sergey Petrunya

Merge fix for BUG#822134

parents b468a80e 81335120
......@@ -7189,6 +7189,32 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab,
DBUG_RETURN(FALSE);
}
/*
Check if a set of tables specified by used_tables can be accessed when
we're doing scan on join_tab jtab.
*/
static bool are_tables_local(JOIN_TAB *jtab, table_map used_tables)
{
if (jtab->bush_root_tab)
{
/*
jtab is inside execution join nest. We may not refer to outside tables,
except the const tables.
*/
table_map local_tables= jtab->emb_sj_nest->nested_join->used_tables |
jtab->join->const_table_map;
return !test(used_tables & ~local_tables);
}
/*
If we got here then jtab is at top level.
- all other tables at top level are accessible,
- tables in join nests are accessible too, because all their columns that
are needed at top level will be unpacked when scanning the
materialization table.
*/
return TRUE;
}
static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
KEYUSE *org_keyuse, table_map used_tables)
......@@ -7233,6 +7259,8 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
do
{
if (!(~used_tables & keyuse->used_tables))
{
if (are_tables_local(j, keyuse->val->used_tables()))
{
if ((is_hash_join_key_no(key) &&
(keyparts == 0 || keyuse->keypart != (keyuse-1)->keypart)) ||
......@@ -7244,6 +7272,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
found_part_ref_or_null|= keyuse->optimize & ~KEY_OPTIMIZE_EQ;
}
}
}
keyuse++;
} while (keyuse->table == table && keyuse->key == key);
} /* not ftkey */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment