Commit 15b67384 authored by serg@serg.mysql.com's avatar serg@serg.mysql.com
Browse files

memory-limited tree

bulk inserts optimization: caching keys in binary tree
parent 3c7cc228
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -91,7 +91,9 @@ enum ha_extra_function {
  HA_EXTRA_RESET_STATE,			/* Reset positions */
  HA_EXTRA_IGNORE_DUP_KEY,		/* Dup keys don't rollback everything*/
  HA_EXTRA_NO_IGNORE_DUP_KEY,
  HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE	/* Cursor will not be used for update */
  HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE,	/* Cursor will not be used for update */
  HA_EXTRA_BULK_INSERT_BEGIN,
  HA_EXTRA_BULK_INSERT_END
};

	/* The following is parameter to ha_panic() */
+9 −6
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ typedef enum { left_root_right, right_root_left } TREE_WALK;
typedef uint32 element_count;
typedef int (*tree_walk_action)(void *,element_count,void *);

typedef enum { free_init, free_free, free_end } TREE_FREE;
typedef void (*tree_element_free)(void*, TREE_FREE, void *);

#ifdef MSDOS
typedef struct st_tree_element {
  struct st_tree_element *left,*right;
@@ -49,18 +52,18 @@ typedef struct st_tree_element {
typedef struct st_tree {
  TREE_ELEMENT *root,null_element;
  TREE_ELEMENT **parents[MAX_TREE_HIGHT];
  uint offset_to_key,elements_in_tree,size_of_element;
  uint offset_to_key,elements_in_tree,size_of_element,memory_limit,allocated;
  qsort_cmp2 compare;
  void* cmp_arg;
  void* custom_arg;
  MEM_ROOT mem_root;
  my_bool with_delete;
  void (*free)(void *);
  tree_element_free free;
} TREE;

	/* Functions on whole tree */
void init_tree(TREE *tree,uint default_alloc_size, int element_size,
	       qsort_cmp2 compare, my_bool with_delete,
	       void (*free_element)(void*));
void init_tree(TREE *tree, uint default_alloc_size, uint memory_limit,
               int size, qsort_cmp2 compare, my_bool with_delete,
	       tree_element_free free_element, void *custom_arg);
void delete_tree(TREE*);
void reset_tree(TREE*);
  /* similar to delete tree, except we do not my_free() blocks in mem_root
+1 −0
Original line number Diff line number Diff line
@@ -190,6 +190,7 @@ extern uint myisam_block_size;
extern my_bool myisam_flush,myisam_delay_key_write,myisam_single_user;
extern my_bool myisam_concurrent_insert;
extern my_off_t myisam_max_temp_length,myisam_max_extra_temp_length;
extern uint myisam_bulk_insert_tree_size;

	/* Prototypes for myisam-functions */

+2 −2
Original line number Diff line number Diff line
@@ -325,8 +325,8 @@ static int examine_log(my_string file_name, char **table_names)

  init_io_cache(&cache,file,0,READ_CACHE,start_offset,0,MYF(0));
  bzero((gptr) com_count,sizeof(com_count));
  init_tree(&tree,0,sizeof(file_info),(qsort_cmp) file_info_compare,1,
	    (void(*)(void*)) file_info_free);
  init_tree(&tree,0,0,sizeof(file_info),(qsort_cmp2) file_info_compare,1,
	    (tree_element_free) file_info_free, NULL);
  VOID(init_key_cache(KEY_CACHE_SIZE,(uint) (10*4*(IO_SIZE+MALLOC_OVERHEAD))));

  files_open=0; access_time=0;
+1 −1
Original line number Diff line number Diff line
@@ -684,7 +684,7 @@ static HUFF_COUNTS *init_huff_count(N_INFO *info,my_off_t records)
	  (type == FIELD_NORMAL ||
	   type == FIELD_SKIPP_ZERO))
	count[i].max_zero_fill= count[i].field_length;
      init_tree(&count[i].int_tree,0,-1,(qsort_cmp) compare_tree,0,NULL);
      init_tree(&count[i].int_tree,0,0,-1,(qsort_cmp2) compare_tree,0,NULL,NULL);
      if (records)
	count[i].tree_pos=count[i].tree_buff =
	  my_malloc(count[i].field_length > 1 ? tree_buff_length : 2,
Loading