mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-3858 Change JOIN_TAB::records_read from ha_rows to double
Currently JOIN_TAB::records_read is of type ha_rows. This is an integer type, which prevents proper selectivity and rows estimates.
This commit is contained in:
@@ -94,7 +94,7 @@ a1 a2
|
||||
explain extended
|
||||
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t2i index it2i1,it2i3 it2i1 # NULL 5 40.00 Using where; Using index; LooseScan
|
||||
1 PRIMARY t2i index it2i1,it2i3 it2i1 # NULL 5 50.00 Using where; Using index; LooseScan
|
||||
1 PRIMARY t1i ref _it1_idx _it1_idx # _ref_ 1 100.00
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where ((`test`.`t1i`.`a1` = `test`.`t2i`.`b1`) and (`test`.`t2i`.`b1` > '0'))
|
||||
@@ -117,7 +117,7 @@ a1 a2
|
||||
explain extended
|
||||
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t2i index it2i1,it2i2,it2i3 it2i3 # NULL 5 40.00 Using where; Using index; LooseScan
|
||||
1 PRIMARY t2i index it2i1,it2i2,it2i3 it2i3 # NULL 5 50.00 Using where; Using index; LooseScan
|
||||
1 PRIMARY t1i ref _it1_idx _it1_idx # _ref_ 1 100.00
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where ((`test`.`t1i`.`a2` = `test`.`t2i`.`b2`) and (`test`.`t1i`.`a1` = `test`.`t2i`.`b1`) and (`test`.`t2i`.`b1` > '0'))
|
||||
@@ -319,7 +319,7 @@ where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
|
||||
(a1, a2) in (select c1, c2 from t3i
|
||||
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t2i index it2i1,it2i2,it2i3 # # # 5 40.00 #
|
||||
1 PRIMARY t2i index it2i1,it2i2,it2i3 # # # 5 50.00 #
|
||||
1 PRIMARY t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 #
|
||||
1 PRIMARY t3i ref it3i1,it3i2,it3i3 # # # 1 100.00 #
|
||||
1 PRIMARY t2i ref it2i1,it2i2,it2i3 # # # 2 100.00 #
|
||||
@@ -407,7 +407,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
2 MATERIALIZED t2 ALL NULL # # # 5 100.00 #
|
||||
4 MATERIALIZED t3 ALL NULL # # # 4 100.00 #
|
||||
3 MATERIALIZED t3 ALL NULL # # # 4 100.00 #
|
||||
7 UNION t2i index it2i1,it2i2,it2i3 # # # 5 40.00 #
|
||||
7 UNION t2i index it2i1,it2i2,it2i3 # # # 5 50.00 #
|
||||
7 UNION t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 #
|
||||
7 UNION t3i ref it3i1,it3i2,it3i3 # # # 1 100.00 #
|
||||
7 UNION t2i ref it2i1,it2i2,it2i3 # # # 2 100.00 #
|
||||
|
@@ -4553,7 +4553,7 @@ double get_fanout_with_deps(JOIN *join, table_map tset)
|
||||
!tab->emb_sj_nest &&
|
||||
tab->records_read != 0)
|
||||
{
|
||||
fanout *= rows2double(tab->records_read);
|
||||
fanout *= tab->records_read;
|
||||
}
|
||||
}
|
||||
return fanout;
|
||||
|
@@ -6789,7 +6789,7 @@ void JOIN::get_prefix_cost_and_fanout(uint n_tables,
|
||||
|
||||
double JOIN::get_examined_rows()
|
||||
{
|
||||
ha_rows examined_rows;
|
||||
double examined_rows;
|
||||
double prev_fanout= 1;
|
||||
JOIN_TAB *tab= first_breadth_first_tab(this, WALK_OPTIMIZATION_TABS);
|
||||
JOIN_TAB *prev_tab= tab;
|
||||
@@ -6799,7 +6799,7 @@ double JOIN::get_examined_rows()
|
||||
while ((tab= next_breadth_first_tab(this, WALK_OPTIMIZATION_TABS, tab)))
|
||||
{
|
||||
prev_fanout *= prev_tab->records_read;
|
||||
examined_rows+= (ha_rows) (tab->get_examined_rows() * prev_fanout);
|
||||
examined_rows+= tab->get_examined_rows() * prev_fanout;
|
||||
prev_tab= tab;
|
||||
}
|
||||
return examined_rows;
|
||||
@@ -7704,7 +7704,8 @@ get_best_combination(JOIN *join)
|
||||
sub-order
|
||||
*/
|
||||
SJ_MATERIALIZATION_INFO *sjm= cur_pos->table->emb_sj_nest->sj_mat_info;
|
||||
j->records= j->records_read= (ha_rows)(sjm->is_sj_scan? sjm->rows : 1);
|
||||
j->records_read= sjm->is_sj_scan? sjm->rows : 1;
|
||||
j->records= (ha_rows) j->records_read;
|
||||
JOIN_TAB *jt;
|
||||
JOIN_TAB_RANGE *jt_range;
|
||||
if (!(jt= (JOIN_TAB*)join->thd->alloc(sizeof(JOIN_TAB)*sjm->tables)) ||
|
||||
@@ -7766,7 +7767,7 @@ get_best_combination(JOIN *join)
|
||||
Save records_read in JOIN_TAB so that select_describe()/etc don't have
|
||||
to access join->best_positions[].
|
||||
*/
|
||||
j->records_read= (ha_rows)join->best_positions[tablenr].records_read;
|
||||
j->records_read= join->best_positions[tablenr].records_read;
|
||||
join->map2table[j->table->tablenr]= j;
|
||||
|
||||
/* If we've reached the end of sjm nest, switch back to main sequence */
|
||||
@@ -10460,7 +10461,7 @@ double JOIN_TAB::scan_time()
|
||||
|
||||
ha_rows JOIN_TAB::get_examined_rows()
|
||||
{
|
||||
ha_rows examined_rows;
|
||||
double examined_rows;
|
||||
|
||||
if (select && select->quick && use_quick != 2)
|
||||
examined_rows= select->quick->records;
|
||||
@@ -10490,7 +10491,7 @@ ha_rows JOIN_TAB::get_examined_rows()
|
||||
}
|
||||
}
|
||||
else
|
||||
examined_rows= (ha_rows) records_read;
|
||||
examined_rows= records_read;
|
||||
|
||||
return examined_rows;
|
||||
}
|
||||
@@ -21972,7 +21973,7 @@ int JOIN::print_explain(select_result_sink *result, uint8 explain_flags,
|
||||
}
|
||||
else
|
||||
{
|
||||
ha_rows examined_rows= tab->get_examined_rows();
|
||||
double examined_rows= tab->get_examined_rows();
|
||||
|
||||
item_list.push_back(new Item_int((longlong) (ulonglong) examined_rows,
|
||||
MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
@@ -21982,7 +21983,7 @@ int JOIN::print_explain(select_result_sink *result, uint8 explain_flags,
|
||||
{
|
||||
float f= 0.0;
|
||||
if (examined_rows)
|
||||
f= (float) (100.0 * tab->records_read / examined_rows);
|
||||
f= (100.0 * (float)tab->records_read) / examined_rows;
|
||||
set_if_smaller(f, 100.0);
|
||||
item_list.push_back(new Item_float(f, 2));
|
||||
}
|
||||
|
@@ -280,8 +280,8 @@ typedef struct st_join_table {
|
||||
*/
|
||||
double read_time;
|
||||
|
||||
/* psergey-todo: make the below have type double, like POSITION::records_read? */
|
||||
ha_rows records_read;
|
||||
/* Copy of POSITION::records_read, set by get_best_combination() */
|
||||
double records_read;
|
||||
|
||||
/* Startup cost for execution */
|
||||
double startup_cost;
|
||||
|
Reference in New Issue
Block a user