Skip to content

Commit b11ff3d

Browse files
author
Varun Gupta
committed
MDEV-22019: Sig 11 in next_breadth_first_tab | max_sort_length setting + double GROUP BY leads to crash
No need to create a temp table for aggregation if we have encountered some error.
1 parent 0b00c1a commit b11ff3d

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

mysql-test/r/group_by.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,3 +2861,17 @@ SELECT 1 FROM t1
28612861
GROUP BY REPEAT((BINARY pk), v1), AES_DECRYPT((@A := i1), 20852) WITH ROLLUP HAVING LOAD_FILE('a') ;
28622862
1
28632863
drop table t1;
2864+
#
2865+
# MDEV-22019: Sig 11 in next_breadth_first_tab | max_sort_length setting + double
2866+
# GROUP BY leads to crash
2867+
#
2868+
CALL mtr.add_suppression("Out of sort memory");
2869+
CALL mtr.add_suppression("Sort aborted");
2870+
SET @save_max_sort_length= @@max_sort_length;
2871+
SET max_sort_length=2000000;
2872+
SELECT * FROM information_schema.tables t JOIN information_schema.columns c
2873+
ON t.table_schema=c.table_schema
2874+
WHERE c.table_schema=(SELECT COUNT(*) FROM INFORMATION_SCHEMA.columns GROUP BY column_type)
2875+
GROUP BY t.table_name;
2876+
ERROR HY001: Out of sort memory, consider increasing server sort buffer size
2877+
SET max_sort_length= @save_max_sort_length;

mysql-test/t/group_by.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,3 +1979,20 @@ GROUP BY REPEAT((BINARY pk), v1), AES_DECRYPT((@A := i1), 20852) WITH ROLLUP HAV
19791979
SELECT 1 FROM t1
19801980
GROUP BY REPEAT((BINARY pk), v1), AES_DECRYPT((@A := i1), 20852) WITH ROLLUP HAVING LOAD_FILE('a') ;
19811981
drop table t1;
1982+
1983+
--echo #
1984+
--echo # MDEV-22019: Sig 11 in next_breadth_first_tab | max_sort_length setting + double
1985+
--echo # GROUP BY leads to crash
1986+
--echo #
1987+
1988+
1989+
CALL mtr.add_suppression("Out of sort memory");
1990+
CALL mtr.add_suppression("Sort aborted");
1991+
SET @save_max_sort_length= @@max_sort_length;
1992+
SET max_sort_length=2000000;
1993+
--error ER_OUT_OF_SORTMEMORY
1994+
SELECT * FROM information_schema.tables t JOIN information_schema.columns c
1995+
ON t.table_schema=c.table_schema
1996+
WHERE c.table_schema=(SELECT COUNT(*) FROM INFORMATION_SCHEMA.columns GROUP BY column_type)
1997+
GROUP BY t.table_name;
1998+
SET max_sort_length= @save_max_sort_length;

sql/sql_select.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,8 +2210,12 @@ JOIN::optimize_inner()
22102210
having_is_correlated= MY_TEST(having->used_tables() & OUTER_REF_TABLE_BIT);
22112211
tmp_having= having;
22122212

2213-
if ((select_lex->options & OPTION_SCHEMA_TABLE))
2214-
optimize_schema_tables_reads(this);
2213+
if ((select_lex->options & OPTION_SCHEMA_TABLE) &&
2214+
optimize_schema_tables_reads(this))
2215+
DBUG_RETURN(TRUE);
2216+
2217+
if (unlikely(thd->is_error()))
2218+
DBUG_RETURN(TRUE);
22152219

22162220
/*
22172221
The loose index scan access method guarantees that all grouping or

sql/sql_show.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8299,7 +8299,6 @@ static bool optimize_for_get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond
82998299
bool optimize_schema_tables_reads(JOIN *join)
83008300
{
83018301
THD *thd= join->thd;
8302-
bool result= 0;
83038302
DBUG_ENTER("optimize_schema_tables_reads");
83048303

83058304
JOIN_TAB *tab;
@@ -8334,11 +8333,11 @@ bool optimize_schema_tables_reads(JOIN *join)
83348333
*/
83358334
cond= tab->cache_select->cond;
83368335
}
8337-
8338-
optimize_for_get_all_tables(thd, table_list, cond);
8336+
if (optimize_for_get_all_tables(thd, table_list, cond))
8337+
DBUG_RETURN(TRUE); // Handle OOM
83398338
}
83408339
}
8341-
DBUG_RETURN(result);
8340+
DBUG_RETURN(FALSE);
83428341
}
83438342

83448343

0 commit comments

Comments
 (0)