mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 13:32:33 +01:00
8707870dd9
BUILD/autorun.sh: Auto merged BitKeeper/deleted/.del-var: Delete: mysql-test/var BitKeeper/etc/config: Auto merged configure.in: Auto merged mysql-test/r/information_schema_db.result: Auto merged mysys/Makefile.am: Auto merged mysys/default.c: Auto merged sql/ha_berkeley.cc: Auto merged sql/ha_berkeley.h: Auto merged sql/ha_federated.h: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_innodb.h: Auto merged sql/ha_myisam.cc: Auto merged sql/ha_myisammrg.cc: Auto merged sql/ha_ndbcluster.cc: Auto merged sql/handler.h: Auto merged sql/item.cc: Auto merged sql/lex.h: Auto merged sql/lock.cc: Auto merged sql/log.cc: Auto merged sql/log_event.cc: Auto merged sql/mysql_priv.h: Auto merged sql/mysqld.cc: Auto merged sql/opt_range.cc: Auto merged sql/set_var.cc: Auto merged sql/sp.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_bitmap.h: Auto merged sql/sql_cache.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_lex.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_prepare.cc: Auto merged sql/sql_repl.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_select.h: Auto merged sql/sql_show.cc: Auto merged sql/examples/ha_tina.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/table.h: Auto merged storage/myisam/mi_check.c: Auto merged storage/myisam/mi_create.c: Auto merged storage/myisam/mi_delete.c: Auto merged storage/myisam/mi_extra.c: Auto merged storage/myisam/mi_open.c: Auto merged storage/myisam/mi_preload.c: Auto merged storage/myisam/mi_rsame.c: Auto merged storage/myisam/mi_rsamepos.c: Auto merged storage/myisam/mi_search.c: Auto merged storage/myisam/mi_update.c: Auto merged storage/myisam/mi_write.c: Auto merged storage/myisam/myisamchk.c: Auto merged storage/myisam/myisamdef.h: Auto merged storage/myisam/myisamlog.c: Auto merged storage/myisam/myisampack.c: Auto merged storage/myisam/sort.c: Auto merged storage/ndb/src/common/portlib/NdbMutex.c: Auto merged storage/ndb/src/common/portlib/NdbThread.c: Auto merged support-files/mysql.spec.sh: Auto merged
118 lines
3.3 KiB
C
118 lines
3.3 KiB
C
/* 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;
|
|
ulong length, block_length= 0;
|
|
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;
|
|
DBUG_ENTER("mi_preload");
|
|
|
|
if (!keys || !mi_is_any_key_active(key_map) || key_file_length == pos)
|
|
DBUG_RETURN(0);
|
|
|
|
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)
|
|
DBUG_RETURN(my_errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
|
|
}
|
|
|
|
length= info->preload_buff_size/block_length * block_length;
|
|
set_if_bigger(length, block_length);
|
|
|
|
if (!(buff= (uchar *) my_malloc(length, MYF(MY_WME))))
|
|
DBUG_RETURN(my_errno= HA_ERR_OUT_OF_MEM);
|
|
|
|
if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_RELEASE))
|
|
goto err;
|
|
|
|
do
|
|
{
|
|
/* Read the next block of index file into the preload buffer */
|
|
if ((my_off_t) length > (key_file_length-pos))
|
|
length= (ulong) (key_file_length-pos);
|
|
if (my_pread(share->kfile, (byte*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
|
|
goto err;
|
|
|
|
if (ignore_leaves)
|
|
{
|
|
uchar *end= buff+length;
|
|
do
|
|
{
|
|
if (mi_test_if_nod(buff))
|
|
{
|
|
if (key_cache_insert(share->key_cache,
|
|
share->kfile, pos, DFLT_INIT_HITS,
|
|
(byte*) buff, block_length))
|
|
goto err;
|
|
}
|
|
pos+= block_length;
|
|
}
|
|
while ((buff+= block_length) != end);
|
|
buff= end-length;
|
|
}
|
|
else
|
|
{
|
|
if (key_cache_insert(share->key_cache,
|
|
share->kfile, pos, DFLT_INIT_HITS,
|
|
(byte*) buff, length))
|
|
goto err;
|
|
pos+= length;
|
|
}
|
|
}
|
|
while (pos != key_file_length);
|
|
|
|
my_free((char*) buff, MYF(0));
|
|
DBUG_RETURN(0);
|
|
|
|
err:
|
|
my_free((char*) buff, MYF(MY_ALLOW_ZERO_PTR));
|
|
DBUG_RETURN(my_errno= errno);
|
|
}
|
|
|