2003-06-12 13:29:02 +02:00
|
|
|
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
/*
|
|
|
|
Preload indexes into key cache
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "myisamdef.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Preload pages of the index file for a table into the key cache
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
mi_preload()
|
|
|
|
info open table
|
|
|
|
map map of indexes to preload into key cache
|
|
|
|
ignore_leaves only non-leaves pages are to be preloaded
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
0 if a success. error code - otherwise.
|
|
|
|
|
|
|
|
NOTES.
|
|
|
|
At present pages for all indexes are preloaded.
|
|
|
|
In future only pages for indexes specified in the key_map parameter
|
|
|
|
of the table will be preloaded.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves)
|
|
|
|
{
|
|
|
|
uint i;
|
2003-06-24 11:10:35 +02:00
|
|
|
ulong length, block_length= 0;
|
2003-06-12 13:29:02 +02:00
|
|
|
uchar *buff= NULL;
|
|
|
|
MYISAM_SHARE* share= info->s;
|
|
|
|
uint keys= share->state.header.keys;
|
|
|
|
MI_KEYDEF *keyinfo= share->keyinfo;
|
|
|
|
my_off_t key_file_length= share->state.state.key_file_length;
|
|
|
|
my_off_t pos= share->base.keystart;
|
2003-06-24 11:10:35 +02:00
|
|
|
DBUG_ENTER("mi_preload");
|
2003-06-12 13:29:02 +02:00
|
|
|
|
Bug#10932 - Building server with key limit of 128, makes test cases fail
This patch allows to configure MyISAM for 128 indexes per table.
The main problem is the key_map, wich is implemented as an ulonglong.
To get rid of the limit and keep the efficient and flexible
implementation, the highest bit is now used for all upper keys.
This means that the lower keys can be disabled and enabled
individually as usual and the high keys can only be disabled and
enabled as a block. That way the existing test suite is still
applicable, while more keys work, though slightly less efficient.
To really get more than 64 keys, some defines need to be changed.
Another patch will address this.
include/my_bitmap.h:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Added the declaration for a function that extends the highest bit value
to all upper bits of a bigger bitmap.
include/myisam.h:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed MI_MAX_POSSIBLE_KEY to what it was meant for.
Added a bunch of macros to handle the MyISAM key_map.
myisam/mi_check.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_create.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_delete.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_extra.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_open.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
Changed pointer types from signed char* to unsigned char*.
myisam/mi_preload.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_rsame.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_rsamepos.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_search.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_update.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_write.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/myisamchk.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/myisamdef.h:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed pointer types from signed char* to unsigned char*.
myisam/myisamlog.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/myisampack.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/sort.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
mysys/my_bitmap.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Added a function that extends the highest bit value
to all upper bits of a bigger bitmap.
sql/ha_myisam.cc:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
sql/sql_bitmap.h:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Added a method that extends the highest bit value
to all upper bits of a bigger bitmap.
2005-07-19 14:13:56 +02:00
|
|
|
if (!keys || !mi_is_any_key_active(key_map) || key_file_length == pos)
|
2003-06-24 11:10:35 +02:00
|
|
|
DBUG_RETURN(0);
|
2003-06-12 13:29:02 +02:00
|
|
|
|
|
|
|
block_length= keyinfo[0].block_length;
|
|
|
|
|
|
|
|
/* Check whether all indexes use the same block size */
|
|
|
|
for (i= 1 ; i < keys ; i++)
|
|
|
|
{
|
|
|
|
if (keyinfo[i].block_length != block_length)
|
2003-06-24 11:10:35 +02:00
|
|
|
DBUG_RETURN(my_errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
|
2003-06-12 13:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
length= info->preload_buff_size/block_length * block_length;
|
|
|
|
set_if_bigger(length, block_length);
|
|
|
|
|
|
|
|
if (!(buff= (uchar *) my_malloc(length, MYF(MY_WME))))
|
2003-06-24 11:10:35 +02:00
|
|
|
DBUG_RETURN(my_errno= HA_ERR_OUT_OF_MEM);
|
2003-06-12 13:29:02 +02:00
|
|
|
|
2003-11-20 21:06:25 +01:00
|
|
|
if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_RELEASE))
|
2003-06-12 13:29:02 +02:00
|
|
|
goto err;
|
2005-02-12 00:05:13 +01:00
|
|
|
|
2003-06-12 13:29:02 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Read the next block of index file into the preload buffer */
|
2003-06-24 11:10:35 +02:00
|
|
|
if ((my_off_t) length > (key_file_length-pos))
|
|
|
|
length= (ulong) (key_file_length-pos);
|
2005-02-12 00:05:13 +01:00
|
|
|
if (my_pread(share->kfile, (byte*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
|
2003-06-12 13:29:02 +02:00
|
|
|
goto err;
|
2005-02-12 00:05:13 +01:00
|
|
|
|
2003-06-12 13:29:02 +02:00
|
|
|
if (ignore_leaves)
|
|
|
|
{
|
|
|
|
uchar *end= buff+length;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (mi_test_if_nod(buff))
|
|
|
|
{
|
2003-11-20 21:06:25 +01:00
|
|
|
if (key_cache_insert(share->key_cache,
|
2005-02-12 00:05:13 +01:00
|
|
|
share->kfile, pos, DFLT_INIT_HITS,
|
2003-08-09 20:12:22 +02:00
|
|
|
(byte*) buff, block_length))
|
2003-06-12 13:29:02 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
pos+= block_length;
|
|
|
|
}
|
|
|
|
while ((buff+= block_length) != end);
|
|
|
|
buff= end-length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-20 21:06:25 +01:00
|
|
|
if (key_cache_insert(share->key_cache,
|
2003-08-09 20:12:22 +02:00
|
|
|
share->kfile, pos, DFLT_INIT_HITS,
|
|
|
|
(byte*) buff, length))
|
2003-06-12 13:29:02 +02:00
|
|
|
goto err;
|
|
|
|
pos+= length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (pos != key_file_length);
|
|
|
|
|
2003-11-28 11:18:13 +01:00
|
|
|
my_free((char*) buff, MYF(0));
|
2003-06-24 11:10:35 +02:00
|
|
|
DBUG_RETURN(0);
|
2003-06-12 13:29:02 +02:00
|
|
|
|
|
|
|
err:
|
2003-11-28 11:18:13 +01:00
|
|
|
my_free((char*) buff, MYF(MY_ALLOW_ZERO_PTR));
|
2003-06-24 11:10:35 +02:00
|
|
|
DBUG_RETURN(my_errno= errno);
|
2003-06-12 13:29:02 +02:00
|
|
|
}
|
|
|
|
|