Skip to content

Commit 49552cf

Browse files
committed
Merge branch '5.5' into bb-10.0-merge-5.5
2 parents 57fea99 + 2e7ba70 commit 49552cf

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

mysql-test/r/subselect_innodb.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,20 @@ set join_cache_level = default;
511511
drop view v1;
512512
drop table t1,t2;
513513
#
514+
# MDEV-10693: cost-based choice between materialization and in-to-exists
515+
# for a subquery from the expression used in ref access
516+
#
517+
CREATE TABLE t1 (i1 INT PRIMARY KEY) ENGINE=InnoDB;
518+
INSERT INTO t1 VALUES (1),(2);
519+
CREATE TABLE t2 (i2 INT) ENGINE=InnoDB;
520+
CREATE TABLE t3 (i3 INT PRIMARY KEY) ENGINE=InnoDB;
521+
INSERT INTO t3 VALUES (3);
522+
SELECT * FROM t1
523+
WHERE NULL IN ( SELECT i2 FROM t2
524+
WHERE i1 IN ( i2 IN ( SELECT i3 FROM t3 ) ) AND i2 = 2 );
525+
i1
526+
DROP TABLE t1,t2,t3;
527+
#
514528
# MDEV-6041: ORDER BY+subqueries: subquery_table.key=outer_table.col is not recongized as binding
515529
#
516530
create table t1(a int) engine=innodb;

mysql-test/t/subselect_innodb.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,27 @@ set join_cache_level = default;
502502
drop view v1;
503503
drop table t1,t2;
504504

505+
--echo #
506+
--echo # MDEV-10693: cost-based choice between materialization and in-to-exists
507+
--echo # for a subquery from the expression used in ref access
508+
--echo #
509+
510+
--source include/have_innodb.inc
511+
512+
CREATE TABLE t1 (i1 INT PRIMARY KEY) ENGINE=InnoDB;
513+
INSERT INTO t1 VALUES (1),(2);
514+
515+
CREATE TABLE t2 (i2 INT) ENGINE=InnoDB;
516+
517+
CREATE TABLE t3 (i3 INT PRIMARY KEY) ENGINE=InnoDB;
518+
INSERT INTO t3 VALUES (3);
519+
520+
SELECT * FROM t1
521+
WHERE NULL IN ( SELECT i2 FROM t2
522+
WHERE i1 IN ( i2 IN ( SELECT i3 FROM t3 ) ) AND i2 = 2 );
523+
524+
DROP TABLE t1,t2,t3;
525+
505526
--echo #
506527
--echo # MDEV-6041: ORDER BY+subqueries: subquery_table.key=outer_table.col is not recongized as binding
507528
--echo #

sql/sql_select.cc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8443,8 +8443,6 @@ get_best_combination(JOIN *join)
84438443
join->full_join=0;
84448444
join->hash_join= FALSE;
84458445

8446-
used_tables= OUTER_REF_TABLE_BIT; // Outer row is already read
8447-
84488446
fix_semijoin_strategies_for_picked_join_order(join);
84498447

84508448
JOIN_TAB_RANGE *root_range;
@@ -8508,7 +8506,6 @@ get_best_combination(JOIN *join)
85088506
j->bush_root_tab= sjm_nest_root;
85098507

85108508
form=join->table[tablenr]=j->table;
8511-
used_tables|= form->map;
85128509
form->reginfo.join_tab=j;
85138510
DBUG_PRINT("info",("type: %d", j->type));
85148511
if (j->type == JT_CONST)
@@ -8535,9 +8532,6 @@ get_best_combination(JOIN *join)
85358532
join->best_positions[tablenr].loosescan_picker.loosescan_key);
85368533
j->index= join->best_positions[tablenr].loosescan_picker.loosescan_key;
85378534
}*/
8538-
8539-
if (keyuse && create_ref_for_key(join, j, keyuse, TRUE, used_tables))
8540-
DBUG_RETURN(TRUE); // Something went wrong
85418535

85428536
if ((j->type == JT_REF || j->type == JT_EQ_REF) &&
85438537
is_hash_join_key_no(j->ref.key))
@@ -8563,6 +8557,21 @@ get_best_combination(JOIN *join)
85638557
}
85648558
root_range->end= j;
85658559

8560+
used_tables= OUTER_REF_TABLE_BIT; // Outer row is already read
8561+
for (j=join_tab, tablenr=0 ; tablenr < table_count ; tablenr++,j++)
8562+
{
8563+
if (j->bush_children)
8564+
j= j->bush_children->start;
8565+
8566+
used_tables|= j->table->map;
8567+
if ((keyuse= join->best_positions[tablenr].key) &&
8568+
create_ref_for_key(join, j, keyuse, TRUE, used_tables))
8569+
DBUG_RETURN(TRUE); // Something went wrong
8570+
8571+
if (j->last_leaf_in_bush)
8572+
j= j->bush_root_tab;
8573+
}
8574+
85668575
join->top_join_tab_count= join->join_tab_ranges.head()->end -
85678576
join->join_tab_ranges.head()->start;
85688577
/*

0 commit comments

Comments
 (0)