Fixed memory allocation in Unique to not allocate too much memory
This commit is contained in:
parent
7655f05dc2
commit
5f556f11e0
@ -80,15 +80,17 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag)
|
|||||||
(HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) ?
|
(HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) ?
|
||||||
0L : share->base.pack_reclength);
|
0L : share->base.pack_reclength);
|
||||||
x->sortkey= -1; /* No clustering */
|
x->sortkey= -1; /* No clustering */
|
||||||
/* The following should be included even if we are not compiling with
|
|
||||||
USE_RAID as the client must be able to request it! */
|
|
||||||
x->rec_per_key = share->state.rec_per_key_part;
|
x->rec_per_key = share->state.rec_per_key_part;
|
||||||
x->raid_type= share->base.raid_type;
|
|
||||||
x->raid_chunks= share->base.raid_chunks;
|
|
||||||
x->raid_chunksize= share->base.raid_chunksize;
|
|
||||||
x->key_map = share->state.key_map;
|
x->key_map = share->state.key_map;
|
||||||
x->data_file_name = share->data_file_name;
|
x->data_file_name = share->data_file_name;
|
||||||
x->index_file_name = share->index_file_name;
|
x->index_file_name = share->index_file_name;
|
||||||
|
/*
|
||||||
|
The following should be included even if we are not compiling with
|
||||||
|
USE_RAID as the client must be able to request it!
|
||||||
|
*/
|
||||||
|
x->raid_type= share->base.raid_type;
|
||||||
|
x->raid_chunks= share->base.raid_chunks;
|
||||||
|
x->raid_chunksize= share->base.raid_chunksize;
|
||||||
}
|
}
|
||||||
if ((flag & HA_STATUS_TIME) && !my_fstat(info->dfile,&state,MYF(0)))
|
if ((flag & HA_STATUS_TIME) && !my_fstat(info->dfile,&state,MYF(0)))
|
||||||
x->update_time=state.st_mtime;
|
x->update_time=state.st_mtime;
|
||||||
|
@ -90,6 +90,11 @@ void init_tree(TREE *tree, uint default_alloc_size, uint memory_limit,
|
|||||||
if (!free_element && size >= 0 &&
|
if (!free_element && size >= 0 &&
|
||||||
((uint) size <= sizeof(void*) || ((uint) size & (sizeof(void*)-1))))
|
((uint) size <= sizeof(void*) || ((uint) size & (sizeof(void*)-1))))
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
We know that the data doesn't have to be aligned (like if the key
|
||||||
|
contains a double), so we can store the data combined with the
|
||||||
|
TREE_ELEMENT.
|
||||||
|
*/
|
||||||
tree->offset_to_key=sizeof(TREE_ELEMENT); /* Put key after element */
|
tree->offset_to_key=sizeof(TREE_ELEMENT); /* Put key after element */
|
||||||
/* Fix allocation size so that we don't lose any memory */
|
/* Fix allocation size so that we don't lose any memory */
|
||||||
default_alloc_size/=(sizeof(TREE_ELEMENT)+size);
|
default_alloc_size/=(sizeof(TREE_ELEMENT)+size);
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
Read packets are reallocated dynamicly when reading big packets.
|
Read packets are reallocated dynamicly when reading big packets.
|
||||||
Each logical packet has the following pre-info:
|
Each logical packet has the following pre-info:
|
||||||
3 byte length & 1 byte package-number.
|
3 byte length & 1 byte package-number.
|
||||||
|
|
||||||
|
This file needs to be written in C as it's used by the libmysql client as a
|
||||||
|
C file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __WIN__
|
#ifdef __WIN__
|
||||||
|
@ -781,11 +781,12 @@ class Unique :public Sql_alloc
|
|||||||
TREE tree;
|
TREE tree;
|
||||||
byte *record_pointers;
|
byte *record_pointers;
|
||||||
bool flush();
|
bool flush();
|
||||||
|
uint size;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ulong elements;
|
ulong elements;
|
||||||
Unique(qsort_cmp2 comp_func, void * comp_func_fixed_arg,
|
Unique(qsort_cmp2 comp_func, void * comp_func_fixed_arg,
|
||||||
uint size, ulong max_in_memory_size_arg);
|
uint size_arg, ulong max_in_memory_size_arg);
|
||||||
~Unique();
|
~Unique();
|
||||||
inline bool unique_add(gptr ptr)
|
inline bool unique_add(gptr ptr)
|
||||||
{
|
{
|
||||||
@ -800,26 +801,27 @@ public:
|
|||||||
friend int unique_write_to_ptrs(gptr key, element_count count, Unique *unique);
|
friend int unique_write_to_ptrs(gptr key, element_count count, Unique *unique);
|
||||||
};
|
};
|
||||||
|
|
||||||
class multi_delete : public select_result {
|
class multi_delete : public select_result
|
||||||
TABLE_LIST *delete_tables, *table_being_deleted;
|
{
|
||||||
Unique **tempfiles;
|
TABLE_LIST *delete_tables, *table_being_deleted;
|
||||||
THD *thd;
|
Unique **tempfiles;
|
||||||
ha_rows deleted;
|
THD *thd;
|
||||||
uint num_of_tables;
|
ha_rows deleted;
|
||||||
int error;
|
uint num_of_tables;
|
||||||
bool do_delete, transactional_tables, log_delayed, normal_tables;
|
int error;
|
||||||
public:
|
bool do_delete, transactional_tables, log_delayed, normal_tables;
|
||||||
multi_delete(THD *thd, TABLE_LIST *dt, uint num_of_tables);
|
public:
|
||||||
~multi_delete();
|
multi_delete(THD *thd, TABLE_LIST *dt, uint num_of_tables);
|
||||||
int prepare(List<Item> &list);
|
~multi_delete();
|
||||||
bool send_fields(List<Item> &list,
|
int prepare(List<Item> &list);
|
||||||
|
bool send_fields(List<Item> &list,
|
||||||
uint flag) { return 0; }
|
uint flag) { return 0; }
|
||||||
bool send_data(List<Item> &items);
|
bool send_data(List<Item> &items);
|
||||||
bool initialize_tables (JOIN *join);
|
bool initialize_tables (JOIN *join);
|
||||||
void send_error(uint errcode,const char *err);
|
void send_error(uint errcode,const char *err);
|
||||||
int do_deletes (bool from_send_error);
|
int do_deletes (bool from_send_error);
|
||||||
bool send_eof();
|
bool send_eof();
|
||||||
};
|
};
|
||||||
|
|
||||||
class multi_update : public select_result
|
class multi_update : public select_result
|
||||||
{
|
{
|
||||||
|
@ -49,8 +49,8 @@ int unique_write_to_ptrs(gptr key, element_count count, Unique *unique)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Unique::Unique(qsort_cmp2 comp_func, void * comp_func_fixed_arg,
|
Unique::Unique(qsort_cmp2 comp_func, void * comp_func_fixed_arg,
|
||||||
uint size, ulong max_in_memory_size_arg)
|
uint size_arg, ulong max_in_memory_size_arg)
|
||||||
:max_in_memory_size(max_in_memory_size_arg),elements(0)
|
:max_in_memory_size(max_in_memory_size_arg), size(size_arg), elements(0)
|
||||||
{
|
{
|
||||||
my_b_clear(&file);
|
my_b_clear(&file);
|
||||||
init_tree(&tree, max_in_memory_size / 16, 0, size, comp_func, 0, NULL,
|
init_tree(&tree, max_in_memory_size / 16, 0, size, comp_func, 0, NULL,
|
||||||
@ -101,7 +101,7 @@ bool Unique::get(TABLE *table)
|
|||||||
{
|
{
|
||||||
/* Whole tree is in memory; Don't use disk if you don't need to */
|
/* Whole tree is in memory; Don't use disk if you don't need to */
|
||||||
if ((record_pointers=table->record_pointers= (byte*)
|
if ((record_pointers=table->record_pointers= (byte*)
|
||||||
my_malloc(tree.size_of_element * tree.elements_in_tree, MYF(0))))
|
my_malloc(size * tree.elements_in_tree, MYF(0))))
|
||||||
{
|
{
|
||||||
(void) tree_walk(&tree, (tree_walk_action) unique_write_to_ptrs,
|
(void) tree_walk(&tree, (tree_walk_action) unique_write_to_ptrs,
|
||||||
this, left_root_right);
|
this, left_root_right);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user