2697 Sergey Petrunia 2008-10-02
WL#3985: Subqueries: smart choice between semi-join and materialization
- Review feedback: s/SJ_MATERIALIZE_INFO/SJ_MATERIALIZATION_INFO/
- Remove garbage comments.
modified:
sql/handler.h
sql/mysql_priv.h
sql/sql_class.h
sql/sql_select.cc
sql/sql_select.h
sql/sql_test.cc
sql/table.h
2696 Sergey Petrunia 2008-09-04
Forgot DBUG_RETURN(0)
modified:
sql/sql_select.cc
=== modified file 'sql/handler.h'
--- a/sql/handler.h 2008-08-28 17:20:02 +0000
+++ b/sql/handler.h 2008-10-01 22:17:03 +0000
@@ -1176,7 +1176,7 @@ public:
To be used when we go from old single value-based cost calculations to
the new COST_VECT-based.
*/
- void set_double(double cost)
+ void convert_from_cost(double cost)
{
zero();
avg_io_cost= 1.0;
=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h 2008-08-28 17:20:02 +0000
+++ b/sql/mysql_priv.h 2008-10-01 22:17:03 +0000
@@ -1860,7 +1860,7 @@ void TEST_filesort(SORT_FIELD *sortorder
void print_plan(JOIN* join,uint idx, double record_count, double read_time,
double current_read_time, const char *info);
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
-void print_sjm(SJ_MATERIALIZE_INFO *sjm);
+void print_sjm(SJ_MATERIALIZATION_INFO *sjm);
#define EXTRA_DEBUG_DUMP_TABLE_LISTS
#ifdef EXTRA_DEBUG_DUMP_TABLE_LISTS
void dump_TABLE_LIST_graph(SELECT_LEX *select_lex, TABLE_LIST* tl);
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2008-08-21 15:19:35 +0000
+++ b/sql/sql_class.h 2008-10-01 22:17:03 +0000
@@ -2790,9 +2790,9 @@ public:
struct st_table_ref;
/*
- Materialized semi-join info
+ Descriptor of a materialized semi-join.
*/
-class SJ_MATERIALIZE_INFO : public Sql_alloc
+class SJ_MATERIALIZATION_INFO : public Sql_alloc
{
public:
/* optimal join sub-order */
=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc 2008-09-03 21:03:29 +0000
+++ b/sql/sql_select.cc 2008-10-01 22:17:03 +0000
@@ -89,7 +89,7 @@ static bool find_best(JOIN *join,table_m
double record_count,double read_time);
static uint cache_record_length(JOIN *join,uint index);
static double prev_record_reads(JOIN *join, uint idx, table_map found_ref);
-static bool get_best_combination(JOIN *join, table_map join_tables);
+static bool get_best_combination(JOIN *join);
static store_key *get_store_key(THD *thd,
KEYUSE *keyuse, table_map used_tables,
KEY_PART_INFO *key_part, uchar *key_buff,
@@ -272,13 +272,6 @@ bool subquery_types_allow_materializatio
const char *subq_sj_cond_name=
"0123456789ABCDEF0123456789abcdef0123456789ABCDEF0123456789abcdef-sj-cond";
-#if 0
-static bool bitmap_covers(const table_map x, const table_map y)
-{
- return !test(y & ~x);
-}
-#endif
-
/**
This handles SELECT with and without UNION.
*/
@@ -1356,8 +1349,8 @@ static int clear_sj_tmp_tables(JOIN *joi
return res;
}
- SJ_MATERIALIZE_INFO *sjm;
- List_iterator<SJ_MATERIALIZE_INFO> it2(join->sjm_info_list);
+ SJ_MATERIALIZATION_INFO *sjm;
+ List_iterator<SJ_MATERIALIZATION_INFO> it2(join->sjm_info_list);
while ((sjm= it2++))
{
sjm->materialized= FALSE;
@@ -4354,9 +4347,7 @@ make_join_statistics(JOIN *join, TABLE_L
join->best_read=1.0;
}
/* Generate an execution plan from the found optimal join order. */
- DBUG_RETURN(join->thd->killed ||
- get_best_combination(join, all_table_map &
- ~join->const_table_map));
+ DBUG_RETURN(join->thd->killed || get_best_combination(join));
}
@@ -4381,8 +4372,8 @@ static bool optimize_semijoin_nests(JOIN
save it.
*/
uint n_tables= my_count_bits(sj_nest->sj_inner_tables);
- SJ_MATERIALIZE_INFO* sjm;
- if (!(sjm= new SJ_MATERIALIZE_INFO) ||
+ SJ_MATERIALIZATION_INFO* sjm;
+ if (!(sjm= new SJ_MATERIALIZATION_INFO) ||
!(sjm->positions= (POSITION*)join->thd->alloc(sizeof(POSITION)*
n_tables)))
DBUG_RETURN(TRUE);
@@ -4392,7 +4383,7 @@ static bool optimize_semijoin_nests(JOIN
get_partial_join_cost(join, n_tables,
&subjoin_read_time, &subjoin_out_rows);
- sjm->materialization_cost.set_double(subjoin_read_time);
+ sjm->materialization_cost.convert_from_cost(subjoin_read_time);
sjm->rows= subjoin_out_rows;
List<Item> &right_expr_list=
@@ -4459,7 +4450,7 @@ static bool optimize_semijoin_nests(JOIN
sjm->scan_cost.zero();
sjm->scan_cost.add_io(sjm->rows, 1.0);
}
- sjm->lookup_cost.set_double(lookup_cost);
+ sjm->lookup_cost.convert_from_cost(lookup_cost);
sj_nest->sj_mat_info= sjm;
DBUG_EXECUTE("opt", print_sjm(sjm););
}
@@ -6811,7 +6802,7 @@ optimize_straight_join(JOIN *join, table
FALSE No, some of the requirements are not met
*/
-SJ_MATERIALIZE_INFO *
+SJ_MATERIALIZATION_INFO *
at_sjmat_pos(const JOIN *join, table_map remaining_tables, const JOIN_TAB *tab,
uint idx, bool *insideout_scan)
{
@@ -7550,7 +7541,7 @@ prev_record_reads(JOIN *join, uint idx,
*/
static bool
-get_best_combination(JOIN *join, table_map join_tables)
+get_best_combination(JOIN *join)
{
uint i,tablenr;
table_map used_tables;
@@ -7572,7 +7563,7 @@ get_best_combination(JOIN *join, table_m
/*
Prepare semi-join processing info for plan refimenent stage:
*/
- table_map remaining_tables= 0;//join_tables;
+ table_map remaining_tables= 0;
table_map handled_tabs= 0;
for (tablenr= table_count - 1 ; tablenr != join->const_tables - 1; tablenr--)
{
@@ -7589,7 +7580,7 @@ get_best_combination(JOIN *join, table_m
if (pos->sj_strategy == SJ_OPT_MATERIALIZE)
{
- SJ_MATERIALIZE_INFO *sjm= s->emb_sj_nest->sj_mat_info;
+ SJ_MATERIALIZATION_INFO *sjm= s->emb_sj_nest->sj_mat_info;
sjm->is_used= TRUE;
sjm->is_sj_scan= FALSE;
memcpy(pos - sjm->n_tables + 1, sjm->positions,
@@ -7601,7 +7592,7 @@ get_best_combination(JOIN *join, table_m
else if (pos->sj_strategy == SJ_OPT_MATERIALIZE_SCAN)
{
POSITION *first_inner= join->best_positions + pos->sjm_scan_last_inner;
- SJ_MATERIALIZE_INFO *sjm= first_inner->table->emb_sj_nest->sj_mat_info;
+ SJ_MATERIALIZATION_INFO *sjm= first_inner->table->emb_sj_nest->sj_mat_info;
sjm->is_used= TRUE;
sjm->is_sj_scan= TRUE;
first= pos->sjm_scan_last_inner - sjm->n_tables + 1;
@@ -9111,7 +9102,7 @@ end_sj_materialize(JOIN *join, JOIN_TAB
{
int error;
THD *thd= join->thd;
- SJ_MATERIALIZE_INFO *sjm= join_tab[-1].emb_sj_nest->sj_mat_info;
+ SJ_MATERIALIZATION_INFO *sjm= join_tab[-1].emb_sj_nest->sj_mat_info;
DBUG_ENTER("end_sj_materialize");
if (!end_of_records)
{
@@ -9176,7 +9167,7 @@ void remove_sj_conds(Item **tree)
*/
-Item *create_subq_in_equalities(THD *thd, SJ_MATERIALIZE_INFO *sjm,
+Item *create_subq_in_equalities(THD *thd, SJ_MATERIALIZATION_INFO *sjm,
Item_in_subselect *subq_pred)
{
//SELECT_LEX *subq_lex= subq_pred->unit->first_select();
@@ -9219,7 +9210,7 @@ bool setup_sj_materialization(JOIN_TAB *
uint i;
DBUG_ENTER("setup_sj_materialization");
TABLE_LIST *emb_sj_nest= tab->table->pos_in_table_list->embedding;
- SJ_MATERIALIZE_INFO *sjm= emb_sj_nest->sj_mat_info;
+ SJ_MATERIALIZATION_INFO *sjm= emb_sj_nest->sj_mat_info;
THD *thd= tab->join->thd;
/* First the calls come to the materialization function */
List<Item> &item_list= emb_sj_nest->sj_subq_pred->unit->first_select()->item_list;
@@ -12095,7 +12086,7 @@ void advance_sj_state(JOIN *join, table_
POSITION *pos= join->positions + idx;
remaining_tables &= ~s->table->map;
- pos->prefix_cost.set_double(*current_read_time);
+ pos->prefix_cost.convert_from_cost(*current_read_time);
pos->prefix_record_count= *current_record_count;
pos->sj_strategy= SJ_OPT_NONE;
@@ -12269,7 +12260,7 @@ void advance_sj_state(JOIN *join, table_
/* 4. SJ-Materialization and SJ-Materialization-scan strategy handler */
bool sjm_scan;
- SJ_MATERIALIZE_INFO *mat_info;
+ SJ_MATERIALIZATION_INFO *mat_info;
if ((mat_info= at_sjmat_pos(join, remaining_tables, s, idx, &sjm_scan)))
{
if (sjm_scan)
@@ -12341,7 +12332,7 @@ void advance_sj_state(JOIN *join, table_
{
TABLE_LIST *mat_nest=
join->positions[pos->sjm_scan_last_inner].table->emb_sj_nest;
- SJ_MATERIALIZE_INFO *mat_info= mat_nest->sj_mat_info;
+ SJ_MATERIALIZATION_INFO *mat_info= mat_nest->sj_mat_info;
double prefix_cost;
double prefix_rec_count;
@@ -15143,7 +15134,7 @@ sub_select_sjm(JOIN *join,JOIN_TAB *join
if (end_of_records)
return (*join_tab->next_select)(join, join_tab + 1, end_of_records);
- SJ_MATERIALIZE_INFO *sjm= join_tab->emb_sj_nest->sj_mat_info;
+ SJ_MATERIALIZATION_INFO *sjm= join_tab->emb_sj_nest->sj_mat_info;
if (!sjm->materialized)
{
/*
=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h 2008-08-28 17:20:02 +0000
+++ b/sql/sql_select.h 2008-10-01 22:17:03 +0000
@@ -649,7 +649,7 @@ public:
/* Temporary tables used to weed-out semi-join duplicates */
List<TABLE> sj_tmp_tables;
- List<SJ_MATERIALIZE_INFO> sjm_info_list;
+ List<SJ_MATERIALIZATION_INFO> sjm_info_list;
/*
storage for caching buffers allocated during query execution.
=== modified file 'sql/sql_test.cc'
--- a/sql/sql_test.cc 2008-07-26 19:37:13 +0000
+++ b/sql/sql_test.cc 2008-10-01 22:17:03 +0000
@@ -359,7 +359,7 @@ print_plan(JOIN* join, uint idx, double
#ifndef DBUG_OFF
-void print_sjm(SJ_MATERIALIZE_INFO *sjm)
+void print_sjm(SJ_MATERIALIZATION_INFO *sjm)
{
DBUG_LOCK_FILE;
fprintf(DBUG_FILE, "\nsemi-join nest{\n");
=== modified file 'sql/table.h'
--- a/sql/table.h 2008-08-21 15:19:35 +0000
+++ b/sql/table.h 2008-10-01 22:17:03 +0000
@@ -1001,7 +1001,7 @@ public:
};
-class SJ_MATERIALIZE_INFO;
+class SJ_MATERIALIZATION_INFO;
class Index_hint;
class Item_in_subselect;
@@ -1086,7 +1086,7 @@ struct TABLE_LIST
/* Number of IN-compared expressions */
uint sj_in_exprs;
Item_in_subselect *sj_subq_pred;
- SJ_MATERIALIZE_INFO *sj_mat_info;
+ SJ_MATERIALIZATION_INFO *sj_mat_info;
/*
The structure of ON expression presented in the member above
@@ -1451,7 +1451,7 @@ private:
struct st_position;
-class SJ_MATERIALIZE_INFO;
+class SJ_MATERIALIZATION_INFO;
class Item;
| Thread |
|---|
| • bzr push into mysql-6.0-opt-subqueries branch (sergefp:2696 to 2697)WL#3985 | Sergey Petrunia | 2 Oct |