Skip to content

Commit 4c14795

Browse files
committed
Merge 5.5 into 10.0
2 parents c903ba2 + bdcd7f7 commit 4c14795

File tree

11 files changed

+234
-68
lines changed

11 files changed

+234
-68
lines changed

mysql-test/r/subselect.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7186,3 +7186,29 @@ NULL
71867186
# SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2;
71877187
#
71887188
drop table t1, t2;
7189+
#
7190+
# MDEV-13933: Wrong results in COUNT() query with EXISTS and exists_to_in
7191+
# (5.5 test)
7192+
#
7193+
SET @optimiser_switch_save= @@optimizer_switch;
7194+
CREATE TABLE t1 (a INT NOT NULL);
7195+
INSERT INTO t1 VALUES (1),(1),(1),(5),(5);
7196+
CREATE TABLE t2 (b INT);
7197+
INSERT INTO t2 VALUES (5),(1);
7198+
CREATE TABLE t3 (c INT, KEY(c));
7199+
INSERT INTO t3 VALUES (5),(5);
7200+
SET optimizer_switch='semijoin=on';
7201+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7202+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7203+
a
7204+
5
7205+
5
7206+
SET optimizer_switch='semijoin=off';
7207+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7208+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7209+
a
7210+
5
7211+
5
7212+
SET @@optimizer_switch= @optimiser_switch_save;
7213+
DROP TABLE t1, t2, t3;
7214+
End of 5.5 tests

mysql-test/r/subselect_no_exists_to_in.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7186,6 +7186,32 @@ NULL
71867186
# SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2;
71877187
#
71887188
drop table t1, t2;
7189+
#
7190+
# MDEV-13933: Wrong results in COUNT() query with EXISTS and exists_to_in
7191+
# (5.5 test)
7192+
#
7193+
SET @optimiser_switch_save= @@optimizer_switch;
7194+
CREATE TABLE t1 (a INT NOT NULL);
7195+
INSERT INTO t1 VALUES (1),(1),(1),(5),(5);
7196+
CREATE TABLE t2 (b INT);
7197+
INSERT INTO t2 VALUES (5),(1);
7198+
CREATE TABLE t3 (c INT, KEY(c));
7199+
INSERT INTO t3 VALUES (5),(5);
7200+
SET optimizer_switch='semijoin=on';
7201+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7202+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7203+
a
7204+
5
7205+
5
7206+
SET optimizer_switch='semijoin=off';
7207+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7208+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7209+
a
7210+
5
7211+
5
7212+
SET @@optimizer_switch= @optimiser_switch_save;
7213+
DROP TABLE t1, t2, t3;
7214+
End of 5.5 tests
71897215
set optimizer_switch=default;
71907216
select @@optimizer_switch like '%exists_to_in=off%';
71917217
@@optimizer_switch like '%exists_to_in=off%'

mysql-test/r/subselect_no_mat.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7179,6 +7179,32 @@ NULL
71797179
# SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2;
71807180
#
71817181
drop table t1, t2;
7182+
#
7183+
# MDEV-13933: Wrong results in COUNT() query with EXISTS and exists_to_in
7184+
# (5.5 test)
7185+
#
7186+
SET @optimiser_switch_save= @@optimizer_switch;
7187+
CREATE TABLE t1 (a INT NOT NULL);
7188+
INSERT INTO t1 VALUES (1),(1),(1),(5),(5);
7189+
CREATE TABLE t2 (b INT);
7190+
INSERT INTO t2 VALUES (5),(1);
7191+
CREATE TABLE t3 (c INT, KEY(c));
7192+
INSERT INTO t3 VALUES (5),(5);
7193+
SET optimizer_switch='semijoin=on';
7194+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7195+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7196+
a
7197+
5
7198+
5
7199+
SET optimizer_switch='semijoin=off';
7200+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7201+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7202+
a
7203+
5
7204+
5
7205+
SET @@optimizer_switch= @optimiser_switch_save;
7206+
DROP TABLE t1, t2, t3;
7207+
End of 5.5 tests
71827208
set optimizer_switch=default;
71837209
select @@optimizer_switch like '%materialization=on%';
71847210
@@optimizer_switch like '%materialization=on%'

mysql-test/r/subselect_no_opts.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7177,4 +7177,30 @@ NULL
71777177
# SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2;
71787178
#
71797179
drop table t1, t2;
7180+
#
7181+
# MDEV-13933: Wrong results in COUNT() query with EXISTS and exists_to_in
7182+
# (5.5 test)
7183+
#
7184+
SET @optimiser_switch_save= @@optimizer_switch;
7185+
CREATE TABLE t1 (a INT NOT NULL);
7186+
INSERT INTO t1 VALUES (1),(1),(1),(5),(5);
7187+
CREATE TABLE t2 (b INT);
7188+
INSERT INTO t2 VALUES (5),(1);
7189+
CREATE TABLE t3 (c INT, KEY(c));
7190+
INSERT INTO t3 VALUES (5),(5);
7191+
SET optimizer_switch='semijoin=on';
7192+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7193+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7194+
a
7195+
5
7196+
5
7197+
SET optimizer_switch='semijoin=off';
7198+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7199+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7200+
a
7201+
5
7202+
5
7203+
SET @@optimizer_switch= @optimiser_switch_save;
7204+
DROP TABLE t1, t2, t3;
7205+
End of 5.5 tests
71807206
set @optimizer_switch_for_subselect_test=null;

mysql-test/r/subselect_no_scache.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7192,6 +7192,32 @@ NULL
71927192
# SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2;
71937193
#
71947194
drop table t1, t2;
7195+
#
7196+
# MDEV-13933: Wrong results in COUNT() query with EXISTS and exists_to_in
7197+
# (5.5 test)
7198+
#
7199+
SET @optimiser_switch_save= @@optimizer_switch;
7200+
CREATE TABLE t1 (a INT NOT NULL);
7201+
INSERT INTO t1 VALUES (1),(1),(1),(5),(5);
7202+
CREATE TABLE t2 (b INT);
7203+
INSERT INTO t2 VALUES (5),(1);
7204+
CREATE TABLE t3 (c INT, KEY(c));
7205+
INSERT INTO t3 VALUES (5),(5);
7206+
SET optimizer_switch='semijoin=on';
7207+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7208+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7209+
a
7210+
5
7211+
5
7212+
SET optimizer_switch='semijoin=off';
7213+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7214+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7215+
a
7216+
5
7217+
5
7218+
SET @@optimizer_switch= @optimiser_switch_save;
7219+
DROP TABLE t1, t2, t3;
7220+
End of 5.5 tests
71957221
set optimizer_switch=default;
71967222
select @@optimizer_switch like '%subquery_cache=on%';
71977223
@@optimizer_switch like '%subquery_cache=on%'

mysql-test/r/subselect_no_semijoin.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7177,5 +7177,31 @@ NULL
71777177
# SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2;
71787178
#
71797179
drop table t1, t2;
7180+
#
7181+
# MDEV-13933: Wrong results in COUNT() query with EXISTS and exists_to_in
7182+
# (5.5 test)
7183+
#
7184+
SET @optimiser_switch_save= @@optimizer_switch;
7185+
CREATE TABLE t1 (a INT NOT NULL);
7186+
INSERT INTO t1 VALUES (1),(1),(1),(5),(5);
7187+
CREATE TABLE t2 (b INT);
7188+
INSERT INTO t2 VALUES (5),(1);
7189+
CREATE TABLE t3 (c INT, KEY(c));
7190+
INSERT INTO t3 VALUES (5),(5);
7191+
SET optimizer_switch='semijoin=on';
7192+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7193+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7194+
a
7195+
5
7196+
5
7197+
SET optimizer_switch='semijoin=off';
7198+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
7199+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
7200+
a
7201+
5
7202+
5
7203+
SET @@optimizer_switch= @optimiser_switch_save;
7204+
DROP TABLE t1, t2, t3;
7205+
End of 5.5 tests
71807206
set @optimizer_switch_for_subselect_test=null;
71817207
set @join_cache_level_for_subselect_test=NULL;

mysql-test/suite/innodb/t/innodb-master.opt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
--default-storage-engine=MyISAM
33
--innodb-strict-mode=0
44
--innodb-file-per-table=0
5+
--loose-innodb-track-changed-pages
6+
--loose-innodb-log-archive

mysql-test/t/subselect.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6069,3 +6069,31 @@ SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2;
60696069
--echo # SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2;
60706070
--echo #
60716071
drop table t1, t2;
6072+
6073+
--echo #
6074+
--echo # MDEV-13933: Wrong results in COUNT() query with EXISTS and exists_to_in
6075+
--echo # (5.5 test)
6076+
--echo #
6077+
SET @optimiser_switch_save= @@optimizer_switch;
6078+
6079+
CREATE TABLE t1 (a INT NOT NULL);
6080+
INSERT INTO t1 VALUES (1),(1),(1),(5),(5);
6081+
6082+
CREATE TABLE t2 (b INT);
6083+
INSERT INTO t2 VALUES (5),(1);
6084+
6085+
CREATE TABLE t3 (c INT, KEY(c));
6086+
INSERT INTO t3 VALUES (5),(5);
6087+
6088+
SET optimizer_switch='semijoin=on';
6089+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
6090+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
6091+
6092+
SET optimizer_switch='semijoin=off';
6093+
select t1.a from t1 where t1.a in (select `test`.`t2`.`b` from `test`.`t2`)
6094+
and t1.a in (select `test`.`t3`.`c` from `test`.`t3`);
6095+
6096+
SET @@optimizer_switch= @optimiser_switch_save;
6097+
DROP TABLE t1, t2, t3;
6098+
6099+
--echo End of 5.5 tests

sql/opt_subselect.cc

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,7 +2692,8 @@ void advance_sj_state(JOIN *join, table_map remaining_tables, uint idx,
26922692
LooseScan detector in best_access_path)
26932693
*/
26942694
remaining_tables &= ~new_join_tab->table->map;
2695-
table_map dups_producing_tables;
2695+
table_map dups_producing_tables, prev_dups_producing_tables,
2696+
prev_sjm_lookup_tables;
26962697

26972698
if (idx == join->const_tables)
26982699
dups_producing_tables= 0;
@@ -2703,7 +2704,7 @@ void advance_sj_state(JOIN *join, table_map remaining_tables, uint idx,
27032704
if ((emb_sj_nest= new_join_tab->emb_sj_nest))
27042705
dups_producing_tables |= emb_sj_nest->sj_inner_tables;
27052706

2706-
Semi_join_strategy_picker **strategy;
2707+
Semi_join_strategy_picker **strategy, **prev_strategy;
27072708
if (idx == join->const_tables)
27082709
{
27092710
/* First table, initialize pickers */
@@ -2755,23 +2756,54 @@ void advance_sj_state(JOIN *join, table_map remaining_tables, uint idx,
27552756
3. We have no clue what to do about fanount of semi-join Y.
27562757
*/
27572758
if ((dups_producing_tables & handled_fanout) ||
2758-
(read_time < *current_read_time &&
2759+
(read_time < *current_read_time &&
27592760
!(handled_fanout & pos->inner_tables_handled_with_other_sjs)))
27602761
{
2761-
/* Mark strategy as used */
2762-
(*strategy)->mark_used();
2763-
pos->sj_strategy= sj_strategy;
2764-
if (sj_strategy == SJ_OPT_MATERIALIZE)
2765-
join->sjm_lookup_tables |= handled_fanout;
2762+
DBUG_ASSERT(pos->sj_strategy != sj_strategy);
2763+
/*
2764+
If the strategy choosen first time or
2765+
the strategy replace strategy which was used to exectly the same
2766+
tables
2767+
*/
2768+
if (pos->sj_strategy == SJ_OPT_NONE ||
2769+
handled_fanout ==
2770+
(prev_dups_producing_tables ^ dups_producing_tables))
2771+
{
2772+
prev_strategy= strategy;
2773+
if (pos->sj_strategy == SJ_OPT_NONE)
2774+
{
2775+
prev_dups_producing_tables= dups_producing_tables;
2776+
prev_sjm_lookup_tables= join->sjm_lookup_tables;
2777+
}
2778+
/* Mark strategy as used */
2779+
(*strategy)->mark_used();
2780+
pos->sj_strategy= sj_strategy;
2781+
if (sj_strategy == SJ_OPT_MATERIALIZE)
2782+
join->sjm_lookup_tables |= handled_fanout;
2783+
else
2784+
join->sjm_lookup_tables &= ~handled_fanout;
2785+
*current_read_time= read_time;
2786+
*current_record_count= rec_count;
2787+
dups_producing_tables &= ~handled_fanout;
2788+
//TODO: update bitmap of semi-joins that were handled together with
2789+
// others.
2790+
if (is_multiple_semi_joins(join, join->positions, idx,
2791+
handled_fanout))
2792+
pos->inner_tables_handled_with_other_sjs |= handled_fanout;
2793+
}
27662794
else
2767-
join->sjm_lookup_tables &= ~handled_fanout;
2768-
*current_read_time= read_time;
2769-
*current_record_count= rec_count;
2770-
dups_producing_tables &= ~handled_fanout;
2771-
//TODO: update bitmap of semi-joins that were handled together with
2772-
// others.
2773-
if (is_multiple_semi_joins(join, join->positions, idx, handled_fanout))
2774-
pos->inner_tables_handled_with_other_sjs |= handled_fanout;
2795+
{
2796+
/* Conflict fall to most general variant */
2797+
(*prev_strategy)->set_empty();
2798+
dups_producing_tables= prev_dups_producing_tables;
2799+
join->sjm_lookup_tables= prev_sjm_lookup_tables;
2800+
// mark it 'none' to avpoid loops
2801+
pos->sj_strategy= SJ_OPT_NONE;
2802+
// next skip to last;
2803+
strategy= pickers +
2804+
(sizeof(pickers)/sizeof(Semi_join_strategy_picker*) - 3);
2805+
continue;
2806+
}
27752807
}
27762808
else
27772809
{

storage/innobase/trx/trx0purge.cc

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -585,32 +585,6 @@ trx_purge_rseg_get_next_history_log(
585585

586586
mutex_exit(&(rseg->mutex));
587587
mtr_commit(&mtr);
588-
589-
mutex_enter(&trx_sys->mutex);
590-
591-
/* Add debug code to track history list corruption reported
592-
on the MySQL mailing list on Nov 9, 2004. The fut0lst.cc
593-
file-based list was corrupt. The prev node pointer was
594-
FIL_NULL, even though the list length was over 8 million nodes!
595-
We assume that purge truncates the history list in large
596-
size pieces, and if we here reach the head of the list, the
597-
list cannot be longer than 2000 000 undo logs now. */
598-
599-
if (trx_sys->rseg_history_len > 2000000) {
600-
ut_print_timestamp(stderr);
601-
fprintf(stderr,
602-
" InnoDB: Warning: purge reached the"
603-
" head of the history list,\n"
604-
"InnoDB: but its length is still"
605-
" reported as %lu! Make a detailed bug\n"
606-
"InnoDB: report, and submit it"
607-
" to https://jira.mariadb.org/\n",
608-
(ulong) trx_sys->rseg_history_len);
609-
ut_ad(0);
610-
}
611-
612-
mutex_exit(&trx_sys->mutex);
613-
614588
return;
615589
}
616590

0 commit comments

Comments
 (0)