20 #include "myisamdef.h"
41 int mi_preload(
MI_INFO *info, ulonglong
key_map, my_bool ignore_leaves)
44 ulong length, block_length= 0;
47 uint keys= share->state.header.keys;
49 my_off_t key_file_length= share->state.state.key_file_length;
50 my_off_t pos= share->base.keystart;
51 DBUG_ENTER(
"mi_preload");
53 if (!keys || !mi_is_any_key_active(key_map) || key_file_length == pos)
57 DBUG_ASSERT(share->key_cache->key_cache_inited);
59 block_length= keyinfo[0].block_length;
64 for (i= 1 ; i < keys ; i++)
66 if (keyinfo[i].block_length != block_length)
67 DBUG_RETURN(my_errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
71 block_length= share->key_cache->key_cache_block_size;
73 length= info->preload_buff_size/block_length * block_length;
74 set_if_bigger(length, block_length);
76 if (!(buff= (uchar *) my_malloc(length, MYF(MY_WME))))
77 DBUG_RETURN(my_errno= HA_ERR_OUT_OF_MEM);
79 if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_RELEASE))
85 if ((my_off_t) length > (key_file_length-pos))
86 length= (ulong) (key_file_length-pos);
88 MYF(MY_FAE|MY_FNABP)))
93 uchar *end= buff+length;
96 if (mi_test_if_nod(buff))
98 if (key_cache_insert(share->key_cache,
99 share->kfile, pos, DFLT_INIT_HITS,
100 (uchar*) buff, block_length))
105 while ((buff+= block_length) != end);
110 if (key_cache_insert(share->key_cache,
111 share->kfile, pos, DFLT_INIT_HITS,
112 (uchar*) buff, length))
117 while (pos != key_file_length);
124 DBUG_RETURN(my_errno= errno);