summaryrefslogtreecommitdiff
path: root/sql/sql_table.cc
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2003-11-18 13:47:27 +0200
committerunknown <monty@mashka.mysql.fi>2003-11-18 13:47:27 +0200
commite72124c4ccad5b390b84562389175dcd7355769c (patch)
tree0a23d90c946c5f05a8c160fc7c6ef3f05505fc79 /sql/sql_table.cc
parent61e682b8adafdfae736327fee4ea0263e1a0bd37 (diff)
downloadmariadb-git-e72124c4ccad5b390b84562389175dcd7355769c.tar.gz
CLIENT_MULTI_QUERIES -> CLIENT_MULTI_STATEMENTS
New multi-key-cache handling. This was needed becasue the old one didn't work reliable with MERGE tables. ALTER TABLE table_name ... CHARACTER SET ... now changes all char/varchar/text columns to the given character set (One must use ALTER TABLE ... DEFAULT CHARACTER SET ... to change the default character set) Fixed that have_compress is detected properly (fixes problems with func_compress.test on platforms without zlib) New syntax for CACHE INDEX ('keys' is optional if no index name is given and one mentions the key cache name only ones) Removed compiler warnings Added mysql_set_server_option() to allow clients like PHP to easaily set/reset the multi-statement flag. BUILD/compile-pentium-valgrind-max: Add test of isam client/mysql.cc: CLIENT_MULTI_QUERIES -> CLIENT_MULTI_STATEMENTS include/my_base.h: Remove HA_EXTRA_SET_KEY_CACHE include/my_no_pthread.h: Add defines to ignore rw-locks when running without threads include/my_sys.h: Added function for multi-key-caches include/myisam.h: Added function to handle multi-key-caches include/mysql.h: Added mysql_set_server_option include/mysql_com.h: CLIENT_MULTI_QUERIES -> CLIENT_MULTI_STATEMENTS Added enum_mysql_set_option include/mysqld_error.h: Added error message for unknown key cache innobase/srv/srv0start.c: Removed warning that is confused for MySQL users libmysql/libmysql.c: Added mysql_set_server_option() libmysql/libmysql.def: Added mysql_set_server_option() myisam/ft_nlq_search.c: Removed compiler warning myisam/ft_static.c: Removed compiler warning and fixed wrong return value myisam/mi_check.c: Clean up multi-key-cache usage myisam/mi_checksum.c: Removed not used variable myisam/mi_close.c: keycache -> key_cache myisam/mi_delete_all.c: keycache -> key_cache myisam/mi_extra.c: keycache -> key_cache Removed HA_EXTRA_SET_KEY_CACHE myisam/mi_keycache.c: Changed logic so that it's MyISAM that is responsible for assign tables to different key caches instead of the upper level myisam/mi_locking.c: Don't change key cache on unlock (must be done before) myisam/mi_open.c: Fetch key cache to use from multi_key_cache_search() myisam/mi_page.c: keycache -> key_cache myisam/mi_panic.c: keycache -> key_cache myisam/mi_preload.c: keycache -> key_cache myisam/mi_test1.c: Use KEY_CACHE_BLOCK_SIZE myisam/mi_test2.c: Always test resize_key_cache() myisam/mi_test3.c: Use KEY_CACHE_BLOCK_SIZE instead of 512 myisam/myisamchk.c: update for multiple key caches myisam/myisamdef.h: Remove reg_keycache Add unique_name_length for storing length of unique_file_name myisam/myisamlog.c: Change how end_key_cache() is called mysql-test/mysql-test-run.sh: Fixed web link Added name of failed test to abort row. mysql-test/r/alter_table.result: Testing of ALTER TABLE ... [DEFAULT] CHARACTER SET mysql-test/r/case.result: Update result for DEFAULT CHARSET... mysql-test/r/cast.result: Update result for DEFAULT CHARSET... mysql-test/r/create.result: Update result for DEFAULT CHARSET... mysql-test/r/ctype_collate.result: Update result for DEFAULT CHARSET... mysql-test/r/ctype_latin1_de.result: Update result for DEFAULT CHARSET... mysql-test/r/ctype_many.result: Update result for DEFAULT CHARSET... mysql-test/r/ctype_mb.result: Update result for DEFAULT CHARSET... mysql-test/r/ctype_recoding.result: Update result for DEFAULT CHARSET... mysql-test/r/ctype_ucs.result: Update result for DEFAULT CHARSET... mysql-test/r/derived.result: Use STRAIGHT_JOIN to make join order predictable mysql-test/r/fulltext.result: Update result for DEFAULT CHARSET... mysql-test/r/func_str.result: Update result for DEFAULT CHARSET... mysql-test/r/func_system.result: Update result for DEFAULT CHARSET... mysql-test/r/gis-rtree.result: Update result for DEFAULT CHARSET... mysql-test/r/innodb.result: Update result for DEFAULT CHARSET... mysql-test/r/key_cache.result: Update test for new key cache syntax. Added more tests mysql-test/r/merge.result: Update result for DEFAULT CHARSET... mysql-test/r/preload.result: New syntax mysql-test/r/show_check.result: Update result for DEFAULT CHARSET... mysql-test/r/sql_mode.result: Update result for DEFAULT CHARSET... mysql-test/r/subselect.result: Update result for DEFAULT CHARSET... mysql-test/r/type_blob.result: Update result for DEFAULT CHARSET... mysql-test/r/type_enum.result: Update result for DEFAULT CHARSET... mysql-test/r/type_nchar.result: Update result for DEFAULT CHARSET... mysql-test/r/type_set.result: Update result for DEFAULT CHARSET... mysql-test/r/union.result: Use STRAIGHT_JOIN to make join order predictable mysql-test/t/alter_table.test: Testing of ALTER TABLE ... [DEFAULT] CHARACTER SET mysql-test/t/ctype_many.test: Update result for DEFAULT CHARSET... mysql-test/t/derived.test: Use STRAIGHT_JOIN to make join order predictable mysql-test/t/isam.test: Use disable warnings for test loop mysql-test/t/join.test: Update test now when we only support 61 tables in join mysql-test/t/key_cache.test: Update test for new key cache syntax. Added more tests mysql-test/t/preload.test: Update for new syntax mysql-test/t/union.test: Use STRAIGHT_JOIN to make join order predictable mysys/Makefile.am: Added mf_keycaches.c mysys/hash.c: TRUE -> 1 mysys/mf_keycache.c: Removed compiler warnings Striped end space Fixed indentation and improved function comments TRUE -> 1 Changed parameters to end_key_cache() to make it easer to use Fixed bug when using key blocks size > 1024 bytes (First part of index file could be overwritten with wrong data) Split function flush_key_blocks into two functions to not get mutex used twice when called from flush_all_key_blocks() mysys/my_bitmap.c: More debugging Safe bitmap_free() Fixed indentation mysys/my_getopt.c: Ensure that we initialize option->value, option->max_value and value from GET_ASK_ADDR mysys/my_thr_init.c: Remove not used mutex THR_LOCK_keycache mysys/typelib.c: Fixed function comments sql-common/client.c: CLIENT_MULTI_QUERIES -> CLIENT_MULTI_STATEMENTS Fixed the multi_result flag is set also on SELECT;s sql/ha_myisam.cc: Fixed multiple key_cache handling (Now done on MyISAM level) sql/ha_myisammrg.cc: Fixed multiple key_cache handling (Now done on MyISAM level) sql/handler.cc: New multi key cache handling sql/handler.h: New multi key cache handling Added support for default character set sql/item.h: Added function cleanup() (Needed for prepared statements / cursors) sql/item_cmpfunc.h: Added cleanup function sql/item_func.cc: Indentation cleanup sql/mysql_priv.h: New multi-key-cache functions Removed LOCK_assign sql/mysqld.cc: New multi-key-cache handling Fixed that variable have_compress is set correctly sql/protocol.cc: SELECT didn't work reliable in multi-statements sql/set_var.cc: Support for new key cache variables sql/set_var.h: Support for new key cache variables sql/share/czech/errmsg.txt: New error messages sql/share/danish/errmsg.txt: New error messages sql/share/dutch/errmsg.txt: New error messages sql/share/english/errmsg.txt: New error messages sql/share/estonian/errmsg.txt: New error messages sql/share/french/errmsg.txt: New error messages sql/share/german/errmsg.txt: New error messages sql/share/greek/errmsg.txt: New error messages sql/share/hungarian/errmsg.txt: New error messages sql/share/italian/errmsg.txt: New error messages sql/share/japanese/errmsg.txt: New error messages sql/share/korean/errmsg.txt: New error messages sql/share/norwegian-ny/errmsg.txt: New error messages sql/share/norwegian/errmsg.txt: New error messages sql/share/polish/errmsg.txt: New error messages sql/share/portuguese/errmsg.txt: New error messages sql/share/romanian/errmsg.txt: New error messages sql/share/russian/errmsg.txt: New error messages sql/share/serbian/errmsg.txt: New error messages sql/share/slovak/errmsg.txt: New error messages sql/share/spanish/errmsg.txt: New error messages sql/share/swedish/errmsg.txt: New error messages sql/share/ukrainian/errmsg.txt: New error messages sql/sql_base.cc: Removed all key_cache handling (this is now done on MyISAM level) Change table_charset -> default_table_charset sql/sql_db.cc: table_charset -> default_table_charset sql/sql_delete.cc: table_charset -> default_table_charset sql/sql_lex.cc: CLIENT_MULTI_QUERIES -> CLIENT_MULTI_STATEMENTS sql/sql_lex.h: New option to store a name and length sql/sql_parse.cc: Support for mysql_set_server_option() Reset "default" keycache status variables in 'FLUSH STATUS' (Need to be improved later) sql/sql_show.cc: Add DEFAULT before CHARSET (for table character sets) Fetch key cache variables from 'sql_key_cache' sql/sql_table.cc: table_charset -> default_table_charset New multi-key-cache handling sql/sql_test.cc: Write information from all key caches sql/sql_yacc.yy: Changed syntax for CACHE INDEX ... Force user to use DEFAULT before database/table level character sets sql/structs.h: Added SHOW_KEY_CACHE_LONG (to get values from sql_key_cache) sql/table.cc: table_charset -> default_table_charset sql/table.h: New key cache handling (this is now done in mysys/mf_keycaches.c) sql/unireg.h: A
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r--sql/sql_table.cc125
1 files changed, 51 insertions, 74 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index d2d1926ea06..0f7fb7029aa 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -422,6 +422,12 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
for (field_no=0; (sql_field=it++) ; field_no++)
{
if (!sql_field->charset)
+ sql_field->charset= create_info->default_table_charset;
+ /*
+ table_charset is set in ALTER TABLE if we want change character set
+ for all varchar/char columns
+ */
+ if (create_info->table_charset)
sql_field->charset= create_info->table_charset;
sql_field->create_length_to_internal_length();
@@ -461,7 +467,9 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
{
/* Field redefined */
sql_field->sql_type= dup_field->sql_type;
- sql_field->charset= dup_field->charset ? dup_field->charset : create_info->table_charset;
+ sql_field->charset= (dup_field->charset ?
+ dup_field->charset :
+ create_info->default_table_charset);
sql_field->length= dup_field->length;
sql_field->pack_length= dup_field->pack_length;
sql_field->create_length_to_internal_length();
@@ -484,8 +492,8 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
it.rewind();
while ((sql_field=it++))
{
- if (!sql_field->charset)
- sql_field->charset = create_info->table_charset;
+ DBUG_ASSERT(sql_field->charset);
+
switch (sql_field->sql_type) {
case FIELD_TYPE_BLOB:
case FIELD_TYPE_MEDIUM_BLOB:
@@ -1625,11 +1633,25 @@ int mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
-1 error
*/
-int mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables)
+int mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables,
+ LEX_STRING *key_cache_name)
{
+ HA_CHECK_OPT check_opt;
+ KEY_CACHE_VAR *key_cache;
DBUG_ENTER("mysql_assign_to_keycache");
- DBUG_RETURN(mysql_admin_table(thd, tables, 0,
- "assign_to_keycache", TL_READ, 0,
+
+ check_opt.init();
+ pthread_mutex_lock(&LOCK_global_system_variables);
+ if (!(key_cache= get_key_cache(key_cache_name)))
+ {
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+ my_error(ER_UNKNOWN_KEY_CACHE, MYF(0), key_cache_name->str);
+ DBUG_RETURN(-1);
+ }
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+ check_opt.key_cache= key_cache;
+ DBUG_RETURN(mysql_admin_table(thd, tables, &check_opt,
+ "assign_to_keycache", TL_READ_NO_INSERT, 0,
HA_OPEN_TO_ASSIGN, 0,
&handler::assign_to_keycache));
}
@@ -1642,78 +1664,34 @@ int mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables)
reassign_keycache_tables()
thd Thread object
src_cache Reference to the key cache to clean up
- dest_name Name of the cache to assign tables to
- remove_fl Flag to destroy key cache when all tables are reassigned
+ dest_cache New key cache
- RETURN VALUES
+ NOTES
+ This is called when one sets a key cache size to zero, in which
+ case we have to move the tables associated to this key cache to
+ the "default" one.
+
+ One has to ensure that one never calls this function while
+ some other thread is changing the key cache. This is assured by
+ the caller setting src_cache->in_init before calling this function.
+
+ We don't delete the old key cache as there may still be pointers pointing
+ to it for a while after this function returns.
+
+ RETURN VALUES
0 ok
- -1 error
*/
-int reassign_keycache_tables(THD* thd, KEY_CACHE_VAR* src_cache,
- char *dest_name, bool remove_fl)
+int reassign_keycache_tables(THD *thd, KEY_CACHE_VAR *src_cache,
+ KEY_CACHE_VAR *dst_cache)
{
- int rc= 0;
- TABLE_LIST table;
- KEY_CACHE_ASMT *key_cache_asmt;
-
DBUG_ENTER("reassign_keycache_tables");
- VOID(pthread_mutex_lock(&LOCK_assign));
- for (key_cache_asmt= src_cache->assign_list ;
- key_cache_asmt;
- key_cache_asmt= key_cache_asmt->next)
- key_cache_asmt->to_reassign = 1;
- key_cache_asmt= src_cache->assign_list;
- while (key_cache_asmt)
- {
- if (key_cache_asmt->to_reassign)
- {
- bool refresh;
- VOID(pthread_mutex_unlock(&LOCK_assign));
- bzero((byte *) &table, sizeof(table));
- table.option= dest_name;
- table.db= key_cache_asmt->db_name;
- table.alias= table.real_name= key_cache_asmt->table_name;
- thd->open_options|= HA_OPEN_TO_ASSIGN;
- while (!(table.table=open_table(thd,table.db,
- table.real_name,table.alias,
- &refresh)) && refresh) ;
- thd->open_options&= ~HA_OPEN_TO_ASSIGN;
- if (!table.table)
- DBUG_RETURN(-1);
- table.table->pos_in_table_list= &table;
- key_cache_asmt->triggered= 1;
- rc= table.table->file->assign_to_keycache(thd, 0);
- close_thread_tables(thd);
- if (rc)
- DBUG_RETURN(rc);
- VOID(pthread_mutex_lock(&LOCK_assign));
- key_cache_asmt= src_cache->assign_list;
- continue;
- }
- else
- key_cache_asmt= key_cache_asmt->next;
- }
-
- while (src_cache->assignments)
- {
- struct st_my_thread_var *waiting_thread= my_thread_var;
- pthread_cond_wait(&waiting_thread->suspend, &LOCK_assign);
- }
- if (src_cache->extra_info)
- {
- my_free((char *) src_cache->extra_info, MYF(0));
- src_cache->extra_info= 0;
- }
-
- if (remove_fl && !src_cache->assign_list && src_cache != &dflt_key_cache_var)
- {
- end_key_cache(&src_cache->cache, 1);
- src_cache->buff_size= 0;
- src_cache->block_size= 0;
- }
- VOID(pthread_mutex_unlock(&LOCK_assign));
+ DBUG_ASSERT(src_cache != dst_cache);
+ DBUG_ASSERT(src_cache->in_init);
+ src_cache->buff_size= 0; // Free key cache
+ ha_resize_key_cache(src_cache);
+ ha_change_key_cache(src_cache, dst_cache);
DBUG_RETURN(0);
}
@@ -1766,7 +1744,6 @@ int mysql_create_like_table(THD* thd, TABLE_LIST* table,
char *src_db= thd->db;
char *src_table= table_ident->table.str;
int err;
-
DBUG_ENTER("mysql_create_like_table");
/*
@@ -2126,8 +2103,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
create_info->max_rows=table->max_rows;
if (!(used_fields & HA_CREATE_USED_AVG_ROW_LENGTH))
create_info->avg_row_length=table->avg_row_length;
- if (!(used_fields & HA_CREATE_USED_CHARSET))
- create_info->table_charset=table->table_charset;
+ if (!(used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
+ create_info->default_table_charset= table->table_charset;
restore_record(table,default_values); // Empty record for DEFAULT
List_iterator<Alter_drop> drop_it(drop_list);