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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
Preload indexes into key cache
20
#include "myisamdef.h"
24
Preload pages of the index file for a table into the key cache
29
map map of indexes to preload into key cache
30
ignore_leaves only non-leaves pages are to be preloaded
33
0 if a success. error code - otherwise.
36
At present pages for all indexes are preloaded.
37
In future only pages for indexes specified in the key_map parameter
38
of the table will be preloaded.
41
int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves)
44
ulong length, block_length= 0;
46
MYISAM_SHARE* share= info->s;
47
uint keys= share->state.header.keys;
48
MI_KEYDEF *keyinfo= share->keyinfo;
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)
56
block_length= keyinfo[0].block_length;
60
/* Check whether all indexes use the same block size */
61
for (i= 1 ; i < keys ; i++)
63
if (keyinfo[i].block_length != block_length)
64
DBUG_RETURN(my_errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
68
block_length= share->key_cache->key_cache_block_size;
70
length= info->preload_buff_size/block_length * block_length;
71
set_if_bigger(length, block_length);
73
if (!(buff= (uchar *) my_malloc(length, MYF(MY_WME))))
74
DBUG_RETURN(my_errno= HA_ERR_OUT_OF_MEM);
76
if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_RELEASE))
81
/* Read the next block of index file into the preload buffer */
82
if ((my_off_t) length > (key_file_length-pos))
83
length= (ulong) (key_file_length-pos);
84
if (my_pread(share->kfile, (uchar*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
89
uchar *end= buff+length;
92
if (mi_test_if_nod(buff))
94
if (key_cache_insert(share->key_cache,
95
share->kfile, pos, DFLT_INIT_HITS,
96
(uchar*) buff, block_length))
101
while ((buff+= block_length) != end);
106
if (key_cache_insert(share->key_cache,
107
share->kfile, pos, DFLT_INIT_HITS,
108
(uchar*) buff, length))
113
while (pos != key_file_length);
115
my_free((char*) buff, MYF(0));
119
my_free((char*) buff, MYF(MY_ALLOW_ZERO_PTR));
120
DBUG_RETURN(my_errno= errno);