Commit fe1f4ca8 authored by Monty's avatar Monty

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>
parent 01c82173
...@@ -442,7 +442,6 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -442,7 +442,6 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1 1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where
1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where 1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where
1 SIMPLE e2 eq_ref PRIMARY PRIMARY 4 test.t6.f1 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1
1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1 1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1
1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where 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 ...@@ -465,7 +464,6 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1 1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where
1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where 1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where
1 SIMPLE e2 eq_ref PRIMARY PRIMARY 4 test.t6.f1 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1
1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1 1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1
1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where 1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where
......
...@@ -19,6 +19,16 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -19,6 +19,16 @@ id select_type table type possible_keys key key_len ref rows Extra
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 ); 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 );
COUNT(*) COUNT(*)
293 293
#
# MDEV-30486 Table is not eliminated in bb-11.0
#
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;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE supplier index PRIMARY PRIMARY 4 NULL 10 Using index
1 SIMPLE partsupp ref i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16
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
1 SIMPLE orders eq_ref PRIMARY,i_o_custkey PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1
DROP DATABASE dbt3_s001; DROP DATABASE dbt3_s001;
# #
# End of 10.5 tests # End of 10.5 tests
......
...@@ -26,6 +26,12 @@ explain SELECT COUNT(*) FROM lineitem WHERE l_orderkey BETWEEN 111 AND 262 OR ( ...@@ -26,6 +26,12 @@ explain SELECT COUNT(*) FROM lineitem WHERE l_orderkey BETWEEN 111 AND 262 OR (
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 ); 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 );
--echo #
--echo # MDEV-30486 Table is not eliminated in bb-11.0
--echo #
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;
DROP DATABASE dbt3_s001; DROP DATABASE dbt3_s001;
--echo # --echo #
......
...@@ -1264,7 +1264,7 @@ explain ...@@ -1264,7 +1264,7 @@ explain
SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2; SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 system NULL NULL NULL NULL 1 1 SIMPLE t2 system NULL NULL NULL NULL 1
1 SIMPLE t1 range b b 6 NULL 107 Using where; Using index 1 SIMPLE t1 index b b 6 NULL 107 Using where; Using index
1 SIMPLE t3 ref PRIMARY PRIMARY 5 test.t1.b 1 Using index 1 SIMPLE t3 ref PRIMARY PRIMARY 5 test.t1.b 1 Using index
set @show_explain_probe_select_id=1; set @show_explain_probe_select_id=1;
SET debug_dbug='+d,show_explain_probe_do_select'; SET debug_dbug='+d,show_explain_probe_do_select';
...@@ -1273,7 +1273,7 @@ connection default; ...@@ -1273,7 +1273,7 @@ connection default;
show explain for $thr2; show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 system NULL NULL NULL NULL 1 1 SIMPLE t2 system NULL NULL NULL NULL 1
1 SIMPLE t1 range b b 6 NULL 107 Using where; Using index 1 SIMPLE t1 index b b 6 NULL 107 Using where; Using index
1 SIMPLE t3 ref PRIMARY PRIMARY 5 test.t1.b 1 Using index 1 SIMPLE t3 ref PRIMARY PRIMARY 5 test.t1.b 1 Using index
Warnings: Warnings:
Note 1003 SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2 Note 1003 SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2
......
...@@ -2023,7 +2023,7 @@ WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 ...@@ -2023,7 +2023,7 @@ WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2
WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t2 range c c 5 NULL 8 Using where; Using index 1 PRIMARY t2 index c c 5 NULL 8 Using where; Using index
1 PRIMARY s1 ref c c 5 test.t2.c 1 Using where 1 PRIMARY s1 ref c c 5 test.t2.c 1 Using where
1 PRIMARY s2 ref d d 4 const 2 Using where; Using index; FirstMatch(t2) 1 PRIMARY s2 ref d d 4 const 2 Using where; Using index; FirstMatch(t2)
3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 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 ...@@ -2042,7 +2042,7 @@ WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2
WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t2 range c c 5 NULL 8 Using where; Using index 1 PRIMARY t2 index c c 5 NULL 8 Using where; Using index
1 PRIMARY s1 hash_ALL c #hash#c 5 test.t2.c 8 Using where; Using join buffer (flat, BNLH join) 1 PRIMARY s1 hash_ALL c #hash#c 5 test.t2.c 8 Using where; Using join buffer (flat, BNLH join)
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) 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)
3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 3 SUBQUERY t2 ALL NULL NULL NULL NULL 8
......
...@@ -13390,7 +13390,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -13390,7 +13390,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (!tab->table->is_filled_at_execution() && if (!tab->table->is_filled_at_execution() &&
!tab->loosescan_match_tab && // (1) !tab->loosescan_match_tab && // (1)
((cond && (!tab->keys.is_subset(tab->const_keys) && i > 0)) || ((cond && (!tab->keys.is_subset(tab->const_keys) &&
i > join->const_tables)) ||
(!tab->const_keys.is_clear_all() && i == join->const_tables && (!tab->const_keys.is_clear_all() && i == join->const_tables &&
join->unit->lim.get_select_limit() < join->unit->lim.get_select_limit() <
join->best_positions[i].records_read && join->best_positions[i].records_read &&
...@@ -2046,7 +2046,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, ...@@ -2046,7 +2046,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
next_chunk+= str_db_type_length + 2; next_chunk+= str_db_type_length + 2;
} }
share->set_use_ext_keys_flag(plugin_hton(se_plugin)->flags & HTON_SUPPORTS_EXTENDED_KEYS); share->set_use_ext_keys_flag(plugin_hton(se_plugin)->flags &
HTON_SUPPORTS_EXTENDED_KEYS);
if (create_key_infos(disk_buff + 6, frm_image_end, keys, keyinfo, if (create_key_infos(disk_buff + 6, frm_image_end, keys, keyinfo,
new_frm_ver, &ext_key_parts, new_frm_ver, &ext_key_parts,
...@@ -3083,12 +3084,17 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, ...@@ -3083,12 +3084,17 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (handler_file->index_flags(key, i, 0) & HA_KEYREAD_ONLY) if (handler_file->index_flags(key, i, 0) & HA_KEYREAD_ONLY)
{ {
share->keys_for_keyread.set_bit(key); share->keys_for_keyread.set_bit(key);
/*
part_of_key is used to check if we can use the field
as part of covering key (which implies HA_KEYREAD_ONLY).
*/
field->part_of_key.set_bit(key); field->part_of_key.set_bit(key);
if (i < keyinfo->user_defined_key_parts)
field->part_of_key_not_clustered.set_bit(key);
} }
if (handler_file->index_flags(key, i, 1) & HA_READ_ORDER) if (handler_file->index_flags(key, i, 1) & HA_READ_ORDER)
field->part_of_sortkey.set_bit(key); field->part_of_sortkey.set_bit(key);
if (i < keyinfo->user_defined_key_parts)
field->part_of_key_not_clustered.set_bit(key);
} }
if (!(key_part->key_part_flag & HA_REVERSE_SORT) && if (!(key_part->key_part_flag & HA_REVERSE_SORT) &&
usable_parts == i) usable_parts == i)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment