Skip to content

Commit fe1f4ca

Browse files
committed
MDEV-30486 Table is not eliminated in bb-11.0
Some tables where not eliminated when they could have been. This was caused because HA_KEYREAD_ONLY is not set anymore for InnoDB clustered index and the elimination code was depending on field->part_of_key_not_clustered which was not set if HA_KEYREAD_ONLY is not present. Fixed by moving out field->part_of_key and field->part_of_key_not_clustered from under HA_KEYREAD_ONLY (which they should never have been part of). Other things: - Fixed a bug in make_join_select() that caused range to be used when there where elminiated or constant tables present (Caused wrong change of plans in join_outer_innodb.test). This also affected show_explain.test and subselct_sj_mat.test where wrong 'range's where replaced with index scans. Reviewer: Sergei Petrunia <sergey@mariadb.com>
1 parent 01c8217 commit fe1f4ca

File tree

7 files changed

+31
-10
lines changed

7 files changed

+31
-10
lines changed

mysql-test/main/join_outer_innodb.result

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ id select_type table type possible_keys key key_len ref rows Extra
442442
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1
443443
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where
444444
1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where
445-
1 SIMPLE e2 eq_ref PRIMARY PRIMARY 4 test.t6.f1 1 Using where
446445
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1
447446
1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1
448447
1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where
@@ -465,7 +464,6 @@ id select_type table type possible_keys key key_len ref rows Extra
465464
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1
466465
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where
467466
1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where
468-
1 SIMPLE e2 eq_ref PRIMARY PRIMARY 4 test.t6.f1 1 Using where
469467
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1
470468
1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1
471469
1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where

mysql-test/main/range_aria_dbt3.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ id select_type table type possible_keys key key_len ref rows Extra
1919
SELECT COUNT(*) FROM lineitem WHERE l_orderkey BETWEEN 111 AND 262 OR ( l_orderkey BETWEEN 152 AND 672 AND l_linenumber BETWEEN 4 AND 9 );
2020
COUNT(*)
2121
293
22+
#
23+
# MDEV-30486 Table is not eliminated in bb-11.0
24+
#
25+
explain SELECT c_custkey, c_name AS currency2 FROM partsupp LEFT JOIN part ON ( p_partkey = ps_partkey ) JOIN supplier ON (s_suppkey = ps_suppkey) JOIN lineitem ON ( ps_suppkey = l_suppkey ) JOIN orders ON ( l_orderkey = o_orderkey ) JOIN customer ON ( o_custkey = c_custkey ) HAVING c_custkey > 150;
26+
id select_type table type possible_keys key key_len ref rows Extra
27+
1 SIMPLE supplier index PRIMARY PRIMARY 4 NULL 10 Using index
28+
1 SIMPLE partsupp ref i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16
29+
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100
30+
1 SIMPLE orders eq_ref PRIMARY,i_o_custkey PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
31+
1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1
2232
DROP DATABASE dbt3_s001;
2333
#
2434
# End of 10.5 tests

mysql-test/main/range_aria_dbt3.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ explain SELECT COUNT(*) FROM lineitem WHERE l_orderkey BETWEEN 111 AND 262 OR (
2626

2727
SELECT COUNT(*) FROM lineitem WHERE l_orderkey BETWEEN 111 AND 262 OR ( l_orderkey BETWEEN 152 AND 672 AND l_linenumber BETWEEN 4 AND 9 );
2828

29+
--echo #
30+
--echo # MDEV-30486 Table is not eliminated in bb-11.0
31+
--echo #
32+
33+
explain SELECT c_custkey, c_name AS currency2 FROM partsupp LEFT JOIN part ON ( p_partkey = ps_partkey ) JOIN supplier ON (s_suppkey = ps_suppkey) JOIN lineitem ON ( ps_suppkey = l_suppkey ) JOIN orders ON ( l_orderkey = o_orderkey ) JOIN customer ON ( o_custkey = c_custkey ) HAVING c_custkey > 150;
34+
2935
DROP DATABASE dbt3_s001;
3036

3137
--echo #

mysql-test/main/show_explain.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ explain
12641264
SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2;
12651265
id select_type table type possible_keys key key_len ref rows Extra
12661266
1 SIMPLE t2 system NULL NULL NULL NULL 1
1267-
1 SIMPLE t1 range b b 6 NULL 107 Using where; Using index
1267+
1 SIMPLE t1 index b b 6 NULL 107 Using where; Using index
12681268
1 SIMPLE t3 ref PRIMARY PRIMARY 5 test.t1.b 1 Using index
12691269
set @show_explain_probe_select_id=1;
12701270
SET debug_dbug='+d,show_explain_probe_do_select';
@@ -1273,7 +1273,7 @@ connection default;
12731273
show explain for $thr2;
12741274
id select_type table type possible_keys key key_len ref rows Extra
12751275
1 SIMPLE t2 system NULL NULL NULL NULL 1
1276-
1 SIMPLE t1 range b b 6 NULL 107 Using where; Using index
1276+
1 SIMPLE t1 index b b 6 NULL 107 Using where; Using index
12771277
1 SIMPLE t3 ref PRIMARY PRIMARY 5 test.t1.b 1 Using index
12781278
Warnings:
12791279
Note 1003 SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2

mysql-test/main/subselect_sj_mat.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2
20232023
WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2));
20242024
id select_type table type possible_keys key key_len ref rows Extra
20252025
1 PRIMARY t1 system NULL NULL NULL NULL 1
2026-
1 PRIMARY t2 range c c 5 NULL 8 Using where; Using index
2026+
1 PRIMARY t2 index c c 5 NULL 8 Using where; Using index
20272027
1 PRIMARY s1 ref c c 5 test.t2.c 1 Using where
20282028
1 PRIMARY s2 ref d d 4 const 2 Using where; Using index; FirstMatch(t2)
20292029
3 SUBQUERY t2 ALL NULL NULL NULL NULL 8
@@ -2042,7 +2042,7 @@ WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2
20422042
WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2));
20432043
id select_type table type possible_keys key key_len ref rows Extra
20442044
1 PRIMARY t1 system NULL NULL NULL NULL 1
2045-
1 PRIMARY t2 range c c 5 NULL 8 Using where; Using index
2045+
1 PRIMARY t2 index c c 5 NULL 8 Using where; Using index
20462046
1 PRIMARY s1 hash_ALL c #hash#c 5 test.t2.c 8 Using where; Using join buffer (flat, BNLH join)
20472047
1 PRIMARY s2 hash_range d #hash#d:d 4:4 const 2 Using where; Using index; FirstMatch(t2); Using join buffer (incremental, BNLH join)
20482048
3 SUBQUERY t2 ALL NULL NULL NULL NULL 8

sql/sql_select.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13390,7 +13390,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
1339013390

1339113391
if (!tab->table->is_filled_at_execution() &&
1339213392
!tab->loosescan_match_tab && // (1)
13393-
((cond && (!tab->keys.is_subset(tab->const_keys) && i > 0)) ||
13393+
((cond && (!tab->keys.is_subset(tab->const_keys) &&
13394+
i > join->const_tables)) ||
1339413395
(!tab->const_keys.is_clear_all() && i == join->const_tables &&
1339513396
join->unit->lim.get_select_limit() <
1339613397
join->best_positions[i].records_read &&

sql/table.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
20462046
next_chunk+= str_db_type_length + 2;
20472047
}
20482048

2049-
share->set_use_ext_keys_flag(plugin_hton(se_plugin)->flags & HTON_SUPPORTS_EXTENDED_KEYS);
2049+
share->set_use_ext_keys_flag(plugin_hton(se_plugin)->flags &
2050+
HTON_SUPPORTS_EXTENDED_KEYS);
20502051

20512052
if (create_key_infos(disk_buff + 6, frm_image_end, keys, keyinfo,
20522053
new_frm_ver, &ext_key_parts,
@@ -3083,12 +3084,17 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
30833084
if (handler_file->index_flags(key, i, 0) & HA_KEYREAD_ONLY)
30843085
{
30853086
share->keys_for_keyread.set_bit(key);
3087+
/*
3088+
part_of_key is used to check if we can use the field
3089+
as part of covering key (which implies HA_KEYREAD_ONLY).
3090+
*/
30863091
field->part_of_key.set_bit(key);
3087-
if (i < keyinfo->user_defined_key_parts)
3088-
field->part_of_key_not_clustered.set_bit(key);
30893092
}
30903093
if (handler_file->index_flags(key, i, 1) & HA_READ_ORDER)
30913094
field->part_of_sortkey.set_bit(key);
3095+
3096+
if (i < keyinfo->user_defined_key_parts)
3097+
field->part_of_key_not_clustered.set_bit(key);
30923098
}
30933099
if (!(key_part->key_part_flag & HA_REVERSE_SORT) &&
30943100
usable_parts == i)

0 commit comments

Comments
 (0)