Skip to content

Commit 865ef0f

Browse files
montywivuvova
authored andcommitted
MDEV-33680 Server hangs or assertion fails upon SELECT with limited max_tmp_space_usage
The bug was that Aggregator_distinct::add() did not properly handle write errors. (Old bug exposed by the new code).
1 parent b9f5793 commit 865ef0f

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

mysql-test/main/tmp_space_usage.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,11 @@ INSERT INTO t1 VALUES
150150
UPDATE t1 SET a = '' LIMIT 100;
151151
ERROR HY000: Local temporary space limit reached
152152
DROP TABLE t1;
153+
#
154+
# MDEV-33680 Server hangs or assertion fails upon SELECT with limited
155+
# max_tmp_space_usage
156+
#
157+
set max_tmp_session_space_usage = 1024*1024;
158+
select count(distinct concat(seq,repeat('x',1000))) from seq_1_to_1000;
159+
ERROR HY000: Global temporary space limit reached
153160
# End of 11.5 tests

mysql-test/main/tmp_space_usage.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,13 @@ UPDATE t1 SET a = '' LIMIT 100;
200200

201201
DROP TABLE t1;
202202

203+
--echo #
204+
--echo # MDEV-33680 Server hangs or assertion fails upon SELECT with limited
205+
--echo # max_tmp_space_usage
206+
--echo #
207+
208+
set max_tmp_session_space_usage = 1024*1024;
209+
--error 201
210+
select count(distinct concat(seq,repeat('x',1000))) from seq_1_to_1000;
211+
203212
--echo # End of 11.5 tests

sql/item_sum.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,10 @@ bool Aggregator_distinct::add()
10261026
}
10271027
if (unlikely((error= table->file->ha_write_tmp_row(table->record[0]))) &&
10281028
table->file->is_fatal_error(error, HA_CHECK_DUP))
1029+
{
1030+
table->file->print_error(error, MYF(0));
10291031
return TRUE;
1032+
}
10301033
return FALSE;
10311034
}
10321035
else

sql/sql_expression_cache.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ my_bool Expression_cache_tmptable::put_value(Item *value)
307307
cache_table_param.start_recinfo,
308308
&cache_table_param.recinfo,
309309
error, 1, NULL))
310-
goto err;
310+
goto err2;
311311
}
312312
}
313313
}
@@ -318,6 +318,8 @@ my_bool Expression_cache_tmptable::put_value(Item *value)
318318
DBUG_RETURN(FALSE);
319319

320320
err:
321+
cache_table->file->print_error(error, MYF(0));
322+
err2:
321323
disable_cache();
322324
DBUG_RETURN(TRUE);
323325
}

sql/sql_select.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22353,7 +22353,7 @@ bool open_tmp_table(TABLE *table)
2235322353

2235422354
RETURN
2235522355
FALSE - OK
22356-
TRUE - Error
22356+
TRUE - Error. my_error() have been called
2235722357
*/
2235822358

2235922359

@@ -22569,7 +22569,7 @@ bool create_internal_tmp_table(TABLE *table, KEY *org_keyinfo,
2256922569

2257022570
RETURN
2257122571
FALSE - OK
22572-
TRUE - Error
22572+
TRUE - Error ; my_error() has been called.
2257322573
*/
2257422574

2257522575
/* Create internal MyISAM temporary table */
@@ -22709,6 +22709,8 @@ bool create_internal_tmp_table(TABLE *table, KEY *org_keyinfo,
2270922709
/*
2271022710
If a HEAP table gets full, create a internal table in MyISAM or Maria
2271122711
and copy all rows to this
22712+
22713+
In case of error, my_error() or handler::print_error() will be called.
2271222714
*/
2271322715

2271422716

0 commit comments

Comments
 (0)