Commit 0f46efcb authored by Igor Babaev's avatar Igor Babaev

Post-review fixes for the patch that added the code allowing to use

hash join over equi-join conditions without supporting indexes.
parent ed240578
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
FALSE No FALSE No
*/ */
bool uses_index_fields_only(Item *item, TABLE *tbl, uint keyno, bool uses_index_fields_only(Item *item, TABLE *tbl, uint keyno,
bool other_tbls_ok) bool other_tbls_ok)
{ {
if (item->const_item()) if (item->const_item())
...@@ -279,15 +279,12 @@ Item *make_cond_remainder(Item *cond, bool exclude_index) ...@@ -279,15 +279,12 @@ Item *make_cond_remainder(Item *cond, bool exclude_index)
tab A join tab that has tab->table->file and its condition tab A join tab that has tab->table->file and its condition
in tab->select_cond in tab->select_cond
keyno Index for which extract and push the condition keyno Index for which extract and push the condition
other_tbls_ok TRUE <=> Fields of other non-const tables are allowed
factor_out TRUE <=> Factor out the extracted condition
DESCRIPTION DESCRIPTION
Try to extract and push the index condition down to table handler Try to extract and push the index condition down to table handler
*/ */
void push_index_cond(JOIN_TAB *tab, uint keyno, bool other_tbls_ok, void push_index_cond(JOIN_TAB *tab, uint keyno)
bool factor_out)
{ {
DBUG_ENTER("push_index_cond"); DBUG_ENTER("push_index_cond");
Item *idx_cond; Item *idx_cond;
...@@ -320,7 +317,7 @@ void push_index_cond(JOIN_TAB *tab, uint keyno, bool other_tbls_ok, ...@@ -320,7 +317,7 @@ void push_index_cond(JOIN_TAB *tab, uint keyno, bool other_tbls_ok,
print_where(tab->select_cond, "full cond", QT_ORDINARY);); print_where(tab->select_cond, "full cond", QT_ORDINARY););
idx_cond= make_cond_for_index(tab->select_cond, tab->table, keyno, idx_cond= make_cond_for_index(tab->select_cond, tab->table, keyno,
other_tbls_ok); tab->icp_other_tables_ok);
DBUG_EXECUTE("where", DBUG_EXECUTE("where",
print_where(idx_cond, "idx cond", QT_ORDINARY);); print_where(idx_cond, "idx cond", QT_ORDINARY););
...@@ -339,10 +336,8 @@ void push_index_cond(JOIN_TAB *tab, uint keyno, bool other_tbls_ok, ...@@ -339,10 +336,8 @@ void push_index_cond(JOIN_TAB *tab, uint keyno, bool other_tbls_ok,
/* /*
if cache is used then the value is TRUE only if cache is used then the value is TRUE only
for BKA[_UNIQUE] cache (see check_join_cache_usage func). for BKA[_UNIQUE] cache (see check_join_cache_usage func).
In this case other_tbls_ok is an equivalent of
cache->is_key_access().
*/ */
other_tbls_ok && tab->icp_other_tables_ok &&
(idx_cond->used_tables() & (idx_cond->used_tables() &
~(tab->table->map | tab->join->const_table_map))) ~(tab->table->map | tab->join->const_table_map)))
tab->cache_idx_cond= idx_cond; tab->cache_idx_cond= idx_cond;
...@@ -360,8 +355,9 @@ void push_index_cond(JOIN_TAB *tab, uint keyno, bool other_tbls_ok, ...@@ -360,8 +355,9 @@ void push_index_cond(JOIN_TAB *tab, uint keyno, bool other_tbls_ok,
if (idx_remainder_cond != idx_cond) if (idx_remainder_cond != idx_cond)
tab->ref.disable_cache= TRUE; tab->ref.disable_cache= TRUE;
Item *row_cond= factor_out ? make_cond_remainder(tab->select_cond, TRUE) : Item *row_cond= tab->idx_cond_fact_out ?
tab->pre_idx_push_select_cond; make_cond_remainder(tab->select_cond, TRUE) :
tab->pre_idx_push_select_cond;
DBUG_EXECUTE("where", DBUG_EXECUTE("where",
print_where(row_cond, "remainder cond", QT_ORDINARY);); print_where(row_cond, "remainder cond", QT_ORDINARY););
......
...@@ -1329,19 +1329,18 @@ bool find_eq_ref_candidate(TABLE *table, table_map sj_inner_tables) ...@@ -1329,19 +1329,18 @@ bool find_eq_ref_candidate(TABLE *table, table_map sj_inner_tables)
if (keyuse) if (keyuse)
{ {
while (1) /* For each key */ do
{ {
if (keyuse->is_for_hash_join())
{
keyuse++;
if (keyuse->table != table)
return FALSE;
continue;
}
uint key= keyuse->key; uint key= keyuse->key;
KEY *keyinfo= table->key_info + key; KEY *keyinfo;
key_part_map bound_parts= 0; key_part_map bound_parts= 0;
if (keyinfo->flags & HA_NOSAME) bool is_excluded_key= keyuse->is_for_hash_join();
if (!is_excluded_key)
{
keyinfo= table->key_info + key;
is_excluded_key= !test(keyinfo->flags & HA_NOSAME);
}
if (!is_excluded_key)
{ {
do /* For all equalities on all key parts */ do /* For all equalities on all key parts */
{ {
...@@ -1356,20 +1355,15 @@ bool find_eq_ref_candidate(TABLE *table, table_map sj_inner_tables) ...@@ -1356,20 +1355,15 @@ bool find_eq_ref_candidate(TABLE *table, table_map sj_inner_tables)
if (bound_parts == PREV_BITS(uint, keyinfo->key_parts)) if (bound_parts == PREV_BITS(uint, keyinfo->key_parts))
return TRUE; return TRUE;
if (keyuse->table != table)
return FALSE;
} }
else else
{ {
do do
{ {
keyuse++; keyuse++;
if (keyuse->table != table) } while (keyuse->key == key && keyuse->table == table);
return FALSE;
}
while (keyuse->key == key);
} }
} } while (keyuse->table == table);
} }
return FALSE; return FALSE;
} }
......
This diff is collapsed.
...@@ -251,7 +251,15 @@ typedef struct st_join_table { ...@@ -251,7 +251,15 @@ typedef struct st_join_table {
*/ */
ha_rows limit; ha_rows limit;
TABLE_REF ref; TABLE_REF ref;
/* TRUE <=> condition pushdown supports other tables presence */
bool icp_other_tables_ok;
/*
TRUE <=> condition pushed to the index has to be factored out of
the condition pushed to the table
*/
bool idx_cond_fact_out;
bool use_join_cache; bool use_join_cache;
uint used_join_cache_level;
ulong join_buffer_size_limit; ulong join_buffer_size_limit;
JOIN_CACHE *cache; JOIN_CACHE *cache;
/* /*
...@@ -1247,8 +1255,7 @@ inline bool optimizer_flag(THD *thd, uint flag) ...@@ -1247,8 +1255,7 @@ inline bool optimizer_flag(THD *thd, uint flag)
void eliminate_tables(JOIN *join); void eliminate_tables(JOIN *join);
/* Index Condition Pushdown entry point function */ /* Index Condition Pushdown entry point function */
void push_index_cond(JOIN_TAB *tab, uint keyno, bool other_tbls_ok, void push_index_cond(JOIN_TAB *tab, uint keyno);
bool factor_out);
/**************************************************************************** /****************************************************************************
Temporary table support for SQL Runtime Temporary table support for SQL Runtime
......
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