summaryrefslogtreecommitdiff
path: root/sql/uniques.cc
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2020-06-03 11:56:50 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2020-06-03 13:47:30 +0530
commite900c63f78e6368932d069650ad2ba2bd7e8a3df (patch)
tree16ce9350f3fff6e4932ba58730d0aa819e63148d /sql/uniques.cc
parente485ac2b6014b2b6b521870e04d9f16a18630e31 (diff)
downloadmariadb-git-10.1-mdev22715.tar.gz
MDEV-22728: SIGFPE in Unique::get_cost_calc_buff_size from prepare_search_best_index_intersect on optimized builds10.1-mdev22715
For low sort_buffer_size, in the cost calculation of using the Unique object the elements in the tree were evaluated to 0, make sure to have atleast 1 element in the Unique tree. Also for the function Unique::get allocate memory for atleast MERGEBUFF2+1 keys.
Diffstat (limited to 'sql/uniques.cc')
-rw-r--r--sql/uniques.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/sql/uniques.cc b/sql/uniques.cc
index 03f25d31384..b9cb50543e2 100644
--- a/sql/uniques.cc
+++ b/sql/uniques.cc
@@ -317,6 +317,9 @@ double Unique::get_use_cost(uint *buffer, size_t nkeys, uint key_size,
max_elements_in_tree= ((size_t) max_in_memory_size /
ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
+ if (max_elements_in_tree == 0)
+ max_elements_in_tree= 1;
+
n_full_trees= nkeys / max_elements_in_tree;
last_tree_elems= nkeys % max_elements_in_tree;
@@ -781,7 +784,13 @@ bool Unique::get(TABLE *table)
/* Not enough memory; Save the result to file && free memory used by tree */
if (flush())
return 1;
- size_t buff_sz= (max_in_memory_size / full_size + 1) * full_size;
+
+ /*
+ merge_buffer must fit at least MERGEBUFF2 + 1 keys, because
+ merge_index() can merge that many BUFFPEKs at once. The extra space for
+ one key for Sort_param::unique_buff
+ */
+ size_t buff_sz= MY_MAX(MERGEBUFF2+1, max_in_memory_size/full_size+1) * full_size;
if (!(sort_buffer= (uchar*) my_malloc(buff_sz, MYF(MY_THREAD_SPECIFIC|MY_WME))))
return 1;