summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2015-11-18 23:54:01 +0400
committerSergey Vojtovich <svoj@mariadb.org>2015-11-26 11:34:16 +0400
commit753d1f868c0fd52c2ec44a97fe116c01a38d5ffd (patch)
tree15334b9db1e7dbba85c4486ec93c47f0dee59478 /sql
parent0746a0770867b621cb4fee08239419bec69a2de8 (diff)
downloadmariadb-git-753d1f868c0fd52c2ec44a97fe116c01a38d5ffd.tar.gz
MDEV-8716 - Obsolete sql_calloc() in favor of THD::calloc() and thd_calloc()
Diffstat (limited to 'sql')
-rw-r--r--sql/item.h5
-rw-r--r--sql/item_buff.cc2
-rw-r--r--sql/item_cmpfunc.cc29
-rw-r--r--sql/item_cmpfunc.h17
-rw-r--r--sql/partition_info.cc25
-rw-r--r--sql/partition_info.h12
-rw-r--r--sql/sql_partition.cc29
-rw-r--r--sql/sql_statistics.cc7
-rw-r--r--sql/thr_malloc.cc9
-rw-r--r--sql/thr_malloc.h1
10 files changed, 66 insertions, 70 deletions
diff --git a/sql/item.h b/sql/item.h
index 88cdca67a02..5c377c7f998 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -25,7 +25,6 @@
#include "sql_priv.h" /* STRING_BUFFER_USUAL_SIZE */
#include "unireg.h"
#include "sql_const.h" /* RAND_TABLE_BIT, MAX_FIELD_NAME */
-#include "thr_malloc.h" /* sql_calloc */
#include "field.h" /* Derivation */
#include "sql_type.h"
@@ -4790,11 +4789,11 @@ class Cached_item_field :public Cached_item
uint length;
public:
- Cached_item_field(Field *arg_field) : field(arg_field)
+ Cached_item_field(THD *thd, Field *arg_field): field(arg_field)
{
field= arg_field;
/* TODO: take the memory allocation below out of the constructor. */
- buff= (uchar*) sql_calloc(length=field->pack_length());
+ buff= (uchar*) thd_calloc(thd, length= field->pack_length());
}
bool cmp(void);
};
diff --git a/sql/item_buff.cc b/sql/item_buff.cc
index d1134525f7b..62c2f76dc2e 100644
--- a/sql/item_buff.cc
+++ b/sql/item_buff.cc
@@ -43,7 +43,7 @@ Cached_item *new_Cached_item(THD *thd, Item *item, bool pass_through_ref)
{
Item_field *real_item= (Item_field *) item->real_item();
Field *cached_field= real_item->field;
- return new Cached_item_field(cached_field);
+ return new (thd->mem_root) Cached_item_field(thd, cached_field);
}
switch (item->result_type()) {
case STRING_RESULT:
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index c968ff6f65e..76b8b70ed98 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -3452,8 +3452,9 @@ int in_vector::find(Item *item)
return (int) ((*compare)(collation, base+start*size, result) == 0);
}
-in_string::in_string(uint elements,qsort2_cmp cmp_func, CHARSET_INFO *cs)
- :in_vector(elements, sizeof(String), cmp_func, cs),
+in_string::in_string(THD *thd, uint elements, qsort2_cmp cmp_func,
+ CHARSET_INFO *cs)
+ :in_vector(thd, elements, sizeof(String), cmp_func, cs),
tmp(buff, sizeof(buff), &my_charset_bin)
{}
@@ -3536,8 +3537,9 @@ void in_row::set(uint pos, Item *item)
DBUG_VOID_RETURN;
}
-in_longlong::in_longlong(uint elements)
- :in_vector(elements,sizeof(packed_longlong),(qsort2_cmp) cmp_longlong, 0)
+in_longlong::in_longlong(THD *thd, uint elements)
+ :in_vector(thd, elements, sizeof(packed_longlong),
+ (qsort2_cmp) cmp_longlong, 0)
{}
void in_longlong::set(uint pos,Item *item)
@@ -3594,8 +3596,8 @@ Item *in_datetime::create_item(THD *thd)
}
-in_double::in_double(uint elements)
- :in_vector(elements,sizeof(double),(qsort2_cmp) cmp_double, 0)
+in_double::in_double(THD *thd, uint elements)
+ :in_vector(thd, elements, sizeof(double), (qsort2_cmp) cmp_double, 0)
{}
void in_double::set(uint pos,Item *item)
@@ -3617,8 +3619,8 @@ Item *in_double::create_item(THD *thd)
}
-in_decimal::in_decimal(uint elements)
- :in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
+in_decimal::in_decimal(THD *thd, uint elements)
+ :in_vector(thd, elements, sizeof(my_decimal), (qsort2_cmp) cmp_decimal, 0)
{}
@@ -4063,14 +4065,15 @@ void Item_func_in::fix_length_and_dec()
}
switch (m_compare_type) {
case STRING_RESULT:
- array=new (thd->mem_root) in_string(arg_count-1,(qsort2_cmp) srtcmp_in,
+ array=new (thd->mem_root) in_string(thd, arg_count - 1,
+ (qsort2_cmp) srtcmp_in,
cmp_collation.collation);
break;
case INT_RESULT:
- array= new (thd->mem_root) in_longlong(arg_count-1);
+ array= new (thd->mem_root) in_longlong(thd, arg_count - 1);
break;
case REAL_RESULT:
- array= new (thd->mem_root) in_double(arg_count-1);
+ array= new (thd->mem_root) in_double(thd, arg_count - 1);
break;
case ROW_RESULT:
/*
@@ -4081,11 +4084,11 @@ void Item_func_in::fix_length_and_dec()
((in_row*)array)->tmp.store_value(args[0]);
break;
case DECIMAL_RESULT:
- array= new (thd->mem_root) in_decimal(arg_count - 1);
+ array= new (thd->mem_root) in_decimal(thd, arg_count - 1);
break;
case TIME_RESULT:
date_arg= find_date_time_item(args, arg_count, 0);
- array= new (thd->mem_root) in_datetime(date_arg, arg_count - 1);
+ array= new (thd->mem_root) in_datetime(thd, date_arg, arg_count - 1);
break;
}
if (array && !(thd->is_fatal_error)) // If not EOM
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index e06d93f4b86..f04460a12bc 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -23,7 +23,6 @@
#pragma interface /* gcc class implementation */
#endif
-#include "thr_malloc.h" /* sql_calloc */
#include "item_func.h" /* Item_int_func, Item_bool_func */
#define PCRE_STATIC 1 /* Important on Windows */
#include "pcre.h" /* pcre header file */
@@ -1041,9 +1040,9 @@ public:
uint count;
uint used_count;
in_vector() {}
- in_vector(uint elements,uint element_length,qsort2_cmp cmp_func,
+ in_vector(THD *thd, uint elements, uint element_length, qsort2_cmp cmp_func,
CHARSET_INFO *cmp_coll)
- :base((char*) sql_calloc(elements*element_length)),
+ :base((char*) thd_calloc(thd, elements * element_length)),
size(element_length), compare(cmp_func), collation(cmp_coll),
count(elements), used_count(elements) {}
virtual ~in_vector() {}
@@ -1100,7 +1099,7 @@ class in_string :public in_vector
}
};
public:
- in_string(uint elements,qsort2_cmp cmp_func, CHARSET_INFO *cs);
+ in_string(THD *thd, uint elements, qsort2_cmp cmp_func, CHARSET_INFO *cs);
~in_string();
void set(uint pos,Item *item);
uchar *get_value(Item *item);
@@ -1128,7 +1127,7 @@ protected:
longlong unsigned_flag; // Use longlong, not bool, to preserve alignment
} tmp;
public:
- in_longlong(uint elements);
+ in_longlong(THD *thd, uint elements);
void set(uint pos,Item *item);
uchar *get_value(Item *item);
Item* create_item(THD *thd);
@@ -1159,8 +1158,8 @@ public:
/* Cache for the left item. */
Item *lval_cache;
- in_datetime(Item *warn_item_arg, uint elements)
- :in_longlong(elements), thd(current_thd), warn_item(warn_item_arg),
+ in_datetime(THD *thd, Item *warn_item_arg, uint elements)
+ :in_longlong(thd, elements), thd(current_thd), warn_item(warn_item_arg),
lval_cache(0) {};
void set(uint pos,Item *item);
uchar *get_value(Item *item);
@@ -1179,7 +1178,7 @@ class in_double :public in_vector
{
double tmp;
public:
- in_double(uint elements);
+ in_double(THD *thd, uint elements);
void set(uint pos,Item *item);
uchar *get_value(Item *item);
Item *create_item(THD *thd);
@@ -1195,7 +1194,7 @@ class in_decimal :public in_vector
{
my_decimal val;
public:
- in_decimal(uint elements);
+ in_decimal(THD *thd, uint elements);
void set(uint pos, Item *item);
uchar *get_value(Item *item);
Item *create_item(THD *thd);
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index 36bb2513c9b..43a00607fe6 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -547,11 +547,11 @@ err:
#define MAX_PART_NAME_SIZE 8
-char *partition_info::create_default_partition_names(uint part_no,
+char *partition_info::create_default_partition_names(THD *thd, uint part_no,
uint num_parts_arg,
uint start_no)
{
- char *ptr= (char*) sql_calloc(num_parts_arg*MAX_PART_NAME_SIZE);
+ char *ptr= (char*) thd->calloc(num_parts_arg * MAX_PART_NAME_SIZE);
char *move_ptr= ptr;
uint i= 0;
DBUG_ENTER("create_default_partition_names");
@@ -620,11 +620,11 @@ void partition_info::set_show_version_string(String *packet)
0 Memory allocation error
*/
-char *partition_info::create_default_subpartition_name(uint subpart_no,
+char *partition_info::create_default_subpartition_name(THD *thd, uint subpart_no,
const char *part_name)
{
uint size_alloc= strlen(part_name) + MAX_PART_NAME_SIZE;
- char *ptr= (char*) sql_calloc(size_alloc);
+ char *ptr= (char*) thd->calloc(size_alloc);
DBUG_ENTER("create_default_subpartition_name");
if (likely(ptr != NULL))
@@ -663,7 +663,7 @@ char *partition_info::create_default_subpartition_name(uint subpart_no,
The external routine needing this code is check_partition_info
*/
-bool partition_info::set_up_default_partitions(handler *file,
+bool partition_info::set_up_default_partitions(THD *thd, handler *file,
HA_CREATE_INFO *info,
uint start_no)
{
@@ -695,7 +695,8 @@ bool partition_info::set_up_default_partitions(handler *file,
my_error(ER_TOO_MANY_PARTITIONS_ERROR, MYF(0));
goto end;
}
- if (unlikely((!(default_name= create_default_partition_names(0, num_parts,
+ if (unlikely((!(default_name= create_default_partition_names(thd, 0,
+ num_parts,
start_no)))))
goto end;
i= 0;
@@ -744,7 +745,7 @@ end:
The external routine needing this code is check_partition_info
*/
-bool partition_info::set_up_default_subpartitions(handler *file,
+bool partition_info::set_up_default_subpartitions(THD *thd, handler *file,
HA_CREATE_INFO *info)
{
uint i, j;
@@ -771,7 +772,7 @@ bool partition_info::set_up_default_subpartitions(handler *file,
if (likely(subpart_elem != 0 &&
(!part_elem->subpartitions.push_back(subpart_elem))))
{
- char *ptr= create_default_subpartition_name(j,
+ char *ptr= create_default_subpartition_name(thd, j,
part_elem->partition_name);
if (!ptr)
goto end;
@@ -809,7 +810,7 @@ end:
this will return an error.
*/
-bool partition_info::set_up_defaults_for_partitioning(handler *file,
+bool partition_info::set_up_defaults_for_partitioning(THD *thd, handler *file,
HA_CREATE_INFO *info,
uint start_no)
{
@@ -819,10 +820,10 @@ bool partition_info::set_up_defaults_for_partitioning(handler *file,
{
default_partitions_setup= TRUE;
if (use_default_partitions)
- DBUG_RETURN(set_up_default_partitions(file, info, start_no));
+ DBUG_RETURN(set_up_default_partitions(thd, file, info, start_no));
if (is_sub_partitioned() &&
use_default_subpartitions)
- DBUG_RETURN(set_up_default_subpartitions(file, info));
+ DBUG_RETURN(set_up_default_subpartitions(thd, file, info));
}
DBUG_RETURN(FALSE);
}
@@ -1702,7 +1703,7 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type,
my_error(ER_SUBPARTITION_ERROR, MYF(0));
goto end;
}
- if (unlikely(set_up_defaults_for_partitioning(file, info, (uint)0)))
+ if (unlikely(set_up_defaults_for_partitioning(thd, file, info, (uint)0)))
goto end;
if (!(tot_partitions= get_tot_partitions()))
{
diff --git a/sql/partition_info.h b/sql/partition_info.h
index c58fa8bef55..5181e19d568 100644
--- a/sql/partition_info.h
+++ b/sql/partition_info.h
@@ -307,7 +307,8 @@ public:
return num_parts * (is_sub_partitioned() ? num_subparts : 1);
}
- bool set_up_defaults_for_partitioning(handler *file, HA_CREATE_INFO *info,
+ bool set_up_defaults_for_partitioning(THD *thd, handler *file,
+ HA_CREATE_INFO *info,
uint start_no);
char *find_duplicate_field();
char *find_duplicate_name();
@@ -371,12 +372,13 @@ public:
bool has_same_partitioning(partition_info *new_part_info);
private:
static int list_part_cmp(const void* a, const void* b);
- bool set_up_default_partitions(handler *file, HA_CREATE_INFO *info,
+ bool set_up_default_partitions(THD *thd, handler *file, HA_CREATE_INFO *info,
uint start_no);
- bool set_up_default_subpartitions(handler *file, HA_CREATE_INFO *info);
- char *create_default_partition_names(uint part_no, uint num_parts,
+ bool set_up_default_subpartitions(THD *thd, handler *file,
+ HA_CREATE_INFO *info);
+ char *create_default_partition_names(THD *thd, uint part_no, uint num_parts,
uint start_no);
- char *create_default_subpartition_name(uint subpart_no,
+ char *create_default_subpartition_name(THD *thd, uint subpart_no,
const char *part_name);
bool prune_partition_bitmaps(TABLE_LIST *table_list);
bool add_named_partition(const char *part_name, uint length);
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 16588871fd8..c155d74b7d8 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -255,7 +255,7 @@ static bool is_name_in_list(char *name, List<char> list_names)
FALSE Success
*/
-bool partition_default_handling(TABLE *table, partition_info *part_info,
+bool partition_default_handling(THD *thd, TABLE *table, partition_info *part_info,
bool is_create_table_ind,
const char *normalized_path)
{
@@ -283,7 +283,7 @@ bool partition_default_handling(TABLE *table, partition_info *part_info,
part_info->num_subparts= num_parts / part_info->num_parts;
}
}
- part_info->set_up_defaults_for_partitioning(table->file,
+ part_info->set_up_defaults_for_partitioning(thd, table->file,
NULL, 0U);
DBUG_RETURN(FALSE);
}
@@ -455,7 +455,7 @@ int get_part_for_delete(const uchar *buf, const uchar *rec0,
function.
*/
-static bool set_up_field_array(TABLE *table,
+static bool set_up_field_array(THD *thd, TABLE *table,
bool is_sub_part)
{
Field **ptr, *field, **field_array;
@@ -492,7 +492,7 @@ static bool set_up_field_array(TABLE *table,
DBUG_RETURN(result);
}
size_field_array= (num_fields+1)*sizeof(Field*);
- field_array= (Field**)sql_calloc(size_field_array);
+ field_array= (Field**) thd->calloc(size_field_array);
if (unlikely(!field_array))
{
mem_alloc_error(size_field_array);
@@ -617,7 +617,7 @@ static bool create_full_part_field_array(THD *thd, TABLE *table,
num_part_fields++;
}
size_field_array= (num_part_fields+1)*sizeof(Field*);
- field_array= (Field**)sql_calloc(size_field_array);
+ field_array= (Field**) thd->calloc(size_field_array);
if (unlikely(!field_array))
{
mem_alloc_error(size_field_array);
@@ -804,7 +804,7 @@ static void clear_field_flag(TABLE *table)
*/
-static bool handle_list_of_fields(List_iterator<char> it,
+static bool handle_list_of_fields(THD *thd, List_iterator<char> it,
TABLE *table,
partition_info *part_info,
bool is_sub_part)
@@ -865,7 +865,7 @@ static bool handle_list_of_fields(List_iterator<char> it,
}
}
}
- result= set_up_field_array(table, is_sub_part);
+ result= set_up_field_array(thd, table, is_sub_part);
end:
DBUG_RETURN(result);
}
@@ -1034,7 +1034,7 @@ static bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
if ((!is_sub_part) && (error= check_signed_flag(part_info)))
goto end;
- result= set_up_field_array(table, is_sub_part);
+ result= set_up_field_array(thd, table, is_sub_part);
end:
end_lex_with_single_table(thd, table, old_lex);
#if !defined(DBUG_OFF)
@@ -1622,7 +1622,7 @@ bool fix_partition_func(THD *thd, TABLE *table,
if (!is_create_table_ind ||
thd->lex->sql_command != SQLCOM_CREATE_TABLE)
{
- if (partition_default_handling(table, part_info,
+ if (partition_default_handling(thd, table, part_info,
is_create_table_ind,
table->s->normalized_path.str))
{
@@ -1641,7 +1641,7 @@ bool fix_partition_func(THD *thd, TABLE *table,
if (part_info->list_of_subpart_fields)
{
List_iterator<char> it(part_info->subpart_field_list);
- if (unlikely(handle_list_of_fields(it, table, part_info, TRUE)))
+ if (unlikely(handle_list_of_fields(thd, it, table, part_info, TRUE)))
goto end;
}
else
@@ -1668,7 +1668,7 @@ bool fix_partition_func(THD *thd, TABLE *table,
if (part_info->list_of_part_fields)
{
List_iterator<char> it(part_info->part_field_list);
- if (unlikely(handle_list_of_fields(it, table, part_info, FALSE)))
+ if (unlikely(handle_list_of_fields(thd, it, table, part_info, FALSE)))
goto end;
}
else
@@ -1690,7 +1690,7 @@ bool fix_partition_func(THD *thd, TABLE *table,
if (part_info->column_list)
{
List_iterator<char> it(part_info->part_field_list);
- if (unlikely(handle_list_of_fields(it, table, part_info, FALSE)))
+ if (unlikely(handle_list_of_fields(thd, it, table, part_info, FALSE)))
goto end;
}
else
@@ -4976,7 +4976,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
}
alt_part_info->part_type= tab_part_info->part_type;
alt_part_info->subpart_type= tab_part_info->subpart_type;
- if (alt_part_info->set_up_defaults_for_partitioning(table->file, 0,
+ if (alt_part_info->set_up_defaults_for_partitioning(thd, table->file, 0,
tab_part_info->num_parts))
{
goto err;
@@ -5395,7 +5395,8 @@ state of p1.
DBUG_ASSERT(!alt_part_info->use_default_partitions);
/* We specified partitions explicitly so don't use defaults anymore. */
tab_part_info->use_default_partitions= FALSE;
- if (alt_part_info->set_up_defaults_for_partitioning(table->file, 0, 0))
+ if (alt_part_info->set_up_defaults_for_partitioning(thd, table->file, 0,
+ 0))
{
goto err;
}
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc
index 28e76ae43f1..a13ffc3eae1 100644
--- a/sql/sql_statistics.cc
+++ b/sql/sql_statistics.cc
@@ -1656,7 +1656,7 @@ public:
bool is_single_comp_pk;
- Index_prefix_calc(TABLE *table, KEY *key_info)
+ Index_prefix_calc(THD *thd, TABLE *table, KEY *key_info)
: index_table(table), index_info(key_info)
{
uint i;
@@ -1691,7 +1691,8 @@ public:
break;
if (!(state->last_prefix=
- new Cached_item_field(key_info->key_part[i].field)))
+ new (thd->mem_root) Cached_item_field(thd,
+ key_info->key_part[i].field)))
break;
state->entry_count= state->prefix_count= 0;
prefixes++;
@@ -2475,7 +2476,7 @@ int collect_statistics_for_index(THD *thd, TABLE *table, uint index)
if (key_info->flags & HA_FULLTEXT)
DBUG_RETURN(rc);
- Index_prefix_calc index_prefix_calc(table, key_info);
+ Index_prefix_calc index_prefix_calc(thd, table, key_info);
DEBUG_SYNC(table->in_use, "statistics_collection_start1");
DEBUG_SYNC(table->in_use, "statistics_collection_start2");
diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc
index 10fc5b83a1b..e722b5a21a5 100644
--- a/sql/thr_malloc.cc
+++ b/sql/thr_malloc.cc
@@ -75,15 +75,6 @@ void *sql_alloc(size_t Size)
#endif
-void *sql_calloc(size_t size)
-{
- void *ptr;
- if ((ptr=sql_alloc(size)))
- bzero(ptr,size);
- return ptr;
-}
-
-
char *sql_strmake_with_convert(const char *str, size_t arg_length,
CHARSET_INFO *from_cs,
size_t max_res_length,
diff --git a/sql/thr_malloc.h b/sql/thr_malloc.h
index 4eb1e66d970..d35207c655a 100644
--- a/sql/thr_malloc.h
+++ b/sql/thr_malloc.h
@@ -23,7 +23,6 @@ typedef struct st_mem_root MEM_ROOT;
void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size,
myf my_flags);
void *sql_alloc(size_t);
-void *sql_calloc(size_t);
char *sql_strmake_with_convert(const char *str, size_t arg_length,
CHARSET_INFO *from_cs,
size_t max_res_length,