summaryrefslogtreecommitdiff
path: root/sql/item_sum.cc
diff options
context:
space:
mode:
authorMartin Hansson <martin.hansson@sun.com>2009-11-20 13:29:43 +0100
committerMartin Hansson <martin.hansson@sun.com>2009-11-20 13:29:43 +0100
commitca595821498d6a547fa1780df86cdf127b0019b3 (patch)
treefabb9c5fa11cdf96ecdc1297561875b1a58090ed /sql/item_sum.cc
parentb4a3083dc8b8049e64692ffc8e6e527914fb93da (diff)
parent4205c622e1a741bae1b2d8d213342f8e0bdd936a (diff)
downloadmariadb-git-ca595821498d6a547fa1780df86cdf127b0019b3.tar.gz
merge of Bug#33204 (backport)
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r--sql/item_sum.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 273e996a6a0..f72b64fc66e 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -29,6 +29,18 @@
#include "sql_select.h"
/**
+ Calculate the affordable RAM limit for structures like TREE or Unique
+ used in Item_sum_*
+*/
+
+ulonglong Item_sum::ram_limitation(THD *thd)
+{
+ return min(thd->variables.tmp_table_size,
+ thd->variables.max_heap_table_size);
+}
+
+
+/**
Prepare an aggregate function item for checking context conditions.
The function initializes the members of the Item_sum object created
@@ -522,7 +534,8 @@ Field *Item_sum::create_tmp_field(bool group, TABLE *table,
name, table->s, collation.collation);
break;
case DECIMAL_RESULT:
- field= Field_new_decimal::new_decimal_field(this);
+ field= new Field_new_decimal(max_length, maybe_null, name,
+ decimals, unsigned_flag);
break;
case ROW_RESULT:
default:
@@ -832,7 +845,7 @@ bool Aggregator_distinct::setup(THD *thd)
}
DBUG_ASSERT(tree == 0);
tree= new Unique(compare_key, cmp_arg, tree_key_length,
- thd->variables.max_heap_table_size);
+ item_sum->ram_limitation(thd));
/*
The only time tree_key_length could be 0 is if someone does
count(distinct) on a char(0) field - stupid thing to do,
@@ -901,7 +914,7 @@ bool Aggregator_distinct::setup(THD *thd)
are converted to binary representation as well.
*/
tree= new Unique(simple_raw_key_cmp, &tree_key_length, tree_key_length,
- thd->variables.max_heap_table_size);
+ item_sum->ram_limitation(thd));
DBUG_RETURN(tree == 0);
}
@@ -3513,7 +3526,7 @@ bool Item_func_group_concat::setup(THD *thd)
unique_filter= new Unique(group_concat_key_cmp_with_distinct,
(void*)this,
tree_key_length,
- thd->variables.max_heap_table_size);
+ ram_limitation(thd));
DBUG_RETURN(FALSE);
}