Skip to content

Commit 3c97097

Browse files
committed
Merge 10.4 into 10.5
2 parents 8426c74 + bab4348 commit 3c97097

File tree

8 files changed

+141
-14
lines changed

8 files changed

+141
-14
lines changed

mysql-test/main/derived_cond_pushdown.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16679,7 +16679,7 @@ EXPLAIN EXTENDED
1667916679
SELECT * FROM v1 JOIN v2 ON v1.f = v2.f;
1668016680
id select_type table type possible_keys key key_len ref rows filtered Extra
1668116681
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
16682-
3 LATERAL DERIVED NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
16682+
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
1668316683
Warnings:
1668416684
Note 1003 /* select#1 */ select NULL AS `f`,`v2`.`f` AS `f` from `test`.`t1` `a` straight_join `test`.`t1` `b` join `test`.`v2` where 0
1668516685
DROP VIEW v1,v2;

mysql-test/main/derived_split_innodb.result

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,68 @@ id select_type table type possible_keys key key_len ref rows Extra
176176
3 LATERAL DERIVED t1 ref a,a_2 a 5 test.t1.a 1 Using where; Using temporary; Using filesort
177177
3 LATERAL DERIVED t2 ref c c 5 test.t1.b 1 Using index
178178
DROP TABLE t1, t2;
179+
#
180+
# Bug mdev-25714: usage non-splitting covering index is cheaper than
181+
# usage of the best splitting index for one group
182+
#
183+
create table t1 (
184+
id int not null, itemid int not null, index idx (itemid)
185+
) engine=innodb;
186+
insert into t1 values (1, 2), (2,2), (4,2), (4,2), (0,3), (3,3);
187+
create table t2 (id int not null) engine=innodb;
188+
insert into t2 values (2);
189+
create table t3 (
190+
id int not null, itemid int not null, userid int not null, primary key (id),
191+
index idx1 (userid, itemid), index idx2 (itemid)
192+
) engine innodb;
193+
insert into t3 values (1,1,1), (2,1,1), (3,2,1), (4,2,1), (5,3,1);
194+
set use_stat_tables='never';
195+
set optimizer_use_condition_selectivity=1;
196+
analyze table t1,t2,t3;
197+
Table Op Msg_type Msg_text
198+
test.t1 analyze status OK
199+
test.t2 analyze status OK
200+
test.t3 analyze status OK
201+
set optimizer_switch='split_materialized=on';
202+
explain select t1.id, t1.itemid, dt.id, t2.id
203+
from t1,
204+
(select itemid, max(id) as id from t3 where userid = 1 group by itemid) dt,
205+
t2
206+
where t1.id = dt.id and t1.itemid = dt.itemid and t2.id=t1.itemid;
207+
id select_type table type possible_keys key key_len ref rows Extra
208+
1 PRIMARY t2 ALL NULL NULL NULL NULL 1
209+
1 PRIMARY <derived2> ref key1 key1 4 test.t2.id 2
210+
1 PRIMARY t1 ALL idx NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
211+
2 DERIVED t3 ref idx1,idx2 idx1 4 const 5 Using where; Using index
212+
select t1.id, t1.itemid, dt.id, t2.id
213+
from t1,
214+
(select itemid, max(id) as id from t3 where userid = 1 group by itemid) dt,
215+
t2
216+
where t1.id = dt.id and t1.itemid = dt.itemid and t2.id=t1.itemid;
217+
id itemid id id
218+
4 2 4 2
219+
4 2 4 2
220+
set optimizer_switch='split_materialized=off';
221+
explain select t1.id, t1.itemid, dt.id, t2.id
222+
from t1,
223+
(select itemid, max(id) as id from t3 where userid = 1 group by itemid) dt,
224+
t2
225+
where t1.id = dt.id and t1.itemid = dt.itemid and t2.id=t1.itemid;
226+
id select_type table type possible_keys key key_len ref rows Extra
227+
1 PRIMARY t2 ALL NULL NULL NULL NULL 1
228+
1 PRIMARY <derived2> ref key1 key1 4 test.t2.id 2
229+
1 PRIMARY t1 ALL idx NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
230+
2 DERIVED t3 ref idx1 idx1 4 const 5 Using where; Using index
231+
select t1.id, t1.itemid, dt.id, t2.id
232+
from t1,
233+
(select itemid, max(id) as id from t3 where userid = 1 group by itemid) dt,
234+
t2
235+
where t1.id = dt.id and t1.itemid = dt.itemid and t2.id=t1.itemid;
236+
id itemid id id
237+
4 2 4 2
238+
4 2 4 2
239+
drop table t1,t2,t3;
240+
set optimizer_switch='split_materialized=default';
241+
set use_stat_tables=default;
242+
set optimizer_use_condition_selectivity=default;
243+
# End of 10.3 tests

mysql-test/main/derived_split_innodb.test

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,44 @@ eval set statement optimizer_switch='split_materialized=on' for $query;
152152

153153
DROP TABLE t1, t2;
154154

155+
--echo #
156+
--echo # Bug mdev-25714: usage non-splitting covering index is cheaper than
157+
--echo # usage of the best splitting index for one group
158+
--echo #
159+
160+
create table t1 (
161+
id int not null, itemid int not null, index idx (itemid)
162+
) engine=innodb;
163+
insert into t1 values (1, 2), (2,2), (4,2), (4,2), (0,3), (3,3);
164+
create table t2 (id int not null) engine=innodb;
165+
insert into t2 values (2);
166+
create table t3 (
167+
id int not null, itemid int not null, userid int not null, primary key (id),
168+
index idx1 (userid, itemid), index idx2 (itemid)
169+
) engine innodb;
170+
insert into t3 values (1,1,1), (2,1,1), (3,2,1), (4,2,1), (5,3,1);
171+
set use_stat_tables='never';
172+
set optimizer_use_condition_selectivity=1;
173+
analyze table t1,t2,t3;
174+
175+
let $q=
176+
select t1.id, t1.itemid, dt.id, t2.id
177+
from t1,
178+
(select itemid, max(id) as id from t3 where userid = 1 group by itemid) dt,
179+
t2
180+
where t1.id = dt.id and t1.itemid = dt.itemid and t2.id=t1.itemid;
181+
182+
set optimizer_switch='split_materialized=on';
183+
eval explain $q;
184+
eval $q;
185+
186+
set optimizer_switch='split_materialized=off';
187+
eval explain $q;
188+
eval $q;
189+
190+
drop table t1,t2,t3;
191+
set optimizer_switch='split_materialized=default';
192+
set use_stat_tables=default;
193+
set optimizer_use_condition_selectivity=default;
194+
195+
--echo # End of 10.3 tests

mysql-test/main/lock_kill.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LOCK TABLE t1 WRITE;
1717
eval KILL $conid;
1818
--enable_query_log
1919
--connection con1
20-
--error 0,2013,ER_CONNECTION_KILLED
20+
--error 0,2006,2013,ER_CONNECTION_KILLED
2121
reap;
2222
--connection default
2323
--disconnect con1
@@ -35,7 +35,7 @@ LOCK TABLE t1 WRITE, t2 WRITE;
3535
eval KILL $conid;
3636
--enable_query_log
3737
--connection con1
38-
--error 0,2013,ER_CONNECTION_KILLED
38+
--error 0,2006,2013,ER_CONNECTION_KILLED
3939
reap;
4040
--connection default
4141
--disconnect con1

sql/field.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7857,7 +7857,7 @@ bool Field_varstring::send(Protocol *protocol)
78577857
#ifdef HAVE_MEM_CHECK
78587858
void Field_varstring::mark_unused_memory_as_defined()
78597859
{
7860-
uint used_length= get_length();
7860+
uint used_length __attribute__((unused)) = get_length();
78617861
MEM_MAKE_DEFINED(get_data() + used_length, field_length - used_length);
78627862
}
78637863
#endif

sql/opt_split.cc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -958,11 +958,7 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(double record_count,
958958
in the cache
959959
*/
960960
spl_plan= spl_opt_info->find_plan(best_table, best_key, best_key_parts);
961-
if (!spl_plan &&
962-
(spl_plan= (SplM_plan_info *) thd->alloc(sizeof(SplM_plan_info))) &&
963-
(spl_plan->best_positions=
964-
(POSITION *) thd->alloc(sizeof(POSITION) * join->table_count)) &&
965-
!spl_opt_info->plan_cache.push_back(spl_plan))
961+
if (!spl_plan)
966962
{
967963
/*
968964
The plan for the chosen key has not been found in the cache.
@@ -972,6 +968,27 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(double record_count,
972968
reset_validity_vars_for_keyuses(best_key_keyuse_ext_start, best_table,
973969
best_key, remaining_tables, true);
974970
choose_plan(join, all_table_map & ~join->const_table_map);
971+
972+
/*
973+
Check that the chosen plan is really a splitting plan.
974+
If not or if there is not enough memory to save the plan in the cache
975+
then just return with no splitting plan.
976+
*/
977+
POSITION *first_non_const_pos= join->best_positions + join->const_tables;
978+
TABLE *table= first_non_const_pos->table->table;
979+
key_map spl_keys= table->keys_usable_for_splitting;
980+
if (!(first_non_const_pos->key &&
981+
spl_keys.is_set(first_non_const_pos->key->key)) ||
982+
!(spl_plan= (SplM_plan_info *) thd->alloc(sizeof(SplM_plan_info))) ||
983+
!(spl_plan->best_positions=
984+
(POSITION *) thd->alloc(sizeof(POSITION) * join->table_count)) ||
985+
spl_opt_info->plan_cache.push_back(spl_plan))
986+
{
987+
reset_validity_vars_for_keyuses(best_key_keyuse_ext_start, best_table,
988+
best_key, remaining_tables, false);
989+
return 0;
990+
}
991+
975992
spl_plan->keyuse_ext_start= best_key_keyuse_ext_start;
976993
spl_plan->table= best_table;
977994
spl_plan->key= best_key;

storage/innobase/include/srv0mon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ Use MONITOR_DEC if appropriate mutex protection exists.
639639

640640
#ifdef HAVE_MEM_CHECK
641641
# define MONITOR_CHECK_DEFINED(value) do { \
642-
mon_type_t m = value; \
642+
mon_type_t m __attribute__((unused))= value; \
643643
MEM_CHECK_DEFINED(&m, sizeof m); \
644644
} while (0)
645645
#else /* HAVE_MEM_CHECK */

storage/innobase/page/page0cur.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,8 +1315,10 @@ page_cur_insert_rec_low(
13151315

13161316
#ifdef HAVE_MEM_CHECK
13171317
{
1318-
const void *rec_start= rec - rec_offs_extra_size(offsets);
1319-
ulint extra_size= rec_offs_extra_size(offsets) -
1318+
const void *rec_start __attribute__((unused))=
1319+
rec - rec_offs_extra_size(offsets);
1320+
ulint extra_size __attribute__((unused))=
1321+
rec_offs_extra_size(offsets) -
13201322
(page_is_comp(block->frame)
13211323
? REC_N_NEW_EXTRA_BYTES
13221324
: REC_N_OLD_EXTRA_BYTES);
@@ -1722,8 +1724,10 @@ page_cur_insert_rec_zip(
17221724

17231725
#ifdef HAVE_MEM_CHECK
17241726
{
1725-
const void *rec_start= rec - rec_offs_extra_size(offsets);
1726-
ulint extra_size= rec_offs_extra_size(offsets) - REC_N_NEW_EXTRA_BYTES;
1727+
const void *rec_start __attribute__((unused))=
1728+
rec - rec_offs_extra_size(offsets);
1729+
ulint extra_size __attribute__((unused))=
1730+
rec_offs_extra_size(offsets) - REC_N_NEW_EXTRA_BYTES;
17271731
/* All data bytes of the record must be valid. */
17281732
MEM_CHECK_DEFINED(rec, rec_offs_data_size(offsets));
17291733
/* The variable-length header must be valid. */

0 commit comments

Comments
 (0)