Commit d56e74eb authored by Sergey Petrunya's avatar Sergey Petrunya

MWL#90: Address review feedback part #2

parent 792c67ff
......@@ -3235,6 +3235,13 @@ int JOIN_TAB_SCAN::next()
}
/*
Walk back in join order from join_tab until we encounter a join tab with
tab->cache!=NULL, and save/restore tab->table->status along the way.
@param save TRUE save
FALSE restore
*/
void save_or_restore_used_tabs(JOIN_TAB *join_tab, bool save)
{
JOIN_TAB *first= join_tab->bush_root_tab?
......@@ -3251,6 +3258,7 @@ void save_or_restore_used_tabs(JOIN_TAB *join_tab, bool save)
{
if (save)
child->table->status= child->status;
else
{
tab->status= tab->table->status;
tab->table->status= 0;
......
......@@ -1039,6 +1039,7 @@ JOIN::optimize()
{
List_iterator<JOIN_TAB_RANGE> it(join_tab_ranges);
JOIN_TAB_RANGE *jt_range;
/* For upper level JOIN_TABs, we need to skip the const tables: */
uint first_tab_offs= const_tables;
while ((jt_range= it++))
{
......@@ -1053,6 +1054,11 @@ JOIN::optimize()
(*tab->on_expr_ref)->update_used_tables();
}
}
/*
Next jt_range will refer to SJM nest (and not the top-level range).
Inside SJM nests, we dont have const tables, so should start from the
first table:
*/
first_tab_offs= 0;
}
}
......@@ -2865,13 +2871,10 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds,
table->reginfo.join_tab=s;
table->reginfo.not_exists_optimize=0;
bzero((char*) table->const_key_parts, sizeof(key_part_map)*table->s->keys);
all_table_map|= s->table->map;
all_table_map|= table->map;
s->join=join;
s->info=0; // For describe
s->bush_root_tab= NULL;
s->dependent= tables->dep_tables;
s->key_dependent= 0;
if (tables->schema_table)
table->file->stats.records= 2;
table->quick_condition_rows= table->file->stats.records;
......@@ -6395,7 +6398,7 @@ JOIN_TAB *first_linear_tab(JOIN *join, bool after_const_tables)
first+= join->const_tables;
if (first < join->join_tab + join->top_jtrange_tables)
return first;
return NULL;
return NULL; /* All tables were const tables */
}
......@@ -6472,7 +6475,10 @@ JOIN_TAB *next_depth_first_tab(JOIN* join, JOIN_TAB* tab)
if (!start)
tab++;
if (tab == join->join_tab_ranges.head()->end)
//psergey-remove: check:
DBUG_ASSERT(join->join_tab_ranges.head()->end ==
join->join_tab +join->top_jtrange_tables);
if (tab == join->join_tab +join->top_jtrange_tables)
return NULL; /* End */
if (tab->bush_children)
......@@ -6580,17 +6586,13 @@ get_best_combination(JOIN *join)
JOIN_TAB_RANGE *jt_range= new JOIN_TAB_RANGE;
jt_range->start= jt;
jt_range->end= jt + sjm->tables;
//sjm->jt_range= jt_range;
join->join_tab_ranges.push_back(jt_range);
j->bush_children= jt_range;
j->bush_root_tab= NULL; //note: a lot of code depends on bush nodes not containing one another
j->quick= NULL;
sjm_nest_end= jt + sjm->tables;
sjm_saved_tab= j;
root_range->end= j+1;
j= jt;
//goto loop_end_not_table;
}
*j= *join->best_positions[tablenr].table;
......@@ -8546,12 +8548,10 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
check_join_cache_usage_for_tables(join, options, no_jbuf_after);
//for (i=join->const_tables ; i < join->tables ; i++)
for (tab= first_linear_tab(join, TRUE), i= join->const_tables;
tab;
tab= next_linear_tab(join, tab, TRUE), i++)
{
//JOIN_TAB *tab=join->join_tab+i;
if (tab->bush_children)
{
if (setup_sj_materialization(tab))
......
......@@ -182,7 +182,8 @@ TEST_join(JOIN *join)
in order not to garble the tabular output below.
*/
String ref_key_parts[MAX_TABLES];
for (i= 0; i < (jt_range->end - jt_range->start); i++)
int tables_in_range= jt_range->end - jt_range->start;
for (i= 0; i < tables_in_range; i++)
{
JOIN_TAB *tab= jt_range->start + i;
for (ref= 0; ref < tab->ref.key_parts; ref++)
......@@ -192,7 +193,7 @@ TEST_join(JOIN *join)
}
}
for (i= 0; i < (jt_range->end - jt_range->start); i++)
for (i= 0; i < tables_in_range; i++)
{
JOIN_TAB *tab= jt_range->start + i;
TABLE *form=tab->table;
......
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