00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "myisam_priv.h"
00021 #include <stdlib.h>
00022 #include <drizzled/util/test.h>
00023
00024 using namespace drizzled;
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 int mi_preload(MI_INFO *info, uint64_t key_map, bool ignore_leaves)
00045 {
00046 uint32_t i;
00047 uint32_t length, block_length= 0;
00048 unsigned char *buff= NULL;
00049 MYISAM_SHARE* share= info->s;
00050 uint32_t keys= share->state.header.keys;
00051 MI_KEYDEF *keyinfo= share->keyinfo;
00052 internal::my_off_t key_file_length= share->state.state.key_file_length;
00053 internal::my_off_t pos= share->base.keystart;
00054
00055 if (!keys || !mi_is_any_key_active(key_map) || key_file_length == pos)
00056 return(0);
00057
00058 block_length= keyinfo[0].block_length;
00059
00060 if (ignore_leaves)
00061 {
00062
00063 for (i= 1 ; i < keys ; i++)
00064 {
00065 if (keyinfo[i].block_length != block_length)
00066 return(errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
00067 }
00068 }
00069 else
00070 block_length= share->getKeyCache()->key_cache_block_size;
00071
00072 length= info->preload_buff_size/block_length * block_length;
00073 set_if_bigger(length, block_length);
00074
00075 if (!(buff= (unsigned char *) malloc(length)))
00076 return(errno= HA_ERR_OUT_OF_MEM);
00077
00078 if (flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_RELEASE))
00079 goto err;
00080
00081 do
00082 {
00083
00084 if ((internal::my_off_t) length > (key_file_length-pos))
00085 length= (uint32_t) (key_file_length-pos);
00086 if (my_pread(share->kfile, (unsigned char*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
00087 goto err;
00088
00089 if (ignore_leaves)
00090 {
00091 unsigned char *end= buff+length;
00092 do
00093 {
00094 if (mi_test_if_nod(buff))
00095 {
00096 if (key_cache_insert(share->getKeyCache(),
00097 share->kfile, pos, DFLT_INIT_HITS,
00098 (unsigned char*) buff, block_length))
00099 goto err;
00100 }
00101 pos+= block_length;
00102 }
00103 while ((buff+= block_length) != end);
00104 buff= end-length;
00105 }
00106 else
00107 {
00108 if (key_cache_insert(share->getKeyCache(),
00109 share->kfile, pos, DFLT_INIT_HITS,
00110 (unsigned char*) buff, length))
00111 goto err;
00112 pos+= length;
00113 }
00114 }
00115 while (pos != key_file_length);
00116
00117 free((char*) buff);
00118 return(0);
00119
00120 err:
00121 free((char*) buff);
00122 return(errno= errno);
00123 }
00124