diff options
author | unknown <igor@rurik.mysql.com> | 2003-08-26 00:13:22 -0700 |
---|---|---|
committer | unknown <igor@rurik.mysql.com> | 2003-08-26 00:13:22 -0700 |
commit | f6758b47fb75fb7f39e4883d53523bfda589adfd (patch) | |
tree | 8f6c56f59666be1b54701f57e779e904575b1a4a /myisam | |
parent | 3b799e8fd8eb13c7ad6e2bb01a922e37d9101ea7 (diff) | |
parent | b9a90dffb6c429ab405d036734b3b04b98df69d6 (diff) | |
download | mariadb-git-f6758b47fb75fb7f39e4883d53523bfda589adfd.tar.gz |
Manual merge
include/my_base.h:
Auto merged
include/my_global.h:
Auto merged
include/my_sys.h:
Auto merged
myisam/mi_check.c:
Auto merged
myisam/mi_extra.c:
Auto merged
myisam/mi_locking.c:
Auto merged
myisam/myisamchk.c:
Auto merged
myisam/myisamdef.h:
Auto merged
mysql-test/r/key_cache.result:
Auto merged
mysql-test/t/key_cache.test:
Auto merged
sql/ha_myisam.cc:
Auto merged
sql/handler.cc:
Auto merged
sql/handler.h:
Auto merged
sql/item_cmpfunc.h:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/opt_range.cc:
Auto merged
sql/set_var.h:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_table.cc:
Auto merged
sql/table.h:
Auto merged
Diffstat (limited to 'myisam')
-rw-r--r-- | myisam/Makefile.am | 2 | ||||
-rw-r--r-- | myisam/mi_check.c | 45 | ||||
-rw-r--r-- | myisam/mi_close.c | 2 | ||||
-rw-r--r-- | myisam/mi_delete.c | 40 | ||||
-rw-r--r-- | myisam/mi_delete_all.c | 2 | ||||
-rw-r--r-- | myisam/mi_extra.c | 7 | ||||
-rw-r--r-- | myisam/mi_keycache.c | 63 | ||||
-rw-r--r-- | myisam/mi_locking.c | 19 | ||||
-rw-r--r-- | myisam/mi_page.c | 22 | ||||
-rw-r--r-- | myisam/mi_panic.c | 2 | ||||
-rw-r--r-- | myisam/mi_preload.c | 10 | ||||
-rw-r--r-- | myisam/mi_range.c | 2 | ||||
-rw-r--r-- | myisam/mi_search.c | 10 | ||||
-rw-r--r-- | myisam/mi_test1.c | 2 | ||||
-rw-r--r-- | myisam/mi_test2.c | 12 | ||||
-rw-r--r-- | myisam/mi_test3.c | 2 | ||||
-rw-r--r-- | myisam/mi_write.c | 27 | ||||
-rw-r--r-- | myisam/myisamchk.c | 15 | ||||
-rw-r--r-- | myisam/myisamdef.h | 11 | ||||
-rw-r--r-- | myisam/myisamlog.c | 7 | ||||
-rw-r--r-- | myisam/rt_index.c | 49 | ||||
-rw-r--r-- | myisam/rt_key.c | 3 | ||||
-rw-r--r-- | myisam/rt_split.c | 6 |
23 files changed, 244 insertions, 116 deletions
diff --git a/myisam/Makefile.am b/myisam/Makefile.am index d4cd953ac66..fdcfc6d0d41 100644 --- a/myisam/Makefile.am +++ b/myisam/Makefile.am @@ -47,7 +47,7 @@ libmyisam_a_SOURCES = mi_open.c mi_extra.c mi_info.c mi_rkey.c \ mi_range.c mi_dbug.c mi_checksum.c mi_log.c \ mi_changed.c mi_static.c mi_delete_all.c \ mi_delete_table.c mi_rename.c mi_check.c \ - mi_preload.c \ + mi_keycache.c mi_preload.c \ ft_parser.c ft_stopwords.c ft_static.c \ ft_update.c ft_boolean_search.c ft_nlq_search.c sort.c \ rt_index.c rt_key.c rt_mbr.c rt_split.c sp_key.c diff --git a/myisam/mi_check.c b/myisam/mi_check.c index 60053674647..16fe5567d72 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -230,7 +230,9 @@ static int check_k_link(MI_CHECK *param, register MI_INFO *info, uint nr) if (next_link > info->state->key_file_length || next_link & (info->s->blocksize-1)) DBUG_RETURN(1); - if (!(buff=key_cache_read(info->s->kfile, next_link, (byte*) info->buff, + if (!(buff=key_cache_read(*info->s->keycache, + info->s->kfile, next_link, DFLT_INIT_HITS, + (byte*) info->buff, myisam_block_size, block_size, 1))) DBUG_RETURN(1); next_link=mi_sizekorr(buff); @@ -259,7 +261,8 @@ int chk_size(MI_CHECK *param, register MI_INFO *info) if (!(param->testflag & T_SILENT)) puts("- check file-size"); - flush_key_blocks(info->s->kfile, FLUSH_FORCE_WRITE); /* If called externally */ + flush_key_blocks(*info->s->keycache, + info->s->kfile, FLUSH_FORCE_WRITE); /* If called externally */ size=my_seek(info->s->kfile,0L,MY_SEEK_END,MYF(0)); if ((skr=(my_off_t) info->state->key_file_length) != size) @@ -369,8 +372,8 @@ int chk_key(MI_CHECK *param, register MI_INFO *info) if (share->state.key_root[key] == HA_OFFSET_ERROR && (info->state->records == 0 || keyinfo->flag & HA_FULLTEXT)) continue; - if (!_mi_fetch_keypage(info,keyinfo,share->state.key_root[key],info->buff, - 0)) + if (!_mi_fetch_keypage(info,keyinfo,share->state.key_root[key], + DFLT_INIT_HITS,info->buff,0)) { mi_check_print_error(param,"Can't read indexpage from filepos: %s", llstr(share->state.key_root[key],buff)); @@ -548,7 +551,8 @@ static int chk_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo, info->state->key_file_length=(max_length & ~ (my_off_t) (info->s->blocksize-1)); } - if (!_mi_fetch_keypage(info,keyinfo,next_page,temp_buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,next_page, + DFLT_INIT_HITS,temp_buff,0)) { mi_check_print_error(param,"Can't read key from filepos: %s",llstr(next_page,llbuff)); goto err; @@ -1120,7 +1124,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, param->testflag|=T_REP; /* for easy checking */ if (!param->using_global_keycache) - VOID(init_key_cache(param->use_buffers)); + VOID(init_key_cache(dflt_keycache,dflt_key_cache_var.block_size, + param->use_buffers,&dflt_key_cache_var)); if (init_io_cache(¶m->read_cache,info->dfile, (uint) param->read_buffer_length, @@ -1441,7 +1446,8 @@ int movepoint(register MI_INFO *info, byte *record, my_off_t oldpos, nod_flag=mi_test_if_nod(info->buff); _mi_dpointer(info,info->int_keypos-nod_flag- info->s->rec_reflength,newpos); - if (_mi_write_keypage(info,keyinfo,info->last_keypage,info->buff)) + if (_mi_write_keypage(info,keyinfo,info->last_keypage, + DFLT_INIT_HITS,info->buff)) DBUG_RETURN(-1); } else @@ -1478,13 +1484,13 @@ void lock_memory(MI_CHECK *param __attribute__((unused))) int flush_blocks(MI_CHECK *param, File file) { - if (flush_key_blocks(file,FLUSH_RELEASE)) + if (flush_key_blocks(*dflt_keycache,file,FLUSH_RELEASE)) { mi_check_print_error(param,"%d when trying to write bufferts",my_errno); return(1); } if (!param->using_global_keycache) - end_key_cache(); + end_key_cache(dflt_keycache,1); return 0; } /* flush_blocks */ @@ -1538,7 +1544,7 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, my_string name) } /* Flush key cache for this file if we are calling this outside myisamchk */ - flush_key_blocks(share->kfile, FLUSH_IGNORE_CHANGED); + flush_key_blocks(*share->keycache,share->kfile, FLUSH_IGNORE_CHANGED); share->state.version=(ulong) time((time_t*) 0); old_state=share->state; /* save state if not stored */ @@ -1598,7 +1604,7 @@ static int sort_one_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo, mi_check_print_error(param,"Not Enough memory"); DBUG_RETURN(-1); } - if (!_mi_fetch_keypage(info,keyinfo,pagepos,buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,pagepos,DFLT_INIT_HITS,buff,0)) { mi_check_print_error(param,"Can't read key block from filepos: %s", llstr(pagepos,llbuff)); @@ -1844,7 +1850,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, Flush key cache for this file if we are calling this outside myisamchk */ - flush_key_blocks(share->kfile, FLUSH_IGNORE_CHANGED); + flush_key_blocks(*share->keycache,share->kfile, FLUSH_IGNORE_CHANGED); /* Clear the pointers to the given rows */ for (i=0 ; i < share->base.keys ; i++) share->state.key_root[i]= HA_OFFSET_ERROR; @@ -1854,7 +1860,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, } else { - if (flush_key_blocks(share->kfile, FLUSH_FORCE_WRITE)) + if (flush_key_blocks(*share->keycache,share->kfile, FLUSH_FORCE_WRITE)) goto err; key_map= ~key_map; /* Create the missing keys */ } @@ -2207,7 +2213,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, Flush key cache for this file if we are calling this outside myisamchk */ - flush_key_blocks(share->kfile, FLUSH_IGNORE_CHANGED); + flush_key_blocks(*share->keycache,share->kfile, FLUSH_IGNORE_CHANGED); /* Clear the pointers to the given rows */ for (i=0 ; i < share->base.keys ; i++) share->state.key_root[i]= HA_OFFSET_ERROR; @@ -2217,7 +2223,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, } else { - if (flush_key_blocks(share->kfile, FLUSH_FORCE_WRITE)) + if (flush_key_blocks(*share->keycache,share->kfile, FLUSH_FORCE_WRITE)) goto err; key_map= ~key_map; /* Create the missing keys */ } @@ -3332,13 +3338,13 @@ static int sort_insert_key(MI_SORT_PARAM *sort_param, bzero((byte*) anc_buff+key_block->last_length, keyinfo->block_length- key_block->last_length); key_file_length=info->state->key_file_length; - if ((filepos=_mi_new(info,keyinfo)) == HA_OFFSET_ERROR) + if ((filepos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR) DBUG_RETURN(1); /* If we read the page from the key cache, we have to write it back to it */ if (key_file_length == info->state->key_file_length) { - if (_mi_write_keypage(info, keyinfo, filepos, anc_buff)) + if (_mi_write_keypage(info, keyinfo, filepos, DFLT_INIT_HITS, anc_buff)) DBUG_RETURN(1); } else if (my_pwrite(info->s->kfile,(byte*) anc_buff, @@ -3436,13 +3442,14 @@ int flush_pending_blocks(MI_SORT_PARAM *sort_param) _mi_kpointer(info,key_block->end_pos,filepos); key_file_length=info->state->key_file_length; bzero((byte*) key_block->buff+length, keyinfo->block_length-length); - if ((filepos=_mi_new(info,keyinfo)) == HA_OFFSET_ERROR) + if ((filepos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR) DBUG_RETURN(1); /* If we read the page from the key cache, we have to write it back */ if (key_file_length == info->state->key_file_length) { - if (_mi_write_keypage(info, keyinfo, filepos, key_block->buff)) + if (_mi_write_keypage(info, keyinfo, filepos, + DFLT_INIT_HITS, key_block->buff)) DBUG_RETURN(1); } else if (my_pwrite(info->s->kfile,(byte*) key_block->buff, diff --git a/myisam/mi_close.c b/myisam/mi_close.c index dbaaebb1143..8e7fb497dfc 100644 --- a/myisam/mi_close.c +++ b/myisam/mi_close.c @@ -64,7 +64,7 @@ int mi_close(register MI_INFO *info) if (flag) { if (share->kfile >= 0 && - flush_key_blocks(share->kfile, + flush_key_blocks(*share->keycache,share->kfile, share->temporary ? FLUSH_IGNORE_CHANGED : FLUSH_RELEASE)) error=my_errno; diff --git a/myisam/mi_delete.c b/myisam/mi_delete.c index 2ab5c5d0319..5635e0a2139 100644 --- a/myisam/mi_delete.c +++ b/myisam/mi_delete.c @@ -155,7 +155,7 @@ static int _mi_ck_real_delete(register MI_INFO *info, MI_KEYDEF *keyinfo, DBUG_RETURN(my_errno=ENOMEM); } DBUG_PRINT("info",("root_page: %ld",old_root)); - if (!_mi_fetch_keypage(info,keyinfo,old_root,root_buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,old_root,DFLT_INIT_HITS,root_buff,0)) { error= -1; goto err; @@ -179,11 +179,12 @@ static int _mi_ck_real_delete(register MI_INFO *info, MI_KEYDEF *keyinfo, *root=_mi_kpos(nod_flag,root_buff+2+nod_flag); else *root=HA_OFFSET_ERROR; - if (_mi_dispose(info,keyinfo,old_root)) + if (_mi_dispose(info,keyinfo,old_root,DFLT_INIT_HITS)) error= -1; } else - error=_mi_write_keypage(info,keyinfo,old_root,root_buff); + error=_mi_write_keypage(info,keyinfo,old_root, + DFLT_INIT_HITS,root_buff); } } err: @@ -253,7 +254,7 @@ static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, { /* the last entry in sub-tree */ DBUG_PRINT("info",("FT2: the last entry")); - _mi_dispose(info, keyinfo, root); + _mi_dispose(info, keyinfo, root,DFLT_INIT_HITS); /* fall through to normal delete */ } else @@ -268,7 +269,8 @@ static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, subkeys++; ft_intXstore(kpos, subkeys); if (!ret_value) - ret_value=_mi_write_keypage(info,keyinfo,page,anc_buff); + ret_value=_mi_write_keypage(info,keyinfo,page, + DFLT_INIT_HITS,anc_buff); DBUG_PRINT("exit",("Return: %d",ret_value)); DBUG_RETURN(ret_value); } @@ -287,7 +289,7 @@ static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, DBUG_PRINT("exit",("Return: %d",-1)); DBUG_RETURN(-1); } - if (!_mi_fetch_keypage(info,keyinfo,leaf_page,leaf_buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff,0)) goto err; } @@ -319,7 +321,7 @@ static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, mi_putint(anc_buff,length,nod_flag); if (!nod_flag) { /* On leaf page */ - if (_mi_write_keypage(info,keyinfo,page,anc_buff)) + if (_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,anc_buff)) { DBUG_PRINT("exit",("Return: %d",-1)); DBUG_RETURN(-1); @@ -354,7 +356,7 @@ static int d_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, ret_value=_mi_split_page(info,keyinfo,key,anc_buff,lastkey,0) | 2; } if (save_flag && ret_value != 1) - ret_value|=_mi_write_keypage(info,keyinfo,page,anc_buff); + ret_value|=_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,anc_buff); else { DBUG_DUMP("page",(byte*) anc_buff,mi_getint(anc_buff)); @@ -398,7 +400,7 @@ static int del(register MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *key, if (!(next_buff= (uchar*) my_alloca((uint) keyinfo->block_length+ MI_MAX_KEY_BUFF*2))) DBUG_RETURN(-1); - if (!_mi_fetch_keypage(info,keyinfo,next_page,next_buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,next_buff,0)) ret_value= -1; else { @@ -426,7 +428,7 @@ static int del(register MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *key, (uchar*) 0,(uchar*) 0,(my_off_t) 0,0); } } - if (_mi_write_keypage(info,keyinfo,leaf_page,leaf_buff)) + if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff)) goto err; } my_afree((byte*) next_buff); @@ -436,7 +438,7 @@ static int del(register MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *key, /* Remove last key from leaf page */ mi_putint(leaf_buff,key_start-leaf_buff,nod_flag); - if (_mi_write_keypage(info,keyinfo,leaf_page,leaf_buff)) + if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff)) goto err; /* Place last key in ancestor page on deleted key position */ @@ -524,7 +526,7 @@ static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo, goto err; } next_page= _mi_kpos(key_reflength,next_keypos); - if (!_mi_fetch_keypage(info,keyinfo,next_page,buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff,0)) goto err; buff_length=mi_getint(buff); DBUG_DUMP("next",(byte*) buff,buff_length); @@ -563,7 +565,7 @@ static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo, if (buff_length <= keyinfo->block_length) { /* Keys in one page */ memcpy((byte*) leaf_buff,(byte*) buff,(size_t) buff_length); - if (_mi_dispose(info,keyinfo,next_page)) + if (_mi_dispose(info,keyinfo,next_page,DFLT_INIT_HITS)) goto err; } else @@ -612,10 +614,10 @@ static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo, (*keyinfo->store_key)(keyinfo,buff+p_length,&s_temp); mi_putint(buff,length+t_length+p_length,nod_flag); - if (_mi_write_keypage(info,keyinfo,next_page,buff)) + if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff)) goto err; } - if (_mi_write_keypage(info,keyinfo,leaf_page,leaf_buff)) + if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff)) goto err; DBUG_RETURN(anc_length <= ((info->quick_mode ? MI_MIN_BLOCK_LENGTH : (uint) keyinfo->underflow_block_length))); @@ -627,7 +629,7 @@ static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo, if (!keypos) goto err; next_page= _mi_kpos(key_reflength,keypos); - if (!_mi_fetch_keypage(info,keyinfo,next_page,buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff,0)) goto err; buff_length=mi_getint(buff); endpos=buff+buff_length; @@ -671,7 +673,7 @@ static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo, if (buff_length <= keyinfo->block_length) { /* Keys in one page */ - if (_mi_dispose(info,keyinfo,leaf_page)) + if (_mi_dispose(info,keyinfo,leaf_page,DFLT_INIT_HITS)) goto err; } else @@ -718,11 +720,11 @@ static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo, (size_t) length); (*keyinfo->store_key)(keyinfo,leaf_buff+p_length,&s_temp); mi_putint(leaf_buff,length+t_length+p_length,nod_flag); - if (_mi_write_keypage(info,keyinfo,leaf_page,leaf_buff)) + if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff)) goto err; mi_putint(buff,endpos-buff,nod_flag); } - if (_mi_write_keypage(info,keyinfo,next_page,buff)) + if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff)) goto err; DBUG_RETURN(anc_length <= (uint) keyinfo->block_length/2); err: diff --git a/myisam/mi_delete_all.c b/myisam/mi_delete_all.c index 45e56626d59..99873661feb 100644 --- a/myisam/mi_delete_all.c +++ b/myisam/mi_delete_all.c @@ -53,7 +53,7 @@ int mi_delete_all_rows(MI_INFO *info) If we are using delayed keys or if the user has done changes to the tables since it was locked then there may be key blocks in the key cache */ - flush_key_blocks(share->kfile, FLUSH_IGNORE_CHANGED); + flush_key_blocks(*share->keycache, share->kfile, FLUSH_IGNORE_CHANGED); if (my_chsize(info->dfile, 0, 0, MYF(MY_WME)) || my_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME)) ) goto err; diff --git a/myisam/mi_extra.c b/myisam/mi_extra.c index c86ca1c2e7b..1d57e0c0e18 100644 --- a/myisam/mi_extra.c +++ b/myisam/mi_extra.c @@ -283,7 +283,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) #ifdef __WIN__ /* Close the isam and data files as Win32 can't drop an open table */ pthread_mutex_lock(&share->intern_lock); - if (flush_key_blocks(share->kfile, + if (flush_key_blocks(*share->keycache, share->kfile, (function == HA_EXTRA_FORCE_REOPEN ? FLUSH_RELEASE : FLUSH_IGNORE_CHANGED))) { @@ -329,7 +329,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) break; case HA_EXTRA_FLUSH: if (!share->temporary) - flush_key_blocks(share->kfile,FLUSH_KEEP); + flush_key_blocks(*share->keycache,share->kfile,FLUSH_KEEP); #ifdef HAVE_PWRITE _mi_decrement_open_count(info); #endif @@ -374,6 +374,9 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) case HA_EXTRA_PRELOAD_BUFFER_SIZE: info->preload_buff_size= *((ulong *) extra_arg); break; + case HA_EXTRA_SET_KEY_CACHE: + share->reg_keycache= share->keycache= (KEY_CACHE_HANDLE *) extra_arg; + break; case HA_EXTRA_KEY_CACHE: case HA_EXTRA_NO_KEY_CACHE: default: diff --git a/myisam/mi_keycache.c b/myisam/mi_keycache.c new file mode 100644 index 00000000000..1010aef9e1d --- /dev/null +++ b/myisam/mi_keycache.c @@ -0,0 +1,63 @@ +/* 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 */ + +/* + Key cache assignments +*/ + +#include "myisamdef.h" + + +/* + Assign pages of the index file for a table to a key cache + + SYNOPSIS + mi_assign_to_keycache() + info open table + map map of indexes to assign to the key cache + key_cache_ptr pointer to the key cache handle + + RETURN VALUE + 0 if a success. error code - otherwise. + + NOTES. + At present pages for all indexes must be assigned to the same key cache. + In future only pages for indexes specified in the key_map parameter + of the table will be assigned to the specified key cache. +*/ + +int mi_assign_to_keycache(MI_INFO *info, ulonglong key_map, + KEY_CACHE_HANDLE *reg_keycache) +{ + int error= 0; + MYISAM_SHARE* share= info->s; + + DBUG_ENTER("mi_assign_to_keycache"); + + share->reg_keycache= reg_keycache; + if (!(info->lock_type == F_WRLCK && share->w_locks)) + { + if (flush_key_blocks(*share->keycache, share->kfile, FLUSH_RELEASE)) + { + error=my_errno; + mi_mark_crashed(info); /* Mark that table must be checked */ + } + share->keycache= reg_keycache; + } + + DBUG_RETURN(error); +} + diff --git a/myisam/mi_locking.c b/myisam/mi_locking.c index 22772a3dd2e..14d0b60741f 100644 --- a/myisam/mi_locking.c +++ b/myisam/mi_locking.c @@ -34,6 +34,7 @@ int mi_lock_database(MI_INFO *info, int lock_type) uint count; MYISAM_SHARE *share=info->s; uint flag; + uint switch_fl= 0; DBUG_ENTER("mi_lock_database"); if (share->options & HA_OPTION_READ_ONLY_DATA || @@ -58,12 +59,26 @@ int mi_lock_database(MI_INFO *info, int lock_type) else count= --share->w_locks; --share->tot_locks; + /* + During a key cache reassignment the current and registered + key caches for the table are different. + Although at present key cache ressignment is always + performed with a shared cache for the table acquired, + for future possible optimizations we still + handle this situation as if we could come to this point + during the ressignment (in non-reassignment thread). + */ if (info->lock_type == F_WRLCK && !share->w_locks && - !share->delay_key_write && flush_key_blocks(share->kfile,FLUSH_KEEP)) + ((switch_fl= share->keycache != share->reg_keycache) || + !share->delay_key_write) && + flush_key_blocks(*share->keycache, share->kfile, + switch_fl ? FLUSH_RELEASE : FLUSH_KEEP)) { error=my_errno; mi_mark_crashed(info); /* Mark that table must be checked */ } + if (switch_fl) + share->keycache= share->reg_keycache; if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED)) { if (end_io_cache(&info->rec_cache)) @@ -393,7 +408,7 @@ int _mi_test_if_changed(register MI_INFO *info) { /* Keyfile has changed */ DBUG_PRINT("info",("index file changed")); if (share->state.process != share->this_process) - VOID(flush_key_blocks(share->kfile,FLUSH_RELEASE)); + VOID(flush_key_blocks(*share->keycache,share->kfile,FLUSH_RELEASE)); share->last_process=share->state.process; info->last_unique= share->state.unique; info->last_loop= share->state.update_count; diff --git a/myisam/mi_page.c b/myisam/mi_page.c index 49f3243e08d..72aaac5d381 100644 --- a/myisam/mi_page.c +++ b/myisam/mi_page.c @@ -24,14 +24,16 @@ /* Fetch a key-page in memory */ uchar *_mi_fetch_keypage(register MI_INFO *info, MI_KEYDEF *keyinfo, - my_off_t page, uchar *buff, int return_buffer) + my_off_t page, int level, + uchar *buff, int return_buffer) { uchar *tmp; uint page_size; DBUG_ENTER("_mi_fetch_keypage"); DBUG_PRINT("enter",("page: %ld",page)); - tmp=(uchar*) key_cache_read(info->s->kfile,page,(byte*) buff, + tmp=(uchar*) key_cache_read(*info->s->keycache, + info->s->kfile, page, level, (byte*) buff, (uint) keyinfo->block_length, (uint) keyinfo->block_length, return_buffer); @@ -61,7 +63,7 @@ uchar *_mi_fetch_keypage(register MI_INFO *info, MI_KEYDEF *keyinfo, /* Write a key-page on disk */ int _mi_write_keypage(register MI_INFO *info, register MI_KEYDEF *keyinfo, - my_off_t page, uchar *buff) + my_off_t page, int level, uchar *buff) { reg3 uint length; DBUG_ENTER("_mi_write_keypage"); @@ -92,7 +94,8 @@ int _mi_write_keypage(register MI_INFO *info, register MI_KEYDEF *keyinfo, length=keyinfo->block_length; } #endif - DBUG_RETURN((key_cache_write(info->s->kfile,page,(byte*) buff,length, + DBUG_RETURN((key_cache_write(*info->s->keycache, + info->s->kfile,page, level, (byte*) buff,length, (uint) keyinfo->block_length, (int) ((info->lock_type != F_UNLCK) || info->s->delay_key_write)))); @@ -101,7 +104,8 @@ int _mi_write_keypage(register MI_INFO *info, register MI_KEYDEF *keyinfo, /* Remove page from disk */ -int _mi_dispose(register MI_INFO *info, MI_KEYDEF *keyinfo, my_off_t pos) +int _mi_dispose(register MI_INFO *info, MI_KEYDEF *keyinfo, my_off_t pos, + int level) { my_off_t old_link; char buff[8]; @@ -112,7 +116,8 @@ int _mi_dispose(register MI_INFO *info, MI_KEYDEF *keyinfo, my_off_t pos) info->s->state.key_del[keyinfo->block_size]=pos; mi_sizestore(buff,old_link); info->s->state.changed|= STATE_NOT_SORTED_PAGES; - DBUG_RETURN(key_cache_write(info->s->kfile,pos,buff, + DBUG_RETURN(key_cache_write(*info->s->keycache, + info->s->kfile, pos , level, buff, sizeof(buff), (uint) keyinfo->block_length, (int) (info->lock_type != F_UNLCK))); @@ -121,7 +126,7 @@ int _mi_dispose(register MI_INFO *info, MI_KEYDEF *keyinfo, my_off_t pos) /* Make new page on disk */ -my_off_t _mi_new(register MI_INFO *info, MI_KEYDEF *keyinfo) +my_off_t _mi_new(register MI_INFO *info, MI_KEYDEF *keyinfo, int level) { my_off_t pos; char buff[8]; @@ -140,7 +145,8 @@ my_off_t _mi_new(register MI_INFO *info, MI_KEYDEF *keyinfo) } else { - if (!key_cache_read(info->s->kfile,pos, + if (!key_cache_read(*info->s->keycache, + info->s->kfile, pos, level, buff, (uint) sizeof(buff), (uint) keyinfo->block_length,0)) diff --git a/myisam/mi_panic.c b/myisam/mi_panic.c index bd0b07b097e..f1d1d839fcd 100644 --- a/myisam/mi_panic.c +++ b/myisam/mi_panic.c @@ -48,7 +48,7 @@ int mi_panic(enum ha_panic_function flag) if (info->s->options & HA_OPTION_READ_ONLY_DATA) break; #endif - if (flush_key_blocks(info->s->kfile,FLUSH_RELEASE)) + if (flush_key_blocks(*info->s->keycache,info->s->kfile,FLUSH_RELEASE)) error=my_errno; if (info->opt_flag & WRITE_CACHE_USED) if (flush_io_cache(&info->rec_cache)) diff --git a/myisam/mi_preload.c b/myisam/mi_preload.c index a5d9bec160e..dc4fff5700a 100644 --- a/myisam/mi_preload.c +++ b/myisam/mi_preload.c @@ -69,7 +69,7 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves) if (!(buff= (uchar *) my_malloc(length, MYF(MY_WME)))) DBUG_RETURN(my_errno= HA_ERR_OUT_OF_MEM); - if (flush_key_blocks(share->kfile, FLUSH_RELEASE)) + if (flush_key_blocks(*share->keycache,share->kfile, FLUSH_RELEASE)) goto err; do @@ -87,7 +87,9 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves) { if (mi_test_if_nod(buff)) { - if (key_cache_insert(share->kfile, pos, (byte*) buff, block_length)) + if (key_cache_insert(*share->keycache, + share->kfile, pos, DFLT_INIT_HITS, + (byte*) buff, block_length)) goto err; } pos+= block_length; @@ -97,7 +99,9 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves) } else { - if (key_cache_insert(share->kfile, pos, (byte*) buff, length)) + if (key_cache_insert(*share->keycache, + share->kfile, pos, DFLT_INIT_HITS, + (byte*) buff, length)) goto err; pos+= length; } diff --git a/myisam/mi_range.c b/myisam/mi_range.c index 379ffba135a..caa57ce6187 100644 --- a/myisam/mi_range.c +++ b/myisam/mi_range.c @@ -142,7 +142,7 @@ static double _mi_search_pos(register MI_INFO *info, if (pos == HA_OFFSET_ERROR) DBUG_RETURN(0.5); - if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,info->buff,1))) + if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,DFLT_INIT_HITS,info->buff,1))) goto err; flag=(*keyinfo->bin_search)(info,keyinfo,buff,key,key_len,nextflag, &keypos,info->lastkey, &after_key); diff --git a/myisam/mi_search.c b/myisam/mi_search.c index 7e8577c0656..c2168d97cfe 100644 --- a/myisam/mi_search.c +++ b/myisam/mi_search.c @@ -76,7 +76,7 @@ int _mi_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, DBUG_RETURN(1); /* Search at upper levels */ } - if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,info->buff, + if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,DFLT_INIT_HITS,info->buff, test(!(nextflag & SEARCH_SAVE_BUFF))))) goto err; DBUG_DUMP("page",(byte*) buff,mi_getint(buff)); @@ -119,7 +119,7 @@ int _mi_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, if (pos != info->last_keypage) { uchar *old_buff=buff; - if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,info->buff, + if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,DFLT_INIT_HITS,info->buff, test(!(nextflag & SEARCH_SAVE_BUFF))))) goto err; keypos=buff+(keypos-old_buff); @@ -1105,7 +1105,7 @@ int _mi_search_next(register MI_INFO *info, register MI_KEYDEF *keyinfo, if (info->buff_used) { if (!_mi_fetch_keypage(info,keyinfo,info->last_search_keypage, - info->buff,0)) + DFLT_INIT_HITS,info->buff,0)) DBUG_RETURN(-1); info->buff_used=0; } @@ -1174,7 +1174,7 @@ int _mi_search_first(register MI_INFO *info, register MI_KEYDEF *keyinfo, do { - if (!_mi_fetch_keypage(info,keyinfo,pos,info->buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,pos,DFLT_INIT_HITS,info->buff,0)) { info->lastpos= HA_OFFSET_ERROR; DBUG_RETURN(-1); @@ -1217,7 +1217,7 @@ int _mi_search_last(register MI_INFO *info, register MI_KEYDEF *keyinfo, buff=info->buff; do { - if (!_mi_fetch_keypage(info,keyinfo,pos,buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,pos,DFLT_INIT_HITS,buff,0)) { info->lastpos= HA_OFFSET_ERROR; DBUG_RETURN(-1); diff --git a/myisam/mi_test1.c b/myisam/mi_test1.c index 5a6818b8a3e..ec68e23c0c2 100644 --- a/myisam/mi_test1.c +++ b/myisam/mi_test1.c @@ -50,7 +50,7 @@ int main(int argc,char *argv[]) MY_INIT(argv[0]); my_init(); if (key_cacheing) - init_key_cache(IO_SIZE*16); + init_key_cache(dflt_keycache,512,IO_SIZE*16,0); get_options(argc,argv); exit(run_test("test1")); diff --git a/myisam/mi_test2.c b/myisam/mi_test2.c index 8dc279b6d97..61a14adf1ce 100644 --- a/myisam/mi_test2.c +++ b/myisam/mi_test2.c @@ -49,6 +49,7 @@ static int verbose=0,testflag=0, static int pack_seg=HA_SPACE_PACK,pack_type=HA_PACK_KEY,remove_count=-1, create_flag=0; static ulong key_cache_size=IO_SIZE*16; +static uint key_cache_block_size=IO_SIZE; static uint keys=MYISAM_KEYS,recant=1000; static uint use_blob=0; @@ -214,7 +215,7 @@ int main(int argc, char *argv[]) if (!silent) printf("- Writing key:s\n"); if (key_cacheing) - init_key_cache(key_cache_size); /* Use a small cache */ + init_key_cache(dflt_keycache,key_cache_block_size,key_cache_size,0); /* Use a small cache */ if (locking) mi_lock_database(file,F_WRLCK); if (write_cacheing) @@ -274,7 +275,7 @@ int main(int argc, char *argv[]) goto end; } if (key_cacheing) - resize_key_cache(key_cache_size*2); + resize_key_cache(dflt_keycache,key_cache_block_size,key_cache_size*2); } if (!silent) @@ -816,16 +817,19 @@ end: puts("Locking used"); if (use_blob) puts("blobs used"); +#if 0 printf("key cache status: \n\ blocks used:%10lu\n\ w_requests: %10lu\n\ writes: %10lu\n\ r_requests: %10lu\n\ reads: %10lu\n", - my_blocks_used, my_cache_w_requests, my_cache_write, + my_blocks_used, + my_cache_w_requests, my_cache_write, my_cache_r_requests, my_cache_read); +#endif } - end_key_cache(); + end_key_cache(dflt_keycache,1); if (blob_buffer) my_free(blob_buffer,MYF(0)); my_end(silent ? MY_CHECK_ERROR : MY_CHECK_ERROR | MY_GIVE_INFO); diff --git a/myisam/mi_test3.c b/myisam/mi_test3.c index 63cea4f715d..866c6299fac 100644 --- a/myisam/mi_test3.c +++ b/myisam/mi_test3.c @@ -177,7 +177,7 @@ void start_test(int id) exit(1); } if (key_cacheing && rnd(2) == 0) - init_key_cache(65536L); + init_key_cache(dflt_keycache,512,65536L,0); printf("Process %d, pid: %d\n",id,getpid()); fflush(stdout); for (error=i=0 ; i < tests && !error; i++) diff --git a/myisam/mi_write.c b/myisam/mi_write.c index 6985dac7832..8c08d6f179e 100644 --- a/myisam/mi_write.c +++ b/myisam/mi_write.c @@ -290,8 +290,8 @@ int _mi_enlarge_root(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, mi_putint(info->buff,t_length+2+nod_flag,nod_flag); (*keyinfo->store_key)(keyinfo,info->buff+2+nod_flag,&s_temp); info->buff_used=info->page_changed=1; /* info->buff is used */ - if ((*root= _mi_new(info,keyinfo)) == HA_OFFSET_ERROR || - _mi_write_keypage(info,keyinfo,*root,info->buff)) + if ((*root= _mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR || + _mi_write_keypage(info,keyinfo,*root,DFLT_INIT_HITS,info->buff)) DBUG_RETURN(-1); DBUG_RETURN(0); } /* _mi_enlarge_root */ @@ -322,7 +322,7 @@ static int w_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, if (!(temp_buff= (uchar*) my_alloca((uint) keyinfo->block_length+ MI_MAX_KEY_BUFF*2))) DBUG_RETURN(-1); - if (!_mi_fetch_keypage(info,keyinfo,page,temp_buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff,0)) goto err; flag=(*keyinfo->bin_search)(info,keyinfo,temp_buff,key,search_key_length, @@ -368,7 +368,7 @@ static int w_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, subkeys--; /* should there be underflow protection ? */ ft_intXstore(keypos, subkeys); if (!error) - error=_mi_write_keypage(info,keyinfo,page,temp_buff); + error=_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff); my_afree((byte*) temp_buff); DBUG_RETURN(error); } @@ -391,7 +391,7 @@ static int w_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, { error=_mi_insert(info,keyinfo,key,temp_buff,keypos,keybuff,father_buff, father_keypos,father_page, insert_last); - if (_mi_write_keypage(info,keyinfo,page,temp_buff)) + if (_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,temp_buff)) goto err; } my_afree((byte*) temp_buff); @@ -515,7 +515,7 @@ int _mi_split_page(register MI_INFO *info, register MI_KEYDEF *keyinfo, } /* Move middle item to key and pointer to new page */ - if ((new_pos=_mi_new(info,keyinfo)) == HA_OFFSET_ERROR) + if ((new_pos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR) DBUG_RETURN(-1); _mi_kpointer(info,_mi_move_key(keyinfo,key,key_buff),new_pos); @@ -531,7 +531,7 @@ int _mi_split_page(register MI_INFO *info, register MI_KEYDEF *keyinfo, (*keyinfo->store_key)(keyinfo,info->buff+key_ref_length,&s_temp); mi_putint(info->buff,length+t_length+key_ref_length,nod_flag); - if (_mi_write_keypage(info,keyinfo,new_pos,info->buff)) + if (_mi_write_keypage(info,keyinfo,new_pos,DFLT_INIT_HITS,info->buff)) DBUG_RETURN(-1); DBUG_DUMP("key",(byte*) key,_mi_keylength(keyinfo,key)); DBUG_RETURN(2); /* Middle key up */ @@ -682,7 +682,7 @@ static int _mi_balance_page(register MI_INFO *info, MI_KEYDEF *keyinfo, DBUG_PRINT("test",("use left page: %lu",next_page)); } /* father_key_pos ptr to parting key */ - if (!_mi_fetch_keypage(info,keyinfo,next_page,info->buff,0)) + if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,info->buff,0)) goto err; DBUG_DUMP("next",(byte*) info->buff,mi_getint(info->buff)); @@ -722,8 +722,8 @@ static int _mi_balance_page(register MI_INFO *info, MI_KEYDEF *keyinfo, memcpy((byte*) buff+2,(byte*) pos+k_length,(size_t) length); } - if (_mi_write_keypage(info,keyinfo,next_page,info->buff) || - _mi_write_keypage(info,keyinfo,father_page,father_buff)) + if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,info->buff) || + _mi_write_keypage(info,keyinfo,father_page,DFLT_INIT_HITS,father_buff)) goto err; DBUG_RETURN(0); } @@ -763,12 +763,13 @@ static int _mi_balance_page(register MI_INFO *info, MI_KEYDEF *keyinfo, memcpy((byte*) (right ? key : father_key_pos),pos,(size_t) k_length); memcpy((byte*) (right ? father_key_pos : key),tmp_part_key, k_length); - if ((new_pos=_mi_new(info,keyinfo)) == HA_OFFSET_ERROR) + if ((new_pos=_mi_new(info,keyinfo,DFLT_INIT_HITS)) == HA_OFFSET_ERROR) goto err; _mi_kpointer(info,key+k_length,new_pos); if (_mi_write_keypage(info,keyinfo,(right ? new_pos : next_page), - info->buff) || - _mi_write_keypage(info,keyinfo,(right ? next_page : new_pos),extra_buff)) + DFLT_INIT_HITS,info->buff) || + _mi_write_keypage(info,keyinfo,(right ? next_page : new_pos), + DFLT_INIT_HITS,extra_buff)) goto err; DBUG_RETURN(1); /* Middle key up */ diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c index 43ade35bfd5..63d61af774b 100644 --- a/myisam/myisamchk.c +++ b/myisam/myisamchk.c @@ -44,6 +44,7 @@ static const char *load_default_groups[]= { "myisamchk", 0 }; static const char *set_charset_name, *opt_tmpdir; static CHARSET_INFO *set_charset; static long opt_myisam_block_size; +static long opt_key_cache_block_size; static const char *my_progname_short; static int stopwords_inited= 0; static MY_TMPDIR myisamchk_tmpdir; @@ -148,7 +149,8 @@ int main(int argc, char **argv) enum options { OPT_CHARSETS_DIR=256, OPT_SET_CHARSET,OPT_START_CHECK_POS, - OPT_CORRECT_CHECKSUM, OPT_KEY_BUFFER_SIZE, OPT_MYISAM_BLOCK_SIZE, + OPT_CORRECT_CHECKSUM, OPT_KEY_BUFFER_SIZE, + OPT_KEY_CACHE_BLOCK_SIZE, OPT_MYISAM_BLOCK_SIZE, OPT_READ_BUFFER_SIZE, OPT_WRITE_BUFFER_SIZE, OPT_SORT_BUFFER_SIZE, OPT_SORT_KEY_BLOCKS, OPT_DECODE_BITS, OPT_FT_MIN_WORD_LEN, OPT_FT_MAX_WORD_LEN, OPT_FT_MAX_WORD_LEN_FOR_SORT @@ -283,6 +285,11 @@ static struct my_option my_long_options[] = (gptr*) &check_param.use_buffers, (gptr*) &check_param.use_buffers, 0, GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD, (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0}, + { "key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE, "", + (gptr*) &opt_key_cache_block_size, + (gptr*) &opt_key_cache_block_size, 0, + GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH, + MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0}, { "myisam_block_size", OPT_MYISAM_BLOCK_SIZE, "", (gptr*) &opt_myisam_block_size, (gptr*) &opt_myisam_block_size, 0, GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH, @@ -1017,7 +1024,8 @@ static int myisamchk(MI_CHECK *param, my_string filename) !(param->testflag & (T_FAST | T_FORCE_CREATE))) { if (param->testflag & (T_EXTEND | T_MEDIUM)) - VOID(init_key_cache(param->use_buffers)); + VOID(init_key_cache(dflt_keycache,opt_key_cache_block_size, + param->use_buffers,&dflt_key_cache_var)); VOID(init_io_cache(¶m->read_cache,datafile, (uint) param->read_buffer_length, READ_CACHE, @@ -1439,7 +1447,8 @@ static int mi_sort_records(MI_CHECK *param, if (share->state.key_root[sort_key] == HA_OFFSET_ERROR) DBUG_RETURN(0); /* Nothing to do */ - init_key_cache(param->use_buffers); + init_key_cache(dflt_keycache,opt_key_cache_block_size,param->use_buffers, + &dflt_key_cache_var); if (init_io_cache(&info->rec_cache,-1,(uint) param->write_buffer_length, WRITE_CACHE,share->pack.header_length,1, MYF(MY_WME | MY_WAIT_IF_FULL))) diff --git a/myisam/myisamdef.h b/myisam/myisamdef.h index 83e28a42797..9ed0e3ca3a2 100644 --- a/myisam/myisamdef.h +++ b/myisam/myisamdef.h @@ -166,6 +166,8 @@ typedef struct st_mi_isam_share { /* Shared between opens */ char *data_file_name, /* Resolved path names from symlinks */ *index_file_name; byte *file_map; /* mem-map of file if possible */ + KEY_CACHE_HANDLE *keycache; /* ref to the current key cache */ + KEY_CACHE_HANDLE *reg_keycache; /* ref to the registered key cache */ MI_DECODE_TREE *decode_trees; uint16 *decode_tables; int (*read_record)(struct st_myisam_info*, my_off_t, byte*); @@ -546,11 +548,12 @@ extern int _mi_search_next(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, extern int _mi_search_first(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos); extern int _mi_search_last(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos); extern uchar *_mi_fetch_keypage(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t page, - uchar *buff,int return_buffer); + int level,uchar *buff,int return_buffer); extern int _mi_write_keypage(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t page, - uchar *buff); -extern int _mi_dispose(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos); -extern my_off_t _mi_new(MI_INFO *info,MI_KEYDEF *keyinfo); + int level, uchar *buff); +extern int _mi_dispose(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos, + int level); +extern my_off_t _mi_new(MI_INFO *info,MI_KEYDEF *keyinfo,int level); extern uint _mi_make_key(MI_INFO *info,uint keynr,uchar *key, const byte *record,my_off_t filepos); extern uint _mi_pack_key(MI_INFO *info,uint keynr,uchar *key,uchar *old, diff --git a/myisam/myisamlog.c b/myisam/myisamlog.c index 4bb7cc55d30..5bca25dd439 100644 --- a/myisam/myisamlog.c +++ b/myisam/myisamlog.c @@ -333,7 +333,8 @@ static int examine_log(my_string file_name, char **table_names) bzero((gptr) com_count,sizeof(com_count)); init_tree(&tree,0,0,sizeof(file_info),(qsort_cmp2) file_info_compare,1, (tree_element_free) file_info_free, NULL); - VOID(init_key_cache(KEY_CACHE_SIZE)); + VOID(init_key_cache(dflt_keycache,KEY_CACHE_BLOCK_SIZE,KEY_CACHE_SIZE, + &dflt_key_cache_var)); files_open=0; access_time=0; while (access_time++ != number_of_commands && @@ -639,7 +640,7 @@ static int examine_log(my_string file_name, char **table_names) goto end; } } - end_key_cache(); + end_key_cache(dflt_keycache,1); delete_tree(&tree); VOID(end_io_cache(&cache)); VOID(my_close(file,MYF(0))); @@ -659,7 +660,7 @@ static int examine_log(my_string file_name, char **table_names) llstr(isamlog_filepos,llbuff))); fflush(stderr); end: - end_key_cache(); + end_key_cache(dflt_keycache,1); delete_tree(&tree); VOID(end_io_cache(&cache)); VOID(my_close(file,MYF(0))); diff --git a/myisam/rt_index.c b/myisam/rt_index.c index f02d6121eb5..8b877d2e65c 100644 --- a/myisam/rt_index.c +++ b/myisam/rt_index.c @@ -60,7 +60,7 @@ static int rtree_find_req(MI_INFO *info, MI_KEYDEF *keyinfo, uint search_flag, u my_errno = HA_ERR_OUT_OF_MEM; return -1; } - if (!_mi_fetch_keypage(info, keyinfo, page, page_buf, 0)) + if (!_mi_fetch_keypage(info, keyinfo, page, DFLT_INIT_HITS, page_buf, 0)) goto err1; nod_flag = mi_test_if_nod(page_buf); @@ -257,7 +257,7 @@ static int rtree_get_req(MI_INFO *info, MI_KEYDEF *keyinfo, uint key_length, if (!(page_buf = (uchar*)my_alloca((uint)keyinfo->block_length))) return -1; - if (!_mi_fetch_keypage(info, keyinfo, page, page_buf, 0)) + if (!_mi_fetch_keypage(info, keyinfo, page, DFLT_INIT_HITS, page_buf, 0)) goto err1; nod_flag = mi_test_if_nod(page_buf); @@ -429,7 +429,7 @@ static int rtree_insert_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, my_errno = HA_ERR_OUT_OF_MEM; return -1; } - if (!_mi_fetch_keypage(info, keyinfo, page, page_buf, 0)) + if (!_mi_fetch_keypage(info, keyinfo, page, DFLT_INIT_HITS, page_buf, 0)) goto err1; nod_flag = mi_test_if_nod(page_buf); @@ -445,7 +445,7 @@ static int rtree_insert_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, case 0: /* child was not split */ { rtree_combine_rect(keyinfo->seg, k, key, k, key_length); - if (_mi_write_keypage(info, keyinfo, page, page_buf)) + if (_mi_write_keypage(info, keyinfo, page, DFLT_INIT_HITS, page_buf)) goto err1; goto ok; } @@ -462,7 +462,7 @@ static int rtree_insert_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, goto err1; res = rtree_add_key(info, keyinfo, new_key, key_length, page_buf, new_page); - if (_mi_write_keypage(info, keyinfo, page, page_buf)) + if (_mi_write_keypage(info, keyinfo, page, DFLT_INIT_HITS, page_buf)) goto err1; goto ok; } @@ -476,7 +476,7 @@ static int rtree_insert_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, else { res = rtree_add_key(info, keyinfo, key, key_length, page_buf, new_page); - if (_mi_write_keypage(info, keyinfo, page, page_buf)) + if (_mi_write_keypage(info, keyinfo, page, DFLT_INIT_HITS, page_buf)) goto err1; goto ok; } @@ -509,12 +509,12 @@ static int rtree_insert_level(MI_INFO *info, uint keynr, uchar *key, { int res; - if ((old_root = _mi_new(info, keyinfo)) == HA_OFFSET_ERROR) + if ((old_root = _mi_new(info, keyinfo, DFLT_INIT_HITS)) == HA_OFFSET_ERROR) return -1; info->buff_used = 1; mi_putint(info->buff, 2, 0); res = rtree_add_key(info, keyinfo, key, key_length, info->buff, NULL); - if (_mi_write_keypage(info, keyinfo, old_root, info->buff)) + if (_mi_write_keypage(info, keyinfo, old_root, DFLT_INIT_HITS, info->buff)) return 1; info->s->state.key_root[keynr] = old_root; return res; @@ -542,7 +542,8 @@ static int rtree_insert_level(MI_INFO *info, uint keynr, uchar *key, } mi_putint(new_root_buf, 2, nod_flag); - if ((new_root = _mi_new(info, keyinfo)) == HA_OFFSET_ERROR) + if ((new_root = _mi_new(info, keyinfo, DFLT_INIT_HITS)) == + HA_OFFSET_ERROR) goto err1; new_key = new_root_buf + keyinfo->block_length + nod_flag; @@ -559,7 +560,8 @@ static int rtree_insert_level(MI_INFO *info, uint keynr, uchar *key, if (rtree_add_key(info, keyinfo, new_key, key_length, new_root_buf, NULL) == -1) goto err1; - if (_mi_write_keypage(info, keyinfo, new_root, new_root_buf)) + if (_mi_write_keypage(info, keyinfo, new_root, + DFLT_INIT_HITS, new_root_buf)) goto err1; info->s->state.key_root[keynr] = new_root; @@ -636,7 +638,7 @@ static int rtree_delete_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, my_errno = HA_ERR_OUT_OF_MEM; return -1; } - if (!_mi_fetch_keypage(info, keyinfo, page, page_buf, 0)) + if (!_mi_fetch_keypage(info, keyinfo, page, DFLT_INIT_HITS, page_buf, 0)) goto err1; nod_flag = mi_test_if_nod(page_buf); @@ -662,7 +664,8 @@ static int rtree_delete_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, if (rtree_set_key_mbr(info, keyinfo, k, key_length, _mi_kpos(nod_flag, k))) goto err1; - if (_mi_write_keypage(info, keyinfo, page, page_buf)) + if (_mi_write_keypage(info, keyinfo, page, + DFLT_INIT_HITS, page_buf)) goto err1; } else @@ -672,7 +675,8 @@ static int rtree_delete_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, level + 1)) goto err1; rtree_delete_key(info, page_buf, k, key_length, nod_flag); - if (_mi_write_keypage(info, keyinfo, page, page_buf)) + if (_mi_write_keypage(info, keyinfo, page, + DFLT_INIT_HITS, page_buf)) goto err1; *page_size = mi_getint(page_buf); } @@ -686,7 +690,8 @@ static int rtree_delete_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, case 2: /* vacuous case: last key in the leaf */ { rtree_delete_key(info, page_buf, k, key_length, nod_flag); - if (_mi_write_keypage(info, keyinfo, page, page_buf)) + if (_mi_write_keypage(info, keyinfo, page, + DFLT_INIT_HITS, page_buf)) goto err1; *page_size = mi_getint(page_buf); res = 0; @@ -711,13 +716,13 @@ static int rtree_delete_req(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, { /* last key in the leaf */ res = 2; - if (_mi_dispose(info, keyinfo, page)) + if (_mi_dispose(info, keyinfo, page, DFLT_INIT_HITS)) goto err1; } else { res = 0; - if (_mi_write_keypage(info, keyinfo, page, page_buf)) + if (_mi_write_keypage(info, keyinfo, page, DFLT_INIT_HITS, page_buf)) goto err1; } goto ok; @@ -783,7 +788,7 @@ int rtree_delete(MI_INFO *info, uint keynr, uchar *key, uint key_length) goto err1; } if (!_mi_fetch_keypage(info, keyinfo, ReinsertList.pages[i].offs, - page_buf, 0)) + DFLT_INIT_HITS, page_buf, 0)) goto err1; nod_flag = mi_test_if_nod(page_buf); k = rt_PAGE_FIRST_KEY(page_buf, nod_flag); @@ -798,7 +803,8 @@ int rtree_delete(MI_INFO *info, uint keynr, uchar *key, uint key_length) } } my_afree((byte*)page_buf); - if (_mi_dispose(info, keyinfo, ReinsertList.pages[i].offs)) + if (_mi_dispose(info, keyinfo, ReinsertList.pages[i].offs, + DFLT_INIT_HITS)) goto err1; } if (ReinsertList.pages) @@ -807,7 +813,8 @@ int rtree_delete(MI_INFO *info, uint keynr, uchar *key, uint key_length) /* check for redundant root (not leaf, 1 child) and eliminate */ if ((old_root = info->s->state.key_root[keynr]) == HA_OFFSET_ERROR) goto err1; - if (!_mi_fetch_keypage(info, keyinfo, old_root, info->buff, 0)) + if (!_mi_fetch_keypage(info, keyinfo, old_root, DFLT_INIT_HITS, + info->buff, 0)) goto err1; nod_flag = mi_test_if_nod(info->buff); page_size = mi_getint(info->buff); @@ -816,7 +823,7 @@ int rtree_delete(MI_INFO *info, uint keynr, uchar *key, uint key_length) { my_off_t new_root = _mi_kpos(nod_flag, rt_PAGE_FIRST_KEY(info->buff, nod_flag)); - if (_mi_dispose(info, keyinfo, old_root)) + if (_mi_dispose(info, keyinfo, old_root, DFLT_INIT_HITS)) goto err1; info->s->state.key_root[keynr] = new_root; } @@ -863,7 +870,7 @@ ha_rows rtree_estimate(MI_INFO *info, uint keynr, uchar *key, return HA_POS_ERROR; if (!(page_buf = (uchar*)my_alloca((uint)keyinfo->block_length))) return HA_POS_ERROR; - if (!_mi_fetch_keypage(info, keyinfo, root, page_buf, 0)) + if (!_mi_fetch_keypage(info, keyinfo, root, DFLT_INIT_HITS, page_buf, 0)) goto err1; nod_flag = mi_test_if_nod(page_buf); diff --git a/myisam/rt_key.c b/myisam/rt_key.c index dfabf7624d2..f18d13af8d8 100644 --- a/myisam/rt_key.c +++ b/myisam/rt_key.c @@ -88,7 +88,8 @@ int rtree_delete_key(MI_INFO *info, uchar *page_buf, uchar *key, int rtree_set_key_mbr(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *key, uint key_length, my_off_t child_page) { - if (!_mi_fetch_keypage(info, keyinfo, child_page, info->buff, 0)) + if (!_mi_fetch_keypage(info, keyinfo, child_page, + DFLT_INIT_HITS, info->buff, 0)) return -1; return rtree_page_mbr(info, keyinfo->seg, info->buff, key, key_length); diff --git a/myisam/rt_split.c b/myisam/rt_split.c index 72a3c4887ab..41d6f8f8ccd 100644 --- a/myisam/rt_split.c +++ b/myisam/rt_split.c @@ -332,10 +332,12 @@ int rtree_split_page(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *page, uchar *key, mi_putint(page, 2 + n1 * full_length, nod_flag); mi_putint(new_page, 2 + n2 * full_length, nod_flag); - if ((*new_page_offs= _mi_new(info, keyinfo)) == HA_OFFSET_ERROR) + if ((*new_page_offs= _mi_new(info, keyinfo, DFLT_INIT_HITS)) == + HA_OFFSET_ERROR) err_code= -1; else - err_code= _mi_write_keypage(info, keyinfo, *new_page_offs, new_page); + err_code= _mi_write_keypage(info, keyinfo, *new_page_offs, + DFLT_INIT_HITS, new_page); my_afree((byte*)new_page); |