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.
This commit is contained in:
Mithun C Y 2015-02-25 11:44:19 +05:30
parent cd81a71943
commit 2e3c2cd362
2 changed files with 16 additions and 2 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
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,
const ulong min_sort_memory=
max(MIN_SORT_MEMORY,
ALIGN_SIZE(MERGEBUFF2 * (param.rec_length + sizeof(uchar*))));
/*
Cannot depend on num_rows. For external sort, space for upto MERGEBUFF2
rows is required.
*/
if (num_rows < MERGEBUFF2)
num_rows= MERGEBUFF2;
while (memory_available >= min_sort_memory)
{
ulong keys= memory_available / (param.rec_length + sizeof(char*));

View file

@ -1,6 +1,6 @@
/*****************************************************************************
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2008, 2009 Google Inc.
Copyright (c) 2009, Percona Inc.
@ -7906,6 +7906,13 @@ ha_innobase::estimate_rows_upper_bound(void)
estimate = 2 * local_data_file_length /
dict_index_calc_min_rec_len(index);
/* Set num_rows less than MERGEBUFF to simulate the case where we do
not have enough space to merge the externally sorted file blocks. */
DBUG_EXECUTE_IF("set_num_rows_lt_MERGEBUFF",
estimate = 2;
DBUG_SET("-d,set_num_rows_lt_MERGEBUFF");
);
prebuilt->trx->op_info = (char*)"";
DBUG_RETURN((ha_rows) estimate);