Commit e9bac8db authored by Sergey Petrunya's avatar Sergey Petrunya

MWL#90, code cleanup

- Remove garbage comments
- fix a bug in join_tab_cmp
parent 03904127
...@@ -1398,7 +1398,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -1398,7 +1398,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 SUBQUERY cona ALL NULL NULL NULL NULL 2 100.00 Using where 2 SUBQUERY cona ALL NULL NULL NULL NULL 2 100.00 Using where
2 SUBQUERY c eq_ref PRIMARY PRIMARY 4 test.cona.idContact 1 100.00 2 SUBQUERY c eq_ref PRIMARY PRIMARY 4 test.cona.idContact 1 100.00
Warnings: Warnings:
Note 1003 select `test`.`a`.`idIndividual` AS `idIndividual` from `test`.`t1` `a` semi join (`test`.`t3` `cona` join `test`.`t2` `c`) where ((`test`.`cona`.`idContact` = `test`.`c`.`idContact`) and (`test`.`a`.`idIndividual` = `test`.`c`.`idObj`) and (`test`.`cona`.`postalStripped` = 'T2H3B2')) Note 1003 select `test`.`a`.`idIndividual` AS `idIndividual` from `test`.`t1` `a` semi join (`test`.`t3` `cona` join `test`.`t2` `c`) where ((`test`.`c`.`idContact` = `test`.`cona`.`idContact`) and (`test`.`a`.`idIndividual` = `test`.`c`.`idObj`) and (`test`.`cona`.`postalStripped` = 'T2H3B2'))
drop table t1,t2,t3; drop table t1,t2,t3;
# #
# BUG#47367 Crash in Name_resolution_context::process_error # BUG#47367 Crash in Name_resolution_context::process_error
......
...@@ -1402,7 +1402,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -1402,7 +1402,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 SUBQUERY cona ALL NULL NULL NULL NULL 2 100.00 Using where 2 SUBQUERY cona ALL NULL NULL NULL NULL 2 100.00 Using where
2 SUBQUERY c eq_ref PRIMARY PRIMARY 4 test.cona.idContact 1 100.00 Using join buffer 2 SUBQUERY c eq_ref PRIMARY PRIMARY 4 test.cona.idContact 1 100.00 Using join buffer
Warnings: Warnings:
Note 1003 select `test`.`a`.`idIndividual` AS `idIndividual` from `test`.`t1` `a` semi join (`test`.`t3` `cona` join `test`.`t2` `c`) where ((`test`.`cona`.`idContact` = `test`.`c`.`idContact`) and (`test`.`a`.`idIndividual` = `test`.`c`.`idObj`) and (`test`.`cona`.`postalStripped` = 'T2H3B2')) Note 1003 select `test`.`a`.`idIndividual` AS `idIndividual` from `test`.`t1` `a` semi join (`test`.`t3` `cona` join `test`.`t2` `c`) where ((`test`.`c`.`idContact` = `test`.`cona`.`idContact`) and (`test`.`a`.`idIndividual` = `test`.`c`.`idObj`) and (`test`.`cona`.`postalStripped` = 'T2H3B2'))
drop table t1,t2,t3; drop table t1,t2,t3;
# #
# BUG#47367 Crash in Name_resolution_context::process_error # BUG#47367 Crash in Name_resolution_context::process_error
......
...@@ -312,7 +312,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -312,7 +312,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 SUBQUERY t2i index it2i1,it2i2,it2i3 # # # 5 100.00 # 3 SUBQUERY t2i index it2i1,it2i2,it2i3 # # # 5 100.00 #
3 SUBQUERY t3i index it3i1,it3i2,it3i3 # # # 4 75.00 # 3 SUBQUERY t3i index it3i1,it3i2,it3i3 # # # 4 75.00 #
Warnings: Warnings:
Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where ((`test`.`t2i`.`b2` = `test`.`t3i`.`c2`) and (`test`.`t2i`.`b1` = `test`.`t3i`.`c1`) and (`test`.`t2i`.`b1` > '0') and (`test`.`t3i`.`c2` > '0')) Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where ((`test`.`t3i`.`c2` = `test`.`t2i`.`b2`) and (`test`.`t3i`.`c1` = `test`.`t2i`.`b1`) and (`test`.`t2i`.`b1` > '0') and (`test`.`t2i`.`b2` > '0'))
select * from t1i select * from t1i
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
(a1, a2) in (select c1, c2 from t3i (a1, a2) in (select c1, c2 from t3i
...@@ -402,7 +402,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -402,7 +402,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
9 SUBQUERY t3i index it3i1,it3i2,it3i3 # # # 4 75.00 # 9 SUBQUERY t3i index it3i1,it3i2,it3i3 # # # 4 75.00 #
NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL # NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL #
Warnings: Warnings:
Note 1003 (select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery3>`.`c2`))))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))) group by `test`.`t2`.`b1`,`test`.`t2`.`b2`) semi join (`test`.`t2i` join `test`.`t3`) join `test`.`t1` where ((`test`.`t3`.`c2` = `<subquery2>`.`b2`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`) and (`test`.`t2i`.`b2` = `<subquery2>`.`b2`) and (`test`.`t3`.`c1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t2i`.`b1` = `<subquery2>`.`b1`) and (`<subquery2>`.`b2` > '0'))) union (select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where ((`test`.`t2i`.`b2` = `test`.`t3i`.`c2`) and (`test`.`t2i`.`b1` = `test`.`t3i`.`c1`) and (`test`.`t2i`.`b1` > '0') and (`test`.`t3i`.`c2` > '0'))) Note 1003 (select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery3>`.`c2`))))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))) group by `test`.`t2`.`b1`,`test`.`t2`.`b2`) semi join (`test`.`t2i` join `test`.`t3`) join `test`.`t1` where ((`test`.`t3`.`c2` = `<subquery2>`.`b2`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`) and (`test`.`t2i`.`b2` = `<subquery2>`.`b2`) and (`test`.`t3`.`c1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t2i`.`b1` = `<subquery2>`.`b1`) and (`<subquery2>`.`b2` > '0'))) union (select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where ((`test`.`t3i`.`c2` = `test`.`t2i`.`b2`) and (`test`.`t3i`.`c1` = `test`.`t2i`.`b1`) and (`test`.`t2i`.`b1` > '0') and (`test`.`t2i`.`b2` > '0')))
(select * from t1 (select * from t1
where (a1, a2) in (select b1, b2 from t2 where (a1, a2) in (select b1, b2 from t2
where b2 in (select c2 from t3 where c2 LIKE '%02') or where b2 in (select c2 from t3 where c2 LIKE '%02') or
......
...@@ -384,14 +384,7 @@ class Item_in_subselect :public Item_exists_subselect ...@@ -384,14 +384,7 @@ class Item_in_subselect :public Item_exists_subselect
enum_exec_method exec_method; enum_exec_method exec_method;
/* /*
JTBM: temporary measure to tell JTBM predicates from SJ predicates TRUE<=>this is a flattenable semi-join, false overwise.
psergey-jtbm-todo: can't we do without this?
- either remove it altogether
- or put into enum_exec_method
We can't remove it altogether as it is used to classify contents in
join->sj_subselects.
jtbm-todo: option 1: let sj_subselects list pairs.
*/ */
bool is_flattenable_semijoin; bool is_flattenable_semijoin;
......
...@@ -2663,7 +2663,7 @@ bool setup_sj_materialization(JOIN_TAB *sjm_tab) ...@@ -2663,7 +2663,7 @@ bool setup_sj_materialization(JOIN_TAB *sjm_tab)
DBUG_RETURN(TRUE); /* purecov: inspected */ DBUG_RETURN(TRUE); /* purecov: inspected */
sjm->table->file->extra(HA_EXTRA_WRITE_CACHE); sjm->table->file->extra(HA_EXTRA_WRITE_CACHE);
sjm->table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); sjm->table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
//psergey2-todo: need this or can take advantage of re-init functionality?
tab->join->sj_tmp_tables.push_back(sjm->table); tab->join->sj_tmp_tables.push_back(sjm->table);
tab->join->sjm_info_list.push_back(sjm); tab->join->sjm_info_list.push_back(sjm);
......
...@@ -2112,7 +2112,7 @@ JOIN::exec() ...@@ -2112,7 +2112,7 @@ JOIN::exec()
WHERE clause for any tables after the sorted one. WHERE clause for any tables after the sorted one.
*/ */
JOIN_TAB *curr_table= &curr_join->join_tab[curr_join->const_tables+1]; JOIN_TAB *curr_table= &curr_join->join_tab[curr_join->const_tables+1];
JOIN_TAB *end_table= &curr_join->join_tab[curr_join->tables]; //psergey2-todo: check this! JOIN_TAB *end_table= &curr_join->join_tab[curr_join->top_jtrange_tables];
for (; curr_table < end_table ; curr_table++) for (; curr_table < end_table ; curr_table++)
{ {
/* /*
...@@ -5750,8 +5750,8 @@ void calc_used_field_length(THD *thd, JOIN_TAB *join_tab) ...@@ -5750,8 +5750,8 @@ void calc_used_field_length(THD *thd, JOIN_TAB *join_tab)
rec_length+=(uint) max(4,blob_length); rec_length+=(uint) max(4,blob_length);
} }
/* /*
psergey-todo: why we don't count here rowid that we might need to store TODO: why we don't count here rowid that we might need to store when
when using DuplicateElimination? using DuplicateElimination?
*/ */
join_tab->used_fields=fields; join_tab->used_fields=fields;
join_tab->used_fieldlength=rec_length; join_tab->used_fieldlength=rec_length;
...@@ -6628,8 +6628,12 @@ make_outerjoin_info(JOIN *join) ...@@ -6628,8 +6628,12 @@ make_outerjoin_info(JOIN *join)
tab != jt_range->end; tab++) tab != jt_range->end; tab++)
{ {
TABLE *table=tab->table; TABLE *table=tab->table;
/*
psergey: The following is probably incorrect, fix it when we get
semi+outer joins processing to work:
*/
if (!table) if (!table)
continue; //psergey2: fix this when we get SJM+outer joins really working. continue;
TABLE_LIST *tbl= table->pos_in_table_list; TABLE_LIST *tbl= table->pos_in_table_list;
TABLE_LIST *embedding= tbl->embedding; TABLE_LIST *embedding= tbl->embedding;
...@@ -6766,15 +6770,13 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -6766,15 +6770,13 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
uint i= join->const_tables; uint i= join->const_tables;
for (tab= next_depth_first_tab(join, NULL); tab; for (tab= next_depth_first_tab(join, NULL); tab;
tab= next_depth_first_tab(join, tab), i++) tab= next_depth_first_tab(join, tab), i++)
//for (uint i=join->const_tables ; i < join->tables ; i++)
{ {
//tab= join->join_tab+i;
/* /*
first_inner is the X in queries like: first_inner is the X in queries like:
SELECT * FROM t1 LEFT OUTER JOIN (t2 JOIN t3) ON X SELECT * FROM t1 LEFT OUTER JOIN (t2 JOIN t3) ON X
*/ */
JOIN_TAB *first_inner_tab= tab->first_inner; JOIN_TAB *first_inner_tab= tab->first_inner;
//psergey2-todo: change this to table bitmap.
if (tab->table) if (tab->table)
current_map= tab->table->map; current_map= tab->table->map;
else else
...@@ -7051,8 +7053,6 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -7051,8 +7053,6 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
*/ */
/* First push down constant conditions from on expressions */ /* First push down constant conditions from on expressions */
//for (JOIN_TAB *join_tab= join->join_tab+join->const_tables;
// join_tab < join->join_tab+join->tables ; join_tab++)
for (JOIN_TAB *join_tab= first_linear_tab(join, TRUE); for (JOIN_TAB *join_tab= first_linear_tab(join, TRUE);
join_tab; join_tab;
join_tab= next_linear_tab(join, join_tab, FALSE)) join_tab= next_linear_tab(join, join_tab, FALSE))
...@@ -7098,7 +7098,10 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -7098,7 +7098,10 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
{ {
if (!tab->table) if (!tab->table)
{ {
//psergey3-todo: this is probably incorrect: /*
psergey-todo: this is probably incorrect, fix this when we get
correct processing for outer joins + semi joins
*/
continue; continue;
} }
current_map= tab->table->map; current_map= tab->table->map;
...@@ -7503,10 +7506,7 @@ uint check_join_cache_usage(JOIN_TAB *tab, ...@@ -7503,10 +7506,7 @@ uint check_join_cache_usage(JOIN_TAB *tab,
if (options & SELECT_NO_JOIN_CACHE) if (options & SELECT_NO_JOIN_CACHE)
goto no_join_cache; goto no_join_cache;
/*
psergey-todo: why the below when execution code seems to handle the
"range checked for each record" case?
*/
if (tab->use_quick == 2) if (tab->use_quick == 2)
goto no_join_cache; goto no_join_cache;
/* /*
...@@ -7937,7 +7937,6 @@ void JOIN_TAB::cleanup() ...@@ -7937,7 +7937,6 @@ void JOIN_TAB::cleanup()
select= 0; select= 0;
delete quick; delete quick;
quick= 0; quick= 0;
//psergey3-todo: empty merged SJM temptables here.
if (cache) if (cache)
{ {
cache->free(); cache->free();
...@@ -8455,7 +8454,6 @@ static void clear_tables(JOIN *join) ...@@ -8455,7 +8454,6 @@ static void clear_tables(JOIN *join)
must clear only the non-const tables, as const tables must clear only the non-const tables, as const tables
are not re-calculated. are not re-calculated.
*/ */
// psergey2: What is this for? perhaps, we should reset the SJM temptables, too??
for (uint i= 0 ; i < join->tables ; i++) for (uint i= 0 ; i < join->tables ; i++)
{ {
if (!(join->table[i]->map & join->const_table_map)) if (!(join->table[i]->map & join->const_table_map))
...@@ -9282,16 +9280,20 @@ static int compare_fields_by_table_order(Item_field *field1, ...@@ -9282,16 +9280,20 @@ static int compare_fields_by_table_order(Item_field *field1,
JOIN_TAB **idx= (JOIN_TAB **) table_join_idx; JOIN_TAB **idx= (JOIN_TAB **) table_join_idx;
JOIN_TAB *tab1= idx[field1->field->table->tablenr]; JOIN_TAB *tab1= idx[field1->field->table->tablenr];
JOIN_TAB *tab2= idx[field2->field->table->tablenr];
/* /*
if a table is inside a merged sjm nest, then it compares as its join-bush if one of the table is inside a merged SJM nest and another one isn't,
psergey-5-todo: compare fairly! compare SJM bush roots of the tables.
*/ */
if (tab1->bush_root_tab) if (tab1->bush_root_tab != tab2->bush_root_tab)
tab1= tab1->bush_root_tab; {
if (tab1->bush_root_tab)
tab1= tab1->bush_root_tab;
JOIN_TAB *tab2= idx[field2->field->table->tablenr]; if (tab2->bush_root_tab)
if (tab2->bush_root_tab) tab2= tab2->bush_root_tab;
tab2= tab2->bush_root_tab; }
cmp= tab2 - tab1; cmp= tab2 - tab1;
......
...@@ -187,11 +187,11 @@ typedef struct st_join_table { ...@@ -187,11 +187,11 @@ typedef struct st_join_table {
st_join_table *first_unmatched; /**< used for optimization purposes only */ st_join_table *first_unmatched; /**< used for optimization purposes only */
/* /*
psergey2: for join tabs that are inside a bush: root of this bush. For join tabs that are inside an SJM bush: root of the bush
*/ */
st_join_table *bush_root_tab; st_join_table *bush_root_tab;
/* TRUE <=> This join_tab is inside a join bush and is the last leaf tab here */ /* TRUE <=> This join_tab is inside an SJM bush and is the last leaf tab here */
bool last_leaf_in_bush; bool last_leaf_in_bush;
/* /*
......
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