From 2e3c2cd3625598d6de940b51675dd6a979676ed9 Mon Sep 17 00:00:00 2001 From: Mithun C Y Date: Wed, 25 Feb 2015 11:44:19 +0530 Subject: 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. --- sql/filesort.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'sql/filesort.cc') diff --git a/sql/filesort.cc b/sql/filesort.cc index 1414be2af45..98900efb0d5 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -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*)); -- cgit v1.2.1