Skip to content

Commit

Permalink
Fixes for 'Filtering'
Browse files Browse the repository at this point in the history
- table_after_join_selectivity() should use records_init (new bug)
- get_examined_rows() changed to double to get similar results
  as in MariaDB 10.11
- Fixed bug where table_after_join_selectivity() did not correct
  selectivity in the case where a RANGE is used instead of a REF.
  This can happen if the range can use more key_parts than the REF.
  WHERE key_part1=10 and key_part2 < 10

Other things:
- Use JT_RANGE instead of JT_ALL for RANGE access in all parts of the code.
  Before we used JT_ALL for RANGE.
- Force RANGE be used in best_access_path() if the range used more key
  parts than ref. In the original code, this was done much later in
  make_join_select)(). However we need to know in
  table_after_join_selectivity() if we have used RANGE or not.
- Added more information about filtering to optimizer_trace.
  • Loading branch information
montywi authored and spetrunia committed Feb 2, 2023
1 parent 4464aa4 commit 66d9c1b
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 52 deletions.
12 changes: 12 additions & 0 deletions mysql-test/main/selectivity.result
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,18 @@ b a a b
7 7 8 8
8 8 9 9
9 9 10 10
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
explain extended select t1.b,t2.a,t3.a,t3.b from t1,t2,t3
where t1.c = t2.a AND t1.d = t3.a and t1.a = 50 and t1.b <= 100;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a a 10 NULL 9 100.00 Using index condition; Using where
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 100.00 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.d 1 100.00
Warnings:
Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t1`.`c` and `test`.`t3`.`a` = `test`.`t1`.`d` and `test`.`t1`.`a` = 50 and `test`.`t1`.`b` <= 100
set optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
drop table t1,t2,t3;
#
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/main/selectivity.test
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,8 @@ eval $query;
set optimizer_use_condition_selectivity=2;
eval explain extended $query;
eval $query;
analyze table t1;
eval explain extended $query;
set optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;

drop table t1,t2,t3;
Expand Down
1 change: 1 addition & 0 deletions sql/opt_subselect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4149,6 +4149,7 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join)
*/
if (join->best_positions[idx].key)
{
DBUG_ASSERT(join->best_positions[idx].type != JT_RANGE);
delete join->best_positions[idx].table->quick;
join->best_positions[idx].table->quick= NULL;
}
Expand Down
Loading

0 comments on commit 66d9c1b

Please sign in to comment.