diff --git a/myisam/mi_write.c b/myisam/mi_write.c index 085490649a8..32b767b1433 100644 --- a/myisam/mi_write.c +++ b/myisam/mi_write.c @@ -765,34 +765,47 @@ int _mi_init_bulk_insert(MI_INFO *info) MYISAM_SHARE *share=info->s; MI_KEYDEF *key=share->keyinfo; bulk_insert_param *params; - uint i; + uint i, num_keys; + ulonglong key_map=0; if (info->bulk_insert) return 0; + for (i=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); + } + } + + if (!num_keys) + return 0; + info->bulk_insert=(TREE *) - my_malloc((sizeof(TREE)+sizeof(bulk_insert_param))*share->base.keys, - MYF(0)); + my_malloc((sizeof(TREE)*share->base.keys+ + sizeof(bulk_insert_param)*num_keys),MYF(0)); if (!info->bulk_insert) 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++,params++) + for (i=0 ; i < share->base.keys ; i++,key++) { params->info=info; params->keynr=i; - if (!(key->flag & HA_NOSAME) && share->base.auto_key != i+1 - && test(share->state.key_map & ((ulonglong) 1 << i))) + if (test(key_map & ((ulonglong) 1 << i))) { init_tree(& info->bulk_insert[i], 0, - myisam_bulk_insert_tree_size / share->base.keys, 0, + myisam_bulk_insert_tree_size / num_keys, 0, (qsort_cmp2)keys_compare, 0, - (tree_element_free) keys_free, (void *)params); + (tree_element_free) keys_free, (void *)params++); } else info->bulk_insert[i].root=0; } + return 0; } diff --git a/mysys/tree.c b/mysys/tree.c index e02033ff413..cf9ce0caafa 100644 --- a/mysys/tree.c +++ b/mysys/tree.c @@ -63,31 +63,7 @@ static void rb_delete_fixup(TREE *tree,TREE_ELEMENT ***parent); /* The actuall code for handling binary trees */ #ifndef DBUG_OFF - - /* Test that the proporties for a red-black tree holds */ - -static int test_rb_tree(TREE_ELEMENT *element) -{ - int count_l,count_r; - - if (!element->left) - return 0; /* Found end of tree */ - if (element->colour == RED && - (element->left->colour == RED || element->right->colour == RED)) - { - printf("Wrong tree: Found two red in a row\n"); - return -1; - } - count_l=test_rb_tree(element->left); - count_r=test_rb_tree(element->right); - if (count_l >= 0 && count_r >= 0) - { - if (count_l == count_r) - return count_l+(element->colour == BLACK); - printf("Wrong tree: Incorrect black-count: %d - %d\n",count_l,count_r); - } - return -1; -} +static int test_rb_tree(TREE_ELEMENT *element); #endif void init_tree(TREE *tree, uint default_alloc_size, uint memory_limit, @@ -546,3 +522,31 @@ static void rb_delete_fixup(TREE *tree, TREE_ELEMENT ***parent) } x->colour=BLACK; } + +#ifndef DBUG_OFF + + /* Test that the proporties for a red-black tree holds */ + +static int test_rb_tree(TREE_ELEMENT *element) +{ + int count_l,count_r; + + if (!element->left) + return 0; /* Found end of tree */ + if (element->colour == RED && + (element->left->colour == RED || element->right->colour == RED)) + { + printf("Wrong tree: Found two red in a row\n"); + return -1; + } + count_l=test_rb_tree(element->left); + count_r=test_rb_tree(element->right); + if (count_l >= 0 && count_r >= 0) + { + if (count_l == count_r) + return count_l+(element->colour == BLACK); + printf("Wrong tree: Incorrect black-count: %d - %d\n",count_l,count_r); + } + return -1; +} +#endif diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 8a4443f8a47..2a220f29670 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -114,7 +114,7 @@ int mysqld_show_open_tables(THD *thd,const char *db,const char *wild) if (send_fields(thd,field_list,1)) DBUG_RETURN(1); - if (!(open_list=list_open_tables(thd,wild)) && thd->fatal_error) + if (!(list_open_tables(thd,&tables,db,wild)) && thd->fatal_error) DBUG_RETURN(-1); List_iterator it(tables);