diff options
author | Jon Olav Hauglid <jon.hauglid@sun.com> | 2010-04-20 10:51:50 +0200 |
---|---|---|
committer | Jon Olav Hauglid <jon.hauglid@sun.com> | 2010-04-20 10:51:50 +0200 |
commit | ac7873663866e74fb7572c0b2a5f2548a2897420 (patch) | |
tree | 3c10718d95da445db1e1f9405aa01297659a8739 /sql/sql_table.cc | |
parent | afdf0f030c342e28c5cfd7220e55830b18424de3 (diff) | |
parent | 1a3c03dbb49cfc9ae8246957c5b0ac2a9389d28e (diff) | |
download | mariadb-git-ac7873663866e74fb7572c0b2a5f2548a2897420.tar.gz |
merge from mysql-trunk-bugfixing
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r-- | sql/sql_table.cc | 112 |
1 files changed, 94 insertions, 18 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 5b957cccabd..aaa99e40ba3 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -15,14 +15,40 @@ /* drop and alter of tables */ -#include "mysql_priv.h" +#include "sql_priv.h" +#include "unireg.h" #include "debug_sync.h" +#include "sql_table.h" +#include "sql_rename.h" // do_rename +#include "sql_parse.h" // test_if_data_home_dir +#include "sql_cache.h" // query_cache_* +#include "sql_base.h" // open_temporary_table +#include "lock.h" // wait_if_global_read_lock, lock_table_names, + // start_waiting_global_read_lock, + // unlock_table_names, mysql_unlock_tables +#include "strfunc.h" // find_type2, find_set +#include "sql_view.h" // mysql_frm_type, view_checksum, mysql_frm_type +#include "sql_delete.h" // mysql_truncate +#include "sql_partition.h" // mem_alloc_error, + // generate_partition_syntax, + // partition_info +#include "sql_db.h" // load_db_opt_by_name, lock_db_cache, creating_database +#include "sql_time.h" // make_truncated_value_warning +#include "records.h" // init_read_record, end_read_record +#include "filesort.h" // filesort_free_buffers +#include "sql_select.h" // setup_order, + // make_unireg_sortorder +#include "sql_handler.h" // mysql_ha_rm_tables +#include "discover.h" // readfrm +#include "my_pthread.h" // pthread_mutex_t +#include "log_event.h" // Query_log_event #include <hash.h> #include <myisam.h> #include <my_dir.h> #include "sp_head.h" #include "sp.h" #include "sql_trigger.h" +#include "sql_parse.h" #include "sql_show.h" #include "transaction.h" #include "keycaches.h" @@ -5496,6 +5522,45 @@ err: DBUG_RETURN(-1); } +/** + @brief Check if both DROP and CREATE are present for an index in ALTER TABLE + + @details Checks if any index is being modified (present as both DROP INDEX + and ADD INDEX) in the current ALTER TABLE statement. Needed for disabling + online ALTER TABLE. + + @param table The table being altered + @param alter_info The ALTER TABLE structure + @return presence of index being altered + @retval FALSE No such index + @retval TRUE Have at least 1 index modified +*/ + +static bool +is_index_maintenance_unique (TABLE *table, Alter_info *alter_info) +{ + List_iterator<Key> key_it(alter_info->key_list); + List_iterator<Alter_drop> drop_it(alter_info->drop_list); + Key *key; + + while ((key= key_it++)) + { + if (key->name.str) + { + Alter_drop *drop; + + drop_it.rewind(); + while ((drop= drop_it++)) + { + if (drop->type == Alter_drop::KEY && + !my_strcasecmp(system_charset_info, key->name.str, drop->name)) + return TRUE; + } + } + } + return FALSE; +} + /* SYNOPSIS @@ -5584,6 +5649,7 @@ compare_tables(TABLE *table, */ Alter_info tmp_alter_info(*alter_info, thd->mem_root); uint db_options= 0; /* not used */ + /* Create the prepared information. */ if (mysql_prepare_create_table(thd, create_info, &tmp_alter_info, @@ -6864,10 +6930,14 @@ view_err: */ new_db_type= create_info->db_type; + if (is_index_maintenance_unique (table, alter_info)) + need_copy_table= ALTER_TABLE_DATA_CHANGED; + if (mysql_prepare_alter_table(thd, table, create_info, alter_info)) goto err; - - need_copy_table= alter_info->change_level; + + if (need_copy_table == ALTER_TABLE_METADATA_ONLY) + need_copy_table= alter_info->change_level; set_table_default_charset(thd, create_info, db); @@ -7956,22 +8026,28 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, for (uint i= 0; i < t->s->fields; i++ ) { Field *f= t->field[i]; - enum_field_types field_type= f->type(); - /* - BLOB and VARCHAR have pointers in their field, we must convert - to string; GEOMETRY is implemented on top of BLOB. - */ - if ((field_type == MYSQL_TYPE_BLOB) || - (field_type == MYSQL_TYPE_VARCHAR) || - (field_type == MYSQL_TYPE_GEOMETRY)) - { - String tmp; - f->val_str(&tmp); - row_crc= my_checksum(row_crc, (uchar*) tmp.ptr(), tmp.length()); + + /* + BLOB and VARCHAR have pointers in their field, we must convert + to string; GEOMETRY is implemented on top of BLOB. + BIT may store its data among NULL bits, convert as well. + */ + switch (f->type()) { + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_VARCHAR: + case MYSQL_TYPE_GEOMETRY: + case MYSQL_TYPE_BIT: + { + String tmp; + f->val_str(&tmp); + row_crc= my_checksum(row_crc, (uchar*) tmp.ptr(), + tmp.length()); + break; + } + default: + row_crc= my_checksum(row_crc, f->ptr, f->pack_length()); + break; } - else - row_crc= my_checksum(row_crc, f->ptr, - f->pack_length()); } crc+= row_crc; |