1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
6
(at your option) any later version.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
Preload indexes into key cache
21
#include "myisamdef.h"
25
Preload pages of the index file for a table into the key cache
30
map map of indexes to preload into key cache
31
ignore_leaves only non-leaves pages are to be preloaded
34
0 if a success. error code - otherwise.
37
At present pages for all indexes are preloaded.
38
In future only pages for indexes specified in the key_map parameter
39
of the table will be preloaded.
42
int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves)
45
ulong length, block_length= 0;
47
MYISAM_SHARE* share= info->s;
48
uint keys= share->state.header.keys;
49
MI_KEYDEF *keyinfo= share->keyinfo;
50
my_off_t key_file_length= share->state.state.key_file_length;
51
my_off_t pos= share->base.keystart;
52
DBUG_ENTER("mi_preload");
54
if (!keys || !mi_is_any_key_active(key_map) || key_file_length == pos)
57
block_length= keyinfo[0].block_length;
59
/* Check whether all indexes use the same block size */
60
for (i= 1 ; i < keys ; i++)
62
if (keyinfo[i].block_length != block_length)
63
DBUG_RETURN(my_errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
66
length= info->preload_buff_size/block_length * block_length;
67
set_if_bigger(length, block_length);
69
if (!(buff= (uchar *) my_malloc(length, MYF(MY_WME))))
70
DBUG_RETURN(my_errno= HA_ERR_OUT_OF_MEM);
72
if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_RELEASE))
77
/* Read the next block of index file into the preload buffer */
78
if ((my_off_t) length > (key_file_length-pos))
79
length= (ulong) (key_file_length-pos);
80
if (my_pread(share->kfile, (byte*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
85
uchar *end= buff+length;
88
if (mi_test_if_nod(buff))
90
if (key_cache_insert(share->key_cache,
91
share->kfile, pos, DFLT_INIT_HITS,
92
(byte*) buff, block_length))
97
while ((buff+= block_length) != end);
102
if (key_cache_insert(share->key_cache,
103
share->kfile, pos, DFLT_INIT_HITS,
104
(byte*) buff, length))
109
while (pos != key_file_length);
111
my_free((char*) buff, MYF(0));
115
my_free((char*) buff, MYF(MY_ALLOW_ZERO_PTR));
116
DBUG_RETURN(my_errno= errno);