summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Petrunya <psergey@askmonty.org>2011-12-19 22:24:10 +0400
committerSergey Petrunya <psergey@askmonty.org>2011-12-19 22:24:10 +0400
commit15ea7238e42ea62da32c926c0a1667802f7646d9 (patch)
tree9c894e5273b417b39635a10b113bf02c26aa2be6
parentbe3e52984fe20f5aa7862cf9ace86beb588d3240 (diff)
downloadmariadb-git-15ea7238e42ea62da32c926c0a1667802f7646d9.tar.gz
BUG#906385: EXPLAIN EXTENDED crashes in TABLE_LIST::print with limited max_join_size
- Take into account that subquery's optimization can fail because of @@max_join_size error.
-rw-r--r--mysql-test/r/subselect_sj2_mat.result22
-rw-r--r--mysql-test/t/subselect_sj2_mat.test29
-rw-r--r--sql/sql_select.cc11
3 files changed, 61 insertions, 1 deletions
diff --git a/mysql-test/r/subselect_sj2_mat.result b/mysql-test/r/subselect_sj2_mat.result
index f217cee38ce..5a9c3b90755 100644
--- a/mysql-test/r/subselect_sj2_mat.result
+++ b/mysql-test/r/subselect_sj2_mat.result
@@ -897,3 +897,25 @@ set optimizer_switch=default;
select @@optimizer_switch like '%materialization=on%';
@@optimizer_switch like '%materialization=on%'
1
+#
+# BUG#906385: EXPLAIN EXTENDED crashes in TABLE_LIST::print with limited max_join_size
+#
+CREATE TABLE t1 ( a INT );
+CREATE TABLE t2 ( b INT );
+INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t2 VALUES
+(1),(2),(3),(4),(5),
+(6),(7),(8),(9),(10),
+(11),(12),(13),(14),(15),
+(16),(17),(18),(19),(20);
+set @tmp_906385=@@max_join_size;
+SET max_join_size = 80;
+EXPLAIN EXTENDED
+SELECT COUNT(*) FROM t1
+WHERE a IN
+( SELECT b FROM t2 GROUP BY b )
+AND ( 6 ) IN
+( SELECT MIN( t2.b ) FROM t2 alias1, t2 );
+ERROR 42000: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay
+DROP TABLE t1, t2;
+set max_join_size= @tmp_906385;
diff --git a/mysql-test/t/subselect_sj2_mat.test b/mysql-test/t/subselect_sj2_mat.test
index fdfa0f311d3..7c3b37b517a 100644
--- a/mysql-test/t/subselect_sj2_mat.test
+++ b/mysql-test/t/subselect_sj2_mat.test
@@ -8,3 +8,32 @@ set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
set optimizer_switch=default;
select @@optimizer_switch like '%materialization=on%';
+
+--echo #
+--echo # BUG#906385: EXPLAIN EXTENDED crashes in TABLE_LIST::print with limited max_join_size
+--echo #
+CREATE TABLE t1 ( a INT );
+CREATE TABLE t2 ( b INT );
+
+INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t2 VALUES
+ (1),(2),(3),(4),(5),
+ (6),(7),(8),(9),(10),
+ (11),(12),(13),(14),(15),
+ (16),(17),(18),(19),(20);
+
+set @tmp_906385=@@max_join_size;
+SET max_join_size = 80;
+
+--error ER_TOO_BIG_SELECT
+EXPLAIN EXTENDED
+SELECT COUNT(*) FROM t1
+WHERE a IN
+ ( SELECT b FROM t2 GROUP BY b )
+ AND ( 6 ) IN
+ ( SELECT MIN( t2.b ) FROM t2 alias1, t2 );
+
+DROP TABLE t1, t2;
+set max_join_size= @tmp_906385;
+
+
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index dc9485e0f94..18925f0f83f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -21396,8 +21396,17 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str,
}
else if (jtbm_subselect)
{
- if (jtbm_subselect->is_jtbm_const_tab)
+ if (jtbm_subselect->engine->engine_type() ==
+ subselect_engine::SINGLE_SELECT_ENGINE)
{
+ /*
+ We get here when conversion into materialization didn't finish (this
+ happens when
+ - The subquery is a degenerate case which produces 0 or 1 record
+ - subquery's optimization didn't finish because of @@max_join_size
+ limits
+ - ... maybe some other cases like this
+ */
str->append(STRING_WITH_LEN(" <materialize> ("));
jtbm_subselect->engine->print(str, query_type);
str->append(')');