diff options
author | Mithun C Y <mithun.c.y@oracle.com> | 2015-02-25 11:44:19 +0530 |
---|---|---|
committer | Mithun C Y <mithun.c.y@oracle.com> | 2015-02-25 11:44:19 +0530 |
commit | 2e3c2cd3625598d6de940b51675dd6a979676ed9 (patch) | |
tree | 5352b7e97fc2c84261c0ca33f643b516f99e43a9 /sql/filesort.cc | |
parent | cd81a719430d493bdffc8c2132fdad4c351c0f02 (diff) | |
download | mariadb-git-2e3c2cd3625598d6de940b51675dd6a979676ed9.tar.gz |
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.
Diffstat (limited to 'sql/filesort.cc')
-rw-r--r-- | sql/filesort.cc | 9 |
1 files changed, 8 insertions, 1 deletions
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*)); |