mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
Change cost for REF to take into account cost for 1 extra key read_next
The main difference in code path between EQ_REF and REF is that for REF we have to do an extra read_next on the index to check that there is no more matching rows. Before this patch we added a preference of EQ_REF by ensuring that REF would always estimate to find at least 2 rows. This patch adds the cost of the extra key read_next to REF access and removes the code that limited REF to at least 2 rows. For some queries this can have a big effect as the total estimated rows will be halved for each REF table with 1 rows. multi_range cost calculations are also changed to take into account the difference between EQ_REF and REF. The effect of the patch to the test suite: - About 80 test case changed - Almost all changes where for EXPLAIN where estimated rows for REF where changed from 2 to 1. - A few test cases using explain extended had a change of 'filtered'. This is because of the estimated rows are now closer to the calculated selectivity. - A very few test had a change of table order. This is because the change of estimated rows from 2 to 1 or the small cost change for REF (main.subselect_sj_jcl6, main.group_by, main.dervied_cond_pushdown, main.distinct, main.join_nested, main.order_by, main.join_cache) - No key statistics and the estimated rows are now smaller which cased estimated filtering to be lower. (main.subselect_sj_mat) - The number of total rows are halved. (main.derived_cond_pushdown) - Plans with 1 row changed to use RANGE instead of REF. (main.group_min_max) - ALL changed to REF (main.key_diff) - Key changed from ref + index_only to PRIMARY key for InnoDB, as OPTIMIZER_ROW_LOOKUP_COST + OPTIMIZER_ROW_NEXT_FIND_COST is smaller than OPTIMIZER_KEY_LOOKUP_COST + OPTIMIZER_KEY_NEXT_FIND_COST. (main.join_outer_innodb) - Cost changes printouts (main.opt_trace*) - Result order change (innodb_gis.rtree)
This commit is contained in:
@ -2407,7 +2407,7 @@ insert into t2 values (1,3), (2,3), (3,4), (4,4);
|
||||
explain select * from t1 left join t2 on a=c where d in (4);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ref c,d d 5 const 2 Using where
|
||||
1 SIMPLE t1 ref a a 5 test.t2.c 2
|
||||
1 SIMPLE t1 ref a a 5 test.t2.c 1
|
||||
select * from t1 left join t2 on a=c where d in (4);
|
||||
a b c d
|
||||
3 2 3 4
|
||||
@ -2415,7 +2415,7 @@ a b c d
|
||||
explain select * from t1 left join t2 on a=c where d = 4;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ref c,d d 5 const 2 Using where
|
||||
1 SIMPLE t1 ref a a 5 test.t2.c 2
|
||||
1 SIMPLE t1 ref a a 5 test.t2.c 1
|
||||
select * from t1 left join t2 on a=c where d = 4;
|
||||
a b c d
|
||||
3 2 3 4
|
||||
@ -2442,11 +2442,11 @@ INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
|
||||
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5
|
||||
1 SIMPLE t2 ref a a 23 test.t1.a 2 Using where
|
||||
1 SIMPLE t2 ref a a 23 test.t1.a 1 Using where
|
||||
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 FORCE INDEX (a) ON t1.a=t2.a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5
|
||||
1 SIMPLE t2 ref a a 23 test.t1.a 2 Using where
|
||||
1 SIMPLE t2 ref a a 23 test.t1.a 1 Using where
|
||||
DROP TABLE t1, t2;
|
||||
CREATE TABLE t1 ( city char(30) );
|
||||
INSERT INTO t1 VALUES ('London');
|
||||
@ -3926,7 +3926,7 @@ cc 3 7
|
||||
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5
|
||||
1 SIMPLE t2 ref name name 6 test.t1.name 2 Using where
|
||||
1 SIMPLE t2 ref name name 6 test.t1.name 1 Using where
|
||||
SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
|
||||
name name n
|
||||
ccc NULL NULL
|
||||
@ -4019,7 +4019,7 @@ cc 3 7
|
||||
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5
|
||||
1 SIMPLE t2 ref name name 6 test.t1.name 2 Using where
|
||||
1 SIMPLE t2 ref name name 6 test.t1.name 1 Using where
|
||||
SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
|
||||
name name n
|
||||
ccc NULL NULL
|
||||
|
Reference in New Issue
Block a user