summaryrefslogtreecommitdiff
path: root/sql/ha_myisam.cc
diff options
context:
space:
mode:
authorunknown <igor@rurik.mysql.com>2003-10-30 10:45:28 -0800
committerunknown <igor@rurik.mysql.com>2003-10-30 10:45:28 -0800
commit52e86548c2ed957e1bef549c38a5b391cd3f47c6 (patch)
treebfd8508896ec045400e82650920bcfd37e53a8f1 /sql/ha_myisam.cc
parenta4161274ef18a38eff95272cf9f05f46fb08fcb7 (diff)
parent06ecf87e15d8e8d7ae24aa23ccead4a2c4bbc78e (diff)
downloadmariadb-git-52e86548c2ed957e1bef549c38a5b391cd3f47c6.tar.gz
Merge
include/my_base.h: Auto merged include/my_global.h: Auto merged include/my_sys.h: Auto merged isam/test2.c: Auto merged myisam/mi_check.c: Auto merged myisam/mi_test2.c: Auto merged myisam/myisamchk.c: Auto merged myisam/myisamdef.h: Auto merged mysql-test/r/func_group.result: 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_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_test.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/mysqld.cc: SCCS merged sql/set_var.cc: SCCS merged
Diffstat (limited to 'sql/ha_myisam.cc')
-rw-r--r--sql/ha_myisam.cc131
1 files changed, 131 insertions, 0 deletions
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 864ee55a85f..aa889b649d0 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -228,6 +228,12 @@ int ha_myisam::open(const char *name, int mode, uint test_if_locked)
{
if (!(file=mi_open(name, mode, test_if_locked)))
return (my_errno ? my_errno : -1);
+
+ /* Synchronize key cache assignment of the handler */
+ KEY_CACHE_VAR *key_cache= table->key_cache ? table->key_cache :
+ &dflt_key_cache_var;
+ VOID(mi_extra(file, HA_EXTRA_SET_KEY_CACHE,
+ (void*) &key_cache->cache));
if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE))
VOID(mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0));
@@ -692,6 +698,131 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
/*
+ Assign table indexes to a key cache.
+*/
+
+int ha_myisam::assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt)
+{
+ uint len;
+ KEY_CACHE_VAR *old_key_cache;
+ KEY_CACHE_VAR *new_key_cache;
+ const char *errmsg=0;
+ int error= HA_ADMIN_OK;
+ ulonglong map= ~(ulonglong) 0;
+ TABLE_LIST *table_list= table->pos_in_table_list;
+ const char *new_key_cache_name= table_list->option ?
+ (const char *) table_list->option :
+ DEFAULT_KEY_CACHE_NAME;
+ KEY_CACHE_ASMT *key_cache_asmt= table->key_cache_asmt;
+ bool triggered= key_cache_asmt->triggered;
+
+ DBUG_ENTER("ha_myisam::assign_to_keycache");
+
+ VOID(pthread_mutex_lock(&LOCK_assign));
+
+ old_key_cache= key_cache_asmt->key_cache;
+
+ /* Check validity of the index references */
+ if (!triggered && table_list->use_index)
+ {
+ key_map kmap= get_key_map_from_key_list(table, table_list->use_index);
+ if (kmap == ~(key_map) 0)
+ {
+ errmsg= thd->net.last_error;
+ error= HA_ADMIN_FAILED;
+ goto err;
+ }
+ if (kmap)
+ map= kmap;
+ }
+
+ len= strlen(new_key_cache_name);
+ new_key_cache= get_or_create_key_cache(new_key_cache_name, len);
+ if (old_key_cache == new_key_cache)
+ {
+ /* Nothing to do: table is assigned to the same key cache */
+ goto ok;
+ }
+
+ if (!new_key_cache ||
+ (!new_key_cache->cache && ha_key_cache(new_key_cache)))
+ {
+ if (key_cache_asmt->triggered)
+ error= HA_ERR_OUT_OF_MEM;
+ else
+ {
+ char buf[ERRMSGSIZE];
+ my_snprintf(buf, ERRMSGSIZE,
+ "Failed to create key cache %s", new_key_cache_name);
+ errmsg= buf;
+ error= HA_ADMIN_FAILED;
+ }
+ goto err;
+ }
+
+ reassign_key_cache(key_cache_asmt, new_key_cache);
+
+ VOID(pthread_mutex_unlock(&LOCK_assign));
+ error= mi_assign_to_keycache(file, map, new_key_cache, &LOCK_assign);
+ VOID(pthread_mutex_lock(&LOCK_assign));
+
+ if (error && !key_cache_asmt->triggered)
+ {
+ switch (error) {
+ default:
+ char buf[ERRMSGSIZE+20];
+ my_snprintf(buf, ERRMSGSIZE,
+ "Failed to flush to index file (errno: %d)", my_errno);
+ errmsg= buf;
+ }
+ error= HA_ADMIN_CORRUPT;
+ goto err;
+ }
+
+ goto ok;
+
+ err:
+ if (!triggered)
+ {
+ MI_CHECK param;
+ myisamchk_init(&param);
+ param.thd= thd;
+ param.op_name= (char*)"assign_to_keycache";
+ param.db_name= table->table_cache_key;
+ param.table_name= table->table_name;
+ param.testflag= 0;
+ mi_check_print_error(&param, errmsg);
+ }
+
+ ok:
+ if (--key_cache_asmt->requests)
+ {
+ /* There is a queue of assignments for the table */
+
+ /* Remove the first member from the queue */
+ struct st_my_thread_var *last= key_cache_asmt->queue;
+ struct st_my_thread_var *thread= last->next;
+ if (thread->next == thread)
+ key_cache_asmt->queue= 0;
+ else
+ {
+ last->next= thread->next;
+ last->next->prev= &last->next;
+ thread->next= 0;
+ }
+ /* Signal the first waiting thread to proceed */
+ VOID(pthread_cond_signal(&thread->suspend));
+ }
+
+ key_cache_asmt->triggered= 0;
+
+ VOID(pthread_mutex_unlock(&LOCK_assign));
+
+ DBUG_RETURN(error);
+}
+
+
+/*
Preload pages of the index file for a table into the key cache.
*/