1
/* Copyright (C) 2003, 2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17
Preload indexes into key cache
20
#include "myisam_priv.h"
22
#include <drizzled/util/test.h>
24
using namespace drizzled;
27
Preload pages of the index file for a table into the key cache
32
map map of indexes to preload into key cache
33
ignore_leaves only non-leaves pages are to be preloaded
36
0 if a success. error code - otherwise.
39
At present pages for all indexes are preloaded.
40
In future only pages for indexes specified in the key_map parameter
41
of the table will be preloaded.
44
int mi_preload(MI_INFO *info, uint64_t key_map, bool ignore_leaves)
47
uint32_t length, block_length= 0;
48
unsigned char *buff= NULL;
49
MYISAM_SHARE* share= info->s;
50
uint32_t keys= share->state.header.keys;
51
MI_KEYDEF *keyinfo= share->keyinfo;
52
internal::my_off_t key_file_length= share->state.state.key_file_length;
53
internal::my_off_t pos= share->base.keystart;
55
if (!keys || !mi_is_any_key_active(key_map) || key_file_length == pos)
58
block_length= keyinfo[0].block_length;
62
/* Check whether all indexes use the same block size */
63
for (i= 1 ; i < keys ; i++)
65
if (keyinfo[i].block_length != block_length)
66
return(errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
70
block_length= share->getKeyCache()->key_cache_block_size;
72
length= info->preload_buff_size/block_length * block_length;
73
set_if_bigger(length, block_length);
75
if (!(buff= (unsigned char *) malloc(length)))
76
return(errno= HA_ERR_OUT_OF_MEM);
78
if (flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_RELEASE))
83
/* Read the next block of index file into the preload buffer */
84
if ((internal::my_off_t) length > (key_file_length-pos))
85
length= (uint32_t) (key_file_length-pos);
86
if (my_pread(share->kfile, (unsigned char*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
91
unsigned char *end= buff+length;
94
if (mi_test_if_nod(buff))
96
if (key_cache_insert(share->getKeyCache(),
97
share->kfile, pos, DFLT_INIT_HITS,
98
(unsigned char*) buff, block_length))
103
while ((buff+= block_length) != end);
108
if (key_cache_insert(share->getKeyCache(),
109
share->kfile, pos, DFLT_INIT_HITS,
110
(unsigned char*) buff, length))
115
while (pos != key_file_length);
122
return(errno= errno);