Commit e65ddf3f authored by monty@mashka.mysql.fi's avatar monty@mashka.mysql.fi

Try to optimize the cache buffer size needed for bulk_insert

Fix for shutdown on Mac OS X
parent f9e6ae6f
...@@ -76,6 +76,8 @@ int tree_walk(TREE *tree,tree_walk_action action, ...@@ -76,6 +76,8 @@ int tree_walk(TREE *tree,tree_walk_action action,
void *argument, TREE_WALK visit); void *argument, TREE_WALK visit);
int tree_delete(TREE *tree,void *key); int tree_delete(TREE *tree,void *key);
#define TREE_ELEMENT_EXTRA_SIZE (sizeof(TREE_ELEMENT) + sizeof(void*))
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -842,8 +842,9 @@ int _mi_init_bulk_insert(MI_INFO *info, ulong cache_size) ...@@ -842,8 +842,9 @@ int _mi_init_bulk_insert(MI_INFO *info, ulong cache_size)
{ {
params->info=info; params->info=info;
params->keynr=i; params->keynr=i;
/* Only allocate a 16'th of the buffer at a time */
init_tree(&info->bulk_insert[i], init_tree(&info->bulk_insert[i],
cache_size / num_keys / 4 + 10, cache_size / num_keys / 16 + 10,
cache_size / num_keys, 0, cache_size / num_keys, 0,
(qsort_cmp2)keys_compare, 0, (qsort_cmp2)keys_compare, 0,
(tree_element_free) keys_free, (void *)params++); (tree_element_free) keys_free, (void *)params++);
......
...@@ -133,11 +133,11 @@ id parent_id level ...@@ -133,11 +133,11 @@ id parent_id level
1202 107 2 1202 107 2
1204 107 2 1204 107 2
update ignore t1 set id=1023 where id=1010; update ignore t1 set id=1023 where id=1010;
select * from t1 where parent_id=102; select * from t1 where parent_id=102 order by parent_id,id;
id parent_id level id parent_id level
1008 102 2 1008 102 2
1015 102 2
1010 102 2 1010 102 2
1015 102 2
explain select level from t1 where level=1; explain select level from t1 where level=1;
table type possible_keys key key_len ref rows Extra table type possible_keys key key_len ref rows Extra
t1 ref level level 1 const 1 Using where; Using index t1 ref level level 1 const 1 Using where; Using index
......
...@@ -39,7 +39,7 @@ select * from t1; ...@@ -39,7 +39,7 @@ select * from t1;
update ignore t1 set id=id+1; # This will change all rows update ignore t1 set id=id+1; # This will change all rows
select * from t1; select * from t1;
update ignore t1 set id=1023 where id=1010; update ignore t1 set id=1023 where id=1010;
select * from t1 where parent_id=102; select * from t1 where parent_id=102 order by parent_id,id;
explain select level from t1 where level=1; explain select level from t1 where level=1;
explain select level,id from t1 where level=1; explain select level,id from t1 where level=1;
explain select level,id,parent_id from t1 where level=1; explain select level,id,parent_id from t1 where level=1;
......
...@@ -45,7 +45,8 @@ ...@@ -45,7 +45,8 @@
#define BLACK 1 #define BLACK 1
#define RED 0 #define RED 0
#define DEFAULT_ALLOC_SIZE (8192-MALLOC_OVERHEAD) #define DEFAULT_ALLOC_SIZE 8192
#define DEFAULT_ALIGN_SIZE 8192
static void delete_tree_element(TREE *,TREE_ELEMENT *); static void delete_tree_element(TREE *,TREE_ELEMENT *);
static int tree_walk_left_root_right(TREE *,TREE_ELEMENT *, static int tree_walk_left_root_right(TREE *,TREE_ELEMENT *,
...@@ -72,8 +73,9 @@ void init_tree(TREE *tree, uint default_alloc_size, uint memory_limit, ...@@ -72,8 +73,9 @@ void init_tree(TREE *tree, uint default_alloc_size, uint memory_limit,
DBUG_ENTER("init_tree"); DBUG_ENTER("init_tree");
DBUG_PRINT("enter",("tree: %lx size: %d",tree,size)); DBUG_PRINT("enter",("tree: %lx size: %d",tree,size));
if (!default_alloc_size) if (default_alloc_size < DEFAULT_ALLOC_SIZE)
default_alloc_size= DEFAULT_ALLOC_SIZE; default_alloc_size= DEFAULT_ALLOC_SIZE;
default_alloc_size= MY_ALIGN(default_alloc_size, DEFAULT_ALIGN_SIZE);
bzero((gptr) &tree->null_element,sizeof(tree->null_element)); bzero((gptr) &tree->null_element,sizeof(tree->null_element));
tree->root= &tree->null_element; tree->root= &tree->null_element;
tree->compare=compare; tree->compare=compare;
......
...@@ -83,6 +83,7 @@ char* query_table_status(THD *thd,const char *db,const char *table_name); ...@@ -83,6 +83,7 @@ char* query_table_status(THD *thd,const char *db,const char *table_name);
*/ */
#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (16L*1024*1024) #define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (16L*1024*1024)
#define MIN_ROWS_TO_USE_TABLE_CACHE 100 #define MIN_ROWS_TO_USE_TABLE_CACHE 100
#define MIN_ROWS_TO_USE_BULK_INSERT 100
/* /*
The following is used to decide if MySQL should use table scanning The following is used to decide if MySQL should use table scanning
...@@ -707,7 +708,7 @@ bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list); ...@@ -707,7 +708,7 @@ bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
/* old unireg functions */ /* old unireg functions */
void unireg_init(ulong options); void unireg_init(ulong options);
void unireg_end(int signal); void unireg_end(void);
int rea_create_table(my_string file_name,HA_CREATE_INFO *create_info, int rea_create_table(my_string file_name,HA_CREATE_INFO *create_info,
List<create_field> &create_field, List<create_field> &create_field,
uint key_count,KEY *key_info); uint key_count,KEY *key_info);
......
...@@ -764,7 +764,7 @@ static void __cdecl kill_server(int sig_ptr) ...@@ -764,7 +764,7 @@ static void __cdecl kill_server(int sig_ptr)
if (sig != MYSQL_KILL_SIGNAL && sig != 0) if (sig != MYSQL_KILL_SIGNAL && sig != 0)
unireg_abort(1); /* purecov: inspected */ unireg_abort(1); /* purecov: inspected */
else else
unireg_end(0); unireg_end();
pthread_exit(0); /* purecov: deadcode */ pthread_exit(0); /* purecov: deadcode */
RETURN_FROM_KILL_SERVER; RETURN_FROM_KILL_SERVER;
} }
...@@ -803,12 +803,29 @@ extern "C" sig_handler print_signal_warning(int sig) ...@@ -803,12 +803,29 @@ extern "C" sig_handler print_signal_warning(int sig)
#endif #endif
} }
/*
cleanup all memory and end program nicely
SYNOPSIS
unireg_end()
NOTES
This function never returns.
If SIGNALS_DONT_BREAK_READ is defined, this function is called
by the main thread. To get MySQL to shut down nicely in this case
(Mac OS X) we have to call exit() instead if pthread_exit().
*/
void unireg_end(int signal_number __attribute__((unused))) void unireg_end(void)
{ {
clean_up(); clean_up();
my_thread_end(); my_thread_end();
#ifdef SIGNALS_DONT_BREAK_READ
exit(0);
#else
pthread_exit(0); // Exit is in main thread pthread_exit(0); // Exit is in main thread
#endif
} }
......
...@@ -194,15 +194,19 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields, ...@@ -194,15 +194,19 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields,
thd->proc_info="update"; thd->proc_info="update";
if (duplic == DUP_IGNORE || duplic == DUP_REPLACE) if (duplic == DUP_IGNORE || duplic == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
if ((bulk_insert= (values_list.elements > 1 && if ((bulk_insert= (values_list.elements >= MIN_ROWS_TO_USE_BULK_INSERT &&
lock_type != TL_WRITE_DELAYED && lock_type != TL_WRITE_DELAYED &&
!(specialflag & SPECIAL_SAFE_MODE)))) !(specialflag & SPECIAL_SAFE_MODE))))
{ {
table->file->extra_opt(HA_EXTRA_WRITE_CACHE, table->file->extra_opt(HA_EXTRA_WRITE_CACHE,
thd->variables.read_buff_size); min(thd->variables.read_buff_size,
table->avg_row_length*values_list.elements));
if (thd->variables.bulk_insert_buff_size) if (thd->variables.bulk_insert_buff_size)
table->file->extra_opt(HA_EXTRA_BULK_INSERT_BEGIN, table->file->extra_opt(HA_EXTRA_BULK_INSERT_BEGIN,
thd->variables.bulk_insert_buff_size); min(thd->variables.bulk_insert_buff_size,
(table->total_key_length +
table->keys * TREE_ELEMENT_EXTRA_SIZE)*
values_list.elements));
table->bulk_insert= 1; table->bulk_insert= 1;
} }
......
...@@ -3107,12 +3107,13 @@ ident: ...@@ -3107,12 +3107,13 @@ ident:
IDENT { $$=$1; } IDENT { $$=$1; }
| keyword | keyword
{ {
LEX *lex; LEX *lex= Lex;
$$.str=sql_strmake($1.str,$1.length); $$.str= lex->thd->strmake($1.str,$1.length);
$$.length=$1.length; $$.length=$1.length;
if ((lex=Lex)->next_state != STATE_END) if (lex->next_state != STATE_END)
lex->next_state=STATE_OPERATOR_OR_IDENT; lex->next_state=STATE_OPERATOR_OR_IDENT;
}; }
;
ident_or_text: ident_or_text:
ident { $$=$1;} ident { $$=$1;}
......
...@@ -143,7 +143,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, ...@@ -143,7 +143,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
goto err_not_open; /* purecov: inspected */ goto err_not_open; /* purecov: inspected */
bzero((char*) keyinfo,n_length); bzero((char*) keyinfo,n_length);
outparam->key_info=keyinfo; outparam->key_info=keyinfo;
outparam->max_key_length=0; outparam->max_key_length= outparam->total_key_length= 0;
key_part= (KEY_PART_INFO*) (keyinfo+keys); key_part= (KEY_PART_INFO*) (keyinfo+keys);
strpos=disk_buff+6; strpos=disk_buff+6;
...@@ -201,6 +201,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, ...@@ -201,6 +201,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
} }
set_if_bigger(outparam->max_key_length,keyinfo->key_length+ set_if_bigger(outparam->max_key_length,keyinfo->key_length+
keyinfo->key_parts); keyinfo->key_parts);
outparam->total_key_length+= keyinfo->key_length;
if (keyinfo->flags & HA_NOSAME) if (keyinfo->flags & HA_NOSAME)
set_if_bigger(outparam->max_unique_length,keyinfo->key_length); set_if_bigger(outparam->max_unique_length,keyinfo->key_length);
} }
......
...@@ -58,6 +58,7 @@ struct st_table { ...@@ -58,6 +58,7 @@ struct st_table {
uint reclength; /* Recordlength */ uint reclength; /* Recordlength */
uint rec_buff_length; uint rec_buff_length;
uint keys,key_parts,primary_key,max_key_length,max_unique_length; uint keys,key_parts,primary_key,max_key_length,max_unique_length;
uint total_key_length;
uint uniques; uint uniques;
uint null_fields; /* number of null fields */ uint null_fields; /* number of null fields */
uint blob_fields; /* number of blob fields */ uint blob_fields; /* number of blob fields */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment