From f7aed0240511510dfe51083bd7ff12482d8716bc Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jun 2003 04:29:02 -0700 Subject: Many files: New feature: preload indexes into key cache. mi_preload.c: new file Many files: Added preload statement. sql/ha_myisam.h: Added preload statement. sql/handler.cc: Added preload statement. sql/lex.h: Added preload statement. sql/mysql_priv.h: Added preload statement. sql/sql_lex.h: Added preload statement. sql/sql_base.cc: Added preload statement. sql/sql_table.cc: New feature: preload indexes into key cache. sql/sql_parse.cc: New feature: preload indexes into key cache. sql/mysqld.cc: New feature: preload indexes into key cache. sql/set_var.cc: New feature: preload indexes into key cache. sql/sql_yacc.yy: New feature: preload indexes into key cache. sql/ha_myisam.cc: New feature: preload indexes into key cache. sql/table.h: New feature: preload indexes into key cache. mysys/mf_keycache.c: New feature: preload indexes into key cache. myisam/myisamdef.h: New feature: preload indexes into key cache. myisam/mi_extra.c: New feature: preload indexes into key cache. myisam/Makefile.am: New feature: preload indexes into key cache. include/my_base.h: New feature: preload indexes into key cache. include/my_sys.h: New feature: preload indexes into key cache. include/myisam.h: New feature: preload indexes into key cache. --- mysys/mf_keycache.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'mysys') diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index 264037e9a70..3276044fc2f 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -1258,6 +1258,86 @@ byte *key_cache_read(File file, my_off_t filepos, byte *buff, uint length, } +/* + Insert a block of file data from a buffer into key cache + + SYNOPSIS + key_cache_insert() + file file descriptor + filepos file offset of the data from the buffer + buff buffer with data to insert into key cache + length length of the data in the buffer + + RETURN VALUE + 0 if a success, 1 -otherwise. +*/ + +int key_cache_insert(File file, my_off_t filepos, byte *buff, uint length) +{ + DBUG_ENTER("key_cache_insert"); + DBUG_PRINT("enter", ("file %u, filepos %lu, length %u", + (uint) file,(ulong) filepos, length)); + + if (my_disk_blocks > 0) + { + /* Key cache is used */ + reg1 BLOCK_LINK *block; + uint offset= (uint) (filepos & (key_cache_block_size-1)); + uint read_length; + int page_st; + + /* Read data into key cache from buff in key_cache_block_size increments */ + filepos-= offset; + do + { + read_length= length > key_cache_block_size ? + key_cache_block_size : length; + KEYCACHE_DBUG_ASSERT(read_length > 0); + keycache_pthread_mutex_lock(&THR_LOCK_keycache); + my_cache_r_requests++; + block=find_key_block(file, filepos, 0, &page_st); + if (block->status != BLOCK_ERROR && page_st != PAGE_READ) + { + /* The requested page is to be read into the block buffer */ +#if !defined(SERIALIZED_READ_FROM_CACHE) + keycache_pthread_mutex_unlock(&THR_LOCK_keycache); +#endif + + /* Copy data from buff */ + if (!(read_length & 511)) + bmove512(block->buffer+offset, buff, read_length); + else + memcpy(block->buffer+offset, buff, (size_t) read_length); + +#if !defined(SERIALIZED_READ_FROM_CACHE) + keycache_pthread_mutex_lock(&THR_LOCK_keycache); +#endif + block->status= BLOCK_READ; + block->length= read_length+offset; + } + + remove_reader(block); + /* + Link the block into the LRU chain + if it's the last submitted request for the block + */ + unreg_request(block,1); + + keycache_pthread_mutex_unlock(&THR_LOCK_keycache); + + if (block->status & BLOCK_ERROR) + DBUG_RETURN(1); + + buff+=read_length; + filepos+=read_length; + offset=0; + + } while ((length-= read_length)); + } + DBUG_RETURN(0); +} + + /* Write a buffer into disk; filepos must be a multiple of 'block_length', but it doesn't -- cgit v1.2.1