Skip to content

Commit 2e3c2cd

Browse files
committed
Bug #20049521: CRASH IN MERGE_BUFFERS FILESORT.C WHEN INNODB WITH ORDER BY.
ISSUE: ------ There can be up to MERGEBUFF2 number of sorted merge chunks, We need enough buffer space for at least one record from each merge chunks. If estimates are wrong(very low) and we allocate buffer space for less than MERGEBUFF2, then we will have issue in merge_buffers, if actual number of rows to be sorted is bigger than estimate and external filesort is chosen. SOLUTION: --------- Set number of rows to sort to be at least MERGEBUFF2.
1 parent cd81a71 commit 2e3c2cd

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

sql/filesort.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -203,6 +203,13 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
203203
const ulong min_sort_memory=
204204
max(MIN_SORT_MEMORY,
205205
ALIGN_SIZE(MERGEBUFF2 * (param.rec_length + sizeof(uchar*))));
206+
/*
207+
Cannot depend on num_rows. For external sort, space for upto MERGEBUFF2
208+
rows is required.
209+
*/
210+
if (num_rows < MERGEBUFF2)
211+
num_rows= MERGEBUFF2;
212+
206213
while (memory_available >= min_sort_memory)
207214
{
208215
ulong keys= memory_available / (param.rec_length + sizeof(char*));

storage/innobase/handler/ha_innodb.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2008, 2009 Google Inc.
55
Copyright (c) 2009, Percona Inc.
66
@@ -7906,6 +7906,13 @@ ha_innobase::estimate_rows_upper_bound(void)
79067906
estimate = 2 * local_data_file_length /
79077907
dict_index_calc_min_rec_len(index);
79087908

7909+
/* Set num_rows less than MERGEBUFF to simulate the case where we do
7910+
not have enough space to merge the externally sorted file blocks. */
7911+
DBUG_EXECUTE_IF("set_num_rows_lt_MERGEBUFF",
7912+
estimate = 2;
7913+
DBUG_SET("-d,set_num_rows_lt_MERGEBUFF");
7914+
);
7915+
79097916
prebuilt->trx->op_info = (char*)"";
79107917

79117918
DBUG_RETURN((ha_rows) estimate);

0 commit comments

Comments
 (0)