Commit f93b0bbe authored by Sergey Petrunya's avatar Sergey Petrunya

MWL#90: subquery optimizations

- Remove redundant changes againist 5.3-main
parent 9482a2cf
...@@ -3587,7 +3587,7 @@ subselect_hash_sj_engine::get_strategy_using_schema() ...@@ -3587,7 +3587,7 @@ subselect_hash_sj_engine::get_strategy_using_schema()
bitmap_set_bit(&partial_match_key_parts, i); bitmap_set_bit(&partial_match_key_parts, i);
++count_partial_match_columns; ++count_partial_match_columns;
} }
}; }
} }
/* If no column contains NULLs use regular hash index lookups. */ /* If no column contains NULLs use regular hash index lookups. */
...@@ -3787,7 +3787,8 @@ bitmap_init_memroot(MY_BITMAP *map, uint n_bits, MEM_ROOT *mem_root) ...@@ -3787,7 +3787,8 @@ bitmap_init_memroot(MY_BITMAP *map, uint n_bits, MEM_ROOT *mem_root)
reexecution. reexecution.
@param tmp_columns the items that produce the data for the temp table @param tmp_columns the items that produce the data for the temp table
@param subquery_id subquery's identifier (for temptable name) @param subquery_id subquery's identifier (to make "<subquery%d>" name for
EXPLAIN)
@details @details
- Create a temporary table to store the result of the IN subquery. The - Create a temporary table to store the result of the IN subquery. The
...@@ -3803,7 +3804,7 @@ bitmap_init_memroot(MY_BITMAP *map, uint n_bits, MEM_ROOT *mem_root) ...@@ -3803,7 +3804,7 @@ bitmap_init_memroot(MY_BITMAP *map, uint n_bits, MEM_ROOT *mem_root)
@retval FALSE otherwise @retval FALSE otherwise
*/ */
bool subselect_hash_sj_engine::init_permanent(List<Item> *tmp_columns, bool subselect_hash_sj_engine::init_permanent(List<Item> *tmp_columns,
uint subquery_id) uint subquery_id)
{ {
/* Options to create_tmp_table. */ /* Options to create_tmp_table. */
...@@ -3998,7 +3999,6 @@ subselect_hash_sj_engine::make_unique_engine() ...@@ -3998,7 +3999,6 @@ subselect_hash_sj_engine::make_unique_engine()
tab->table= tmp_table; tab->table= tmp_table;
tab->ref.tmp_table_index_lookup_init(thd, tmp_key, it, FALSE); tab->ref.tmp_table_index_lookup_init(thd, tmp_key, it, FALSE);
DBUG_RETURN(new subselect_uniquesubquery_engine(thd, tab, item, DBUG_RETURN(new subselect_uniquesubquery_engine(thd, tab, item,
semi_join_conds)); semi_join_conds));
} }
......
...@@ -7788,6 +7788,7 @@ bool setup_tables(THD *thd, Name_resolution_context *context, ...@@ -7788,6 +7788,7 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
} }
DBUG_ASSERT(item == table_list->jtbm_subselect); DBUG_ASSERT(item == table_list->jtbm_subselect);
table_list->jtbm_subselect->setup_engine(FALSE); table_list->jtbm_subselect->setup_engine(FALSE);
//psergey-merge: ^ todo: error checking!
} }
} }
......
...@@ -3033,7 +3033,8 @@ bool select_dumpvar::send_eof() ...@@ -3033,7 +3033,8 @@ bool select_dumpvar::send_eof()
} }
bool select_materialize_with_stats:: bool
select_materialize_with_stats::
create_result_table(THD *thd_arg, List<Item> *column_types, create_result_table(THD *thd_arg, List<Item> *column_types,
bool is_union_distinct, ulonglong options, bool is_union_distinct, ulonglong options,
const char *table_alias, bool bit_fields_as_long) const char *table_alias, bool bit_fields_as_long)
......
...@@ -1061,7 +1061,6 @@ int JOIN_CACHE::realloc_buffer() ...@@ -1061,7 +1061,6 @@ int JOIN_CACHE::realloc_buffer()
*/ */
int JOIN_CACHE::init() int JOIN_CACHE::init()
//psergey-merge:wtf is this here: for (tab= start_tab; tab != join_tab; tab= next_linear_tab(join, tab, TRUE))
{ {
DBUG_ENTER("JOIN_CACHE::init"); DBUG_ENTER("JOIN_CACHE::init");
...@@ -3260,23 +3259,7 @@ uint JOIN_CACHE_HASHED::get_next_key(uchar ** key) ...@@ -3260,23 +3259,7 @@ uint JOIN_CACHE_HASHED::get_next_key(uchar ** key)
int JOIN_TAB_SCAN::open() int JOIN_TAB_SCAN::open()
{ {
//psergey-merge: todo: check the below:
//JOIN_TAB *bound= join_tab-cache->tables;
#if 0
JOIN_TAB *bound= cache->start_tab;
// psergey-todo-merge: can we really iterate backwards?
// Q: is there really a need to iterate backwards?
for (JOIN_TAB *tab= join_tab-1; tab != bound && !tab->cache; tab--)
{
tab->status= tab->table->status;
tab->table->status= 0;
}
#endif
save_or_restore_used_tabs(join_tab, FALSE); save_or_restore_used_tabs(join_tab, FALSE);
is_first_record= TRUE; is_first_record= TRUE;
return join_init_read_record(join_tab); return join_init_read_record(join_tab);
} }
...@@ -3381,12 +3364,7 @@ void save_or_restore_used_tabs(JOIN_TAB *join_tab, bool save) ...@@ -3381,12 +3364,7 @@ void save_or_restore_used_tabs(JOIN_TAB *join_tab, bool save)
void JOIN_TAB_SCAN::close() void JOIN_TAB_SCAN::close()
{ {
#if 0 save_or_restore_used_tabs(join_tab, TRUE);
JOIN_TAB *bound= join_tab - cache->tables;
for (JOIN_TAB *tab= join_tab-1; tab != bound && !tab->cache; tab--)
tab->table->status= tab->status;
#endif
save_or_restore_used_tabs(join_tab, TRUE);
} }
...@@ -3786,15 +3764,6 @@ int JOIN_TAB_SCAN_MRR::open() ...@@ -3786,15 +3764,6 @@ int JOIN_TAB_SCAN_MRR::open()
/* Dynamic range access is never used with BKA */ /* Dynamic range access is never used with BKA */
DBUG_ASSERT(join_tab->use_quick != 2); DBUG_ASSERT(join_tab->use_quick != 2);
/*
psergey-merge: done?
JOIN_TAB *bound= join_tab - cache->tables;
for (JOIN_TAB *tab= join_tab-1; tab != bound && !tab->cache; tab--)
{
tab->status= tab->table->status;
tab->table->status= 0;
}
*/
save_or_restore_used_tabs(join_tab, FALSE); save_or_restore_used_tabs(join_tab, FALSE);
init_mrr_buff(); init_mrr_buff();
......
...@@ -2827,7 +2827,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds, ...@@ -2827,7 +2827,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds,
SARGABLE_PARAM *sargables= 0; SARGABLE_PARAM *sargables= 0;
JOIN_TAB *stat_vector[MAX_TABLES+1]; JOIN_TAB *stat_vector[MAX_TABLES+1];
DBUG_ENTER("make_join_statistics"); DBUG_ENTER("make_join_statistics");
LINT_INIT(table); /* inited in all loops */ LINT_INIT(table); /* inited in all loops */
table_count=join->tables; table_count=join->tables;
...@@ -2842,7 +2842,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds, ...@@ -2842,7 +2842,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds,
stat_end=stat+table_count; stat_end=stat+table_count;
found_const_table_map= all_table_map=0; found_const_table_map= all_table_map=0;
const_count=0; const_count=0;
for (s= stat, i= 0; for (s= stat, i= 0;
tables; tables;
s++, tables= tables->next_leaf, i++) s++, tables= tables->next_leaf, i++)
...@@ -2876,7 +2876,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds, ...@@ -2876,7 +2876,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds,
if (tables->schema_table) if (tables->schema_table)
table->file->stats.records= 2; table->file->stats.records= 2;
table->quick_condition_rows= table->file->stats.records; table->quick_condition_rows= table->file->stats.records;
s->on_expr_ref= &tables->on_expr; s->on_expr_ref= &tables->on_expr;
if (*s->on_expr_ref) if (*s->on_expr_ref)
{ {
...@@ -2931,7 +2931,6 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds, ...@@ -2931,7 +2931,6 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds,
no_rows_const_tables |= table->map; no_rows_const_tables |= table->map;
} }
} }
stat_vector[i]=0; stat_vector[i]=0;
join->outer_join=outer_join; join->outer_join=outer_join;
...@@ -6498,7 +6497,7 @@ static Item * const null_ptr= NULL; ...@@ -6498,7 +6497,7 @@ static Item * const null_ptr= NULL;
fix_semijoin_strategies_for_picked_join_order) fix_semijoin_strategies_for_picked_join_order)
- create join->join_tab array and put there the JOIN_TABs in the join order - create join->join_tab array and put there the JOIN_TABs in the join order
- create data structures describing ref access methods. - create data structures describing ref access methods.
NOTE NOTE
In this function we switch from pre-join-optimization JOIN_TABs to In this function we switch from pre-join-optimization JOIN_TABs to
post-join-optimization JOIN_TABs. This is achieved by copying the entire post-join-optimization JOIN_TABs. This is achieved by copying the entire
...@@ -6530,7 +6529,7 @@ get_best_combination(JOIN *join) ...@@ -6530,7 +6529,7 @@ get_best_combination(JOIN *join)
used_tables= OUTER_REF_TABLE_BIT; // Outer row is already read used_tables= OUTER_REF_TABLE_BIT; // Outer row is already read
fix_semijoin_strategies_for_picked_join_order(join); fix_semijoin_strategies_for_picked_join_order(join);
JOIN_TAB_RANGE *root_range= new JOIN_TAB_RANGE; JOIN_TAB_RANGE *root_range= new JOIN_TAB_RANGE;
root_range->start= join->join_tab; root_range->start= join->join_tab;
/* root_range->end will be set later */ /* root_range->end will be set later */
...@@ -7057,7 +7056,6 @@ inline void add_cond_and_fix(Item **e1, Item *e2) ...@@ -7057,7 +7056,6 @@ inline void add_cond_and_fix(Item **e1, Item *e2)
} }
/** /**
Add to join_tab->select_cond[i] "table.field IS NOT NULL" conditions Add to join_tab->select_cond[i] "table.field IS NOT NULL" conditions
we've inferred from ref/eq_ref access performed. we've inferred from ref/eq_ref access performed.
......
...@@ -162,7 +162,7 @@ typedef enum_nested_loop_state ...@@ -162,7 +162,7 @@ typedef enum_nested_loop_state
RETURN RETURN
0 - OK 0 - OK
-1 - Record not found -1 - Record not found
Other - Error Other - A fatal error
*/ */
typedef int (*Read_record_func)(struct st_join_table *tab); typedef int (*Read_record_func)(struct st_join_table *tab);
...@@ -356,7 +356,7 @@ typedef struct st_join_table { ...@@ -356,7 +356,7 @@ typedef struct st_join_table {
fix_semijoin_strategies_for_picked_join_order. fix_semijoin_strategies_for_picked_join_order.
*/ */
uint sj_strategy; uint sj_strategy;
//psergey-merge: todo: stop using this: //psergey-merge: todo: stop using this:
struct st_join_table *first_sjm_sibling; struct st_join_table *first_sjm_sibling;
...@@ -446,7 +446,6 @@ typedef struct st_join_table { ...@@ -446,7 +446,6 @@ typedef struct st_join_table {
} }
void calc_used_field_length(bool max_fl); void calc_used_field_length(bool max_fl);
ulong get_used_fieldlength() ulong get_used_fieldlength()
{ {
if (!used_fieldlength) if (!used_fieldlength)
calc_used_field_length(FALSE); calc_used_field_length(FALSE);
......
...@@ -966,7 +966,7 @@ struct st_table { ...@@ -966,7 +966,7 @@ struct st_table {
key_read= 1; key_read= 1;
file->extra(HA_EXTRA_KEYREAD); file->extra(HA_EXTRA_KEYREAD);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/* /*
If TRUE, the table is filled at execution phase (and so, the optimizer If TRUE, the table is filled at execution phase (and so, the optimizer
should not do things like range analysis or constant table detection on should not do things like range analysis or constant table detection on
......
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