mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fixed some issues with FORCE INDEX
Added code to support that force index can be used to force an index scan instead of a full table scan. Currently this code is disable but I added a test to verify that things works if the code is ever enabled. Other things: - FORCE INDEX will now work with "Range checked for each record" and join cache (see main/type_time_6065) - Removed code ifdef with BAD_OPTIMIZATION (New cost calculations should fix this). - Removed TABLE_LIST->force_index and comment that it should be removed - Added TABLE->force_index_join and use in the corresponding places. This means that FORCE INDEX FOR ORDER BY will not affect keys used in joins anymore. Remove TODO that the above should be added. I still kept TABLE->force_index as it's used in test_if_cheaper_ordering() and opt_range.cc - Removed setting table->force_index when calling test_quick_select() as it's not needed (force_index is an argument to test_quick_select())
This commit is contained in:
committed by
Sergei Petrunia
parent
013ba37ae2
commit
33fc8037e0
@ -643,7 +643,7 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 index NULL a 5 NULL 6
|
||||
SHOW STATUS LIKE 'Last_query_cost';
|
||||
Variable_name Value
|
||||
Last_query_cost 11.003515
|
||||
Last_query_cost 8.506592
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# MDEV-21480: Unique key using ref access though eq_ref access can be used
|
||||
@ -692,3 +692,42 @@ drop table t1,t2;
|
||||
#
|
||||
create table t1 (a int, b int, key(a), key(a desc));
|
||||
drop table t1;
|
||||
# Check some issues with FORCE INDEX and full index scans
|
||||
# (Does FORCE INDEX force an index scan)
|
||||
#
|
||||
create table t1 (a int primary key, b int, c int, d int,
|
||||
key k1 (b) using BTREE, key k2 (c,d) using btree) engine=heap;
|
||||
insert into t1 select seq as a, seq as b, seq as c, seq as d
|
||||
from seq_1_to_100;
|
||||
explain select sum(a+b) from t1 force index (k1) where b>0 and a=99;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range k1 k1 5 NULL 100 Using where
|
||||
explain select sum(a+b) from t1 force index (k1) where a>0;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 Using where
|
||||
explain select sum(a+b) from t1 force index (k1);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 100
|
||||
explain select sum(a+b) from t1 force index for join (k1);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 100
|
||||
explain select sum(a+b) from t1 force index for order by (k1);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 100
|
||||
explain select sum(a+b) from t1 force index (k1,k2);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 100
|
||||
select sum(a+b) from t1 force index (k1);
|
||||
sum(a+b)
|
||||
10100
|
||||
explain select sum(a+b) from t1 force index (primary);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 100
|
||||
select sum(a+b) from t1 force index (primary);
|
||||
sum(a+b)
|
||||
10100
|
||||
explain select straight_join sum(a+b) from seq_1_to_10 as s, t1 force index (k2) where t1.a=s.seq;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE s index PRIMARY PRIMARY 8 NULL 10 Using index
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 100 Using where; Using join buffer (flat, BNL join)
|
||||
drop table t1;
|
||||
|
Reference in New Issue
Block a user