summaryrefslogtreecommitdiff
path: root/myisam
diff options
context:
space:
mode:
authorunknown <serg@serg.mysql.com>2002-12-07 22:40:20 +0100
committerunknown <serg@serg.mysql.com>2002-12-07 22:40:20 +0100
commit6271ea35b83501781cf3ee51a62fd95870b3fb96 (patch)
treecac4edcace5032716391947982c07af2dba77b24 /myisam
parent23865c0eea7d3d670f4b84a76cbe3511fe241b7f (diff)
downloadmariadb-git-6271ea35b83501781cf3ee51a62fd95870b3fb96.tar.gz
bulk insert code optimized
mysql-test/r/distinct.result: updated mysql-test/r/fulltext.result: updated mysql-test/r/select.result: updated mysql-test/r/show_check.result: updated mysql-test/t/insert.test: updated
Diffstat (limited to 'myisam')
-rw-r--r--myisam/mi_extra.c27
-rw-r--r--myisam/mi_write.c47
-rw-r--r--myisam/myisamdef.h3
3 files changed, 41 insertions, 36 deletions
diff --git a/myisam/mi_extra.c b/myisam/mi_extra.c
index d7a3aea516d..8429b22dad4 100644
--- a/myisam/mi_extra.c
+++ b/myisam/mi_extra.c
@@ -358,33 +358,6 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
case HA_EXTRA_QUICK:
info->quick_mode=1;
break;
- case HA_EXTRA_BULK_INSERT_BEGIN:
- error=_mi_init_bulk_insert(info, (extra_arg ? *(ulong*) extra_arg :
- myisam_bulk_insert_tree_size));
- break;
- case HA_EXTRA_BULK_INSERT_FLUSH:
- if (info->bulk_insert)
- {
- uint index_to_flush= *(uint*) extra_arg;
- if (is_tree_inited(&info->bulk_insert[index_to_flush]))
- reset_tree(&info->bulk_insert[index_to_flush]);
- }
- break;
- case HA_EXTRA_BULK_INSERT_END:
- if (info->bulk_insert)
- {
- uint i;
- for (i=0 ; i < share->base.keys ; i++)
- {
- if (is_tree_inited(& info->bulk_insert[i]))
- {
- delete_tree(& info->bulk_insert[i]);
- }
- }
- my_free((void *)info->bulk_insert, MYF(0));
- info->bulk_insert=0;
- }
- break;
case HA_EXTRA_NO_ROWS:
if (!share->state.header.uniques)
info->opt_flag|= OPT_NO_ROWS;
diff --git a/myisam/mi_write.c b/myisam/mi_write.c
index 70a1bea26bb..d39bbbf5fc7 100644
--- a/myisam/mi_write.c
+++ b/myisam/mi_write.c
@@ -801,26 +801,27 @@ static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param)
}
-int _mi_init_bulk_insert(MI_INFO *info, ulong cache_size)
+int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows)
{
MYISAM_SHARE *share=info->s;
MI_KEYDEF *key=share->keyinfo;
bulk_insert_param *params;
- uint i, num_keys;
+ uint i, num_keys, total_keylength;
ulonglong key_map=0;
DBUG_ENTER("_mi_init_bulk_insert");
DBUG_PRINT("enter",("cache_size: %lu", cache_size));
- if (info->bulk_insert)
+ if (info->bulk_insert || (rows && rows < MI_MIN_ROWS_TO_USE_BULK_INSERT))
DBUG_RETURN(0);
- for (i=num_keys=0 ; i < share->base.keys ; i++)
+ for (i=total_keylength=num_keys=0 ; i < share->base.keys ; i++)
{
if (!(key[i].flag & HA_NOSAME) && share->base.auto_key != i+1
&& test(share->state.key_map & ((ulonglong) 1 << i)))
{
num_keys++;
key_map |=((ulonglong) 1 << i);
+ total_keylength+=key[i].maxlength+TREE_ELEMENT_EXTRA_SIZE;
}
}
@@ -828,6 +829,11 @@ int _mi_init_bulk_insert(MI_INFO *info, ulong cache_size)
num_keys * MI_MIN_SIZE_BULK_INSERT_TREE > cache_size)
DBUG_RETURN(0);
+ if (rows && rows*total_keylength < cache_size)
+ cache_size=rows;
+ else
+ cache_size/=total_keylength*16;
+
info->bulk_insert=(TREE *)
my_malloc((sizeof(TREE)*share->base.keys+
sizeof(bulk_insert_param)*num_keys),MYF(0));
@@ -836,7 +842,7 @@ int _mi_init_bulk_insert(MI_INFO *info, ulong cache_size)
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
params=(bulk_insert_param *)(info->bulk_insert+share->base.keys);
- for (i=0 ; i < share->base.keys ; i++,key++)
+ for (i=0 ; i < share->base.keys ; i++)
{
if (test(key_map & ((ulonglong) 1 << i)))
{
@@ -844,8 +850,8 @@ int _mi_init_bulk_insert(MI_INFO *info, ulong cache_size)
params->keynr=i;
/* Only allocate a 16'th of the buffer at a time */
init_tree(&info->bulk_insert[i],
- cache_size / num_keys / 16 + 10,
- cache_size / num_keys, 0,
+ cache_size * key[i].maxlength,
+ cache_size * key[i].maxlength, 0,
(qsort_cmp2)keys_compare, 0,
(tree_element_free) keys_free, (void *)params++);
}
@@ -855,3 +861,30 @@ int _mi_init_bulk_insert(MI_INFO *info, ulong cache_size)
DBUG_RETURN(0);
}
+
+void mi_flush_bulk_insert(MI_INFO *info, uint inx)
+{
+ if (info->bulk_insert)
+ {
+ if (is_tree_inited(&info->bulk_insert[inx]))
+ reset_tree(&info->bulk_insert[inx]);
+ }
+}
+
+void mi_end_bulk_insert(MI_INFO *info)
+{
+ if (info->bulk_insert)
+ {
+ uint i;
+ for (i=0 ; i < info->s->base.keys ; i++)
+ {
+ if (is_tree_inited(& info->bulk_insert[i]))
+ {
+ delete_tree(& info->bulk_insert[i]);
+ }
+ }
+ my_free((void *)info->bulk_insert, MYF(0));
+ info->bulk_insert=0;
+ }
+}
+
diff --git a/myisam/myisamdef.h b/myisam/myisamdef.h
index f0d6f740661..07744e11e5f 100644
--- a/myisam/myisamdef.h
+++ b/myisam/myisamdef.h
@@ -373,6 +373,7 @@ struct st_myisam_info {
#define MI_MIN_KEYBLOCK_LENGTH 50 /* When to split delete blocks */
#define MI_MIN_SIZE_BULK_INSERT_TREE 16384 /* this is per key */
+#define MI_MIN_ROWS_TO_USE_BULK_INSERT 100
/* The UNIQUE check is done with a hashed long key */
@@ -658,8 +659,6 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, File file_to_dup);
int mi_open_keyfile(MYISAM_SHARE *share);
void mi_setup_functions(register MYISAM_SHARE *share);
-int _mi_init_bulk_insert(MI_INFO *info, ulong cache_size);
-
/* Functions needed by mi_check */
void mi_check_print_error _VARARGS((MI_CHECK *param, const char *fmt,...));
void mi_check_print_warning _VARARGS((MI_CHECK *param, const char *fmt,...));