diff options
author | Alexey Kopytov <Alexey.Kopytov@Sun.com> | 2010-02-22 00:33:11 +0300 |
---|---|---|
committer | Alexey Kopytov <Alexey.Kopytov@Sun.com> | 2010-02-22 00:33:11 +0300 |
commit | 0afa209018fad0a0863048cebfcc8f0a52b814ee (patch) | |
tree | 94830ebea81e944773f55fcb501055d762e3db1d /sql | |
parent | 4b85061e09ae3ec67948f9814700f69934138e99 (diff) | |
parent | 20dfd709d6454f8cdc25262c945ad203cecafc02 (diff) | |
download | mariadb-git-0afa209018fad0a0863048cebfcc8f0a52b814ee.tar.gz |
Manual merge of mysql-5.1-bugteam to mysql-trunk-merge.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 11 | ||||
-rw-r--r-- | sql/ha_partition.cc | 33 | ||||
-rw-r--r-- | sql/item.cc | 5 | ||||
-rw-r--r-- | sql/item_row.cc | 7 | ||||
-rw-r--r-- | sql/mysql_priv.h | 12 | ||||
-rw-r--r-- | sql/opt_range.cc | 15 | ||||
-rw-r--r-- | sql/opt_sum.cc | 17 | ||||
-rw-r--r-- | sql/share/errmsg-utf8.txt | 2 | ||||
-rw-r--r-- | sql/share/errmsg.txt | 2 | ||||
-rw-r--r-- | sql/sp_cache.cc | 5 | ||||
-rw-r--r-- | sql/sp_head.cc | 3 | ||||
-rw-r--r-- | sql/sql_base.cc | 14 | ||||
-rw-r--r-- | sql/sql_class.cc | 10 | ||||
-rw-r--r-- | sql/sql_class.h | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 134 | ||||
-rw-r--r-- | sql/sql_select.h | 19 | ||||
-rw-r--r-- | sql/sql_table.cc | 44 | ||||
-rw-r--r-- | sql/sql_trigger.cc | 15 | ||||
-rw-r--r-- | sql/sql_update.cc | 97 | ||||
-rw-r--r-- | sql/sql_view.cc | 13 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 2 | ||||
-rw-r--r-- | sql/table.cc | 5 | ||||
-rw-r--r-- | sql/table.h | 14 |
23 files changed, 290 insertions, 191 deletions
diff --git a/sql/field.cc b/sql/field.cc index 64ad2dc180e..5fe031a38b9 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1738,11 +1738,10 @@ uint Field::fill_cache_field(CACHE_FIELD *copy) uint store_length; copy->str=ptr; copy->length=pack_length(); - copy->blob_field=0; + copy->field= this; if (flags & BLOB_FLAG) { - copy->blob_field=(Field_blob*) this; - copy->strip=0; + copy->type= CACHE_BLOB; copy->length-= table->s->blob_ptr_size; return copy->length; } @@ -1750,15 +1749,15 @@ uint Field::fill_cache_field(CACHE_FIELD *copy) (type() == MYSQL_TYPE_STRING && copy->length >= 4 && copy->length < 256)) { - copy->strip=1; /* Remove end space */ + copy->type= CACHE_STRIPPED; store_length= 2; } else { - copy->strip=0; + copy->type= 0; store_length= 0; } - return copy->length+ store_length; + return copy->length + store_length; } diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 04b7e9d7523..b287128471a 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -1803,13 +1803,23 @@ void ha_partition::update_create_info(HA_CREATE_INFO *create_info) void ha_partition::change_table_ptr(TABLE *table_arg, TABLE_SHARE *share) { - handler **file_array= m_file; + handler **file_array; table= table_arg; table_share= share; - do + /* + m_file can be NULL when using an old cached table in DROP TABLE, when the + table just has REMOVED PARTITIONING, see Bug#42438 + */ + if (m_file) { - (*file_array)->change_table_ptr(table_arg, share); - } while (*(++file_array)); + file_array= m_file; + DBUG_ASSERT(*file_array); + do + { + (*file_array)->change_table_ptr(table_arg, share); + } while (*(++file_array)); + } + if (m_added_file && m_added_file[0]) { /* if in middle of a drop/rename etc */ @@ -6207,7 +6217,13 @@ void ha_partition::print_error(int error, myf errflag) thd->lex->sql_command != SQLCOM_TRUNCATE) m_part_info->print_no_partition_found(table); else - m_file[m_last_part]->print_error(error, errflag); + { + /* In case m_file has not been initialized, like in bug#42438 */ + if (m_file) + m_file[m_last_part]->print_error(error, errflag); + else + handler::print_error(error, errflag); + } DBUG_VOID_RETURN; } @@ -6217,7 +6233,12 @@ bool ha_partition::get_error_message(int error, String *buf) DBUG_ENTER("ha_partition::get_error_message"); /* Should probably look for my own errors first */ - DBUG_RETURN(m_file[m_last_part]->get_error_message(error, buf)); + + /* In case m_file has not been initialized, like in bug#42438 */ + if (m_file) + DBUG_RETURN(m_file[m_last_part]->get_error_message(error, buf)); + DBUG_RETURN(handler::get_error_message(error, buf)); + } diff --git a/sql/item.cc b/sql/item.cc index 4b6b77860d6..a30c1dafac8 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -5321,7 +5321,7 @@ int Item::save_in_field(Field *field, bool no_conversions) field->set_notnull(); error=field->store(nr, unsigned_flag); } - return error ? error : (field->table->in_use->is_error() ? 2 : 0); + return error ? error : (field->table->in_use->is_error() ? 1 : 0); } @@ -6652,7 +6652,8 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions) { if (!arg) { - if (field_arg->flags & NO_DEFAULT_VALUE_FLAG) + if (field_arg->flags & NO_DEFAULT_VALUE_FLAG && + field_arg->real_type() != MYSQL_TYPE_ENUM) { if (field_arg->reset()) { diff --git a/sql/item_row.cc b/sql/item_row.cc index 28de03bf049..29b37eb2bc0 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -71,7 +71,12 @@ bool Item_row::fix_fields(THD *thd, Item **ref) Item *item= *arg; used_tables_cache |= item->used_tables(); const_item_cache&= item->const_item() && !with_null; - if (const_item_cache) + /* + Some subqueries transformations aren't done in the view_prepare_mode thus + is_null() will fail. So we skip is_null() calculation for CREATE VIEW as + not necessary. + */ + if (const_item_cache && !thd->lex->view_prepare_mode) { if (item->cols() > 1) with_null|= item->null_inside(); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 1fca19bdb6b..e06147b8780 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -128,13 +128,15 @@ char* query_table_status(THD *thd,const char *db,const char *table_name); #define WARN_DEPRECATED(Thd,Ver,Old,New) \ do { \ DBUG_ASSERT(strncmp(Ver, MYSQL_SERVER_VERSION, sizeof(Ver)-1) > 0); \ - if (((uchar*)Thd) != NULL) \ + if (((uchar*)Thd) != NULL) \ push_warning_printf(((THD *)Thd), MYSQL_ERROR::WARN_LEVEL_WARN, \ - ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX_WITH_VER), \ - (Old), (Ver), (New)); \ + ER_WARN_DEPRECATED_SYNTAX, \ + ER(ER_WARN_DEPRECATED_SYNTAX), \ + (Old), (New)); \ else \ - sql_print_warning("The syntax '%s' is deprecated and will be removed " \ - "in a future release. Please use %s instead.", (Old), (New)); \ + sql_print_warning("'%s' is deprecated and will be removed " \ + "in a future release. Please use '%s' instead.", \ + (Old), (New)); \ } while(0) extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index ac5b1f575de..b27a9e1e74d 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1198,11 +1198,7 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT() if (file) { range_end(); - if (head->key_read) - { - head->key_read= 0; - file->extra(HA_EXTRA_NO_KEYREAD); - } + head->set_keyread(FALSE); if (free_file) { DBUG_PRINT("info", ("Freeing separate handler 0x%lx (free: %d)", (long) file, @@ -1404,10 +1400,7 @@ end: head->file= file; /* We don't have to set 'head->keyread' here as the 'file' is unique */ if (!head->no_keyread) - { - head->key_read= 1; head->mark_columns_used_by_index(index); - } head->prepare_for_position(); head->file= org_file; bitmap_copy(&column_bitmap, head->read_set); @@ -8350,7 +8343,7 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_and_merge() DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::read_keys_and_merge"); /* We're going to just read rowids. */ - file->extra(HA_EXTRA_KEYREAD); + head->set_keyread(TRUE); head->prepare_for_position(); cur_quick_it.rewind(); @@ -8426,7 +8419,7 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_and_merge() delete unique; doing_pk_scan= FALSE; /* index_merge currently doesn't support "using index" at all */ - file->extra(HA_EXTRA_NO_KEYREAD); + head->set_keyread(FALSE); init_read_record(&read_record, thd, head, (SQL_SELECT*) 0, 1 , 1, TRUE); DBUG_RETURN(result); } @@ -10844,7 +10837,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::reset(void) int result; DBUG_ENTER("QUICK_GROUP_MIN_MAX_SELECT::reset"); - file->extra(HA_EXTRA_KEYREAD); /* We need only the key attributes */ + head->set_keyread(TRUE); /* We need only the key attributes */ if ((result= file->ha_index_init(index,1))) DBUG_RETURN(result); if (quick_prefix_select && quick_prefix_select->reset()) diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 13b10ac2e8f..1bd137836e8 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -326,11 +326,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) if (!error && reckey_in_range(0, &ref, item_field->field, conds, range_fl, prefix_len)) error= HA_ERR_KEY_NOT_FOUND; - if (table->key_read) - { - table->key_read= 0; - table->file->extra(HA_EXTRA_NO_KEYREAD); - } + table->set_keyread(FALSE); table->file->ha_index_end(); if (error) { @@ -416,11 +412,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) if (!error && reckey_in_range(1, &ref, item_field->field, conds, range_fl, prefix_len)) error= HA_ERR_KEY_NOT_FOUND; - if (table->key_read) - { - table->key_read=0; - table->file->extra(HA_EXTRA_NO_KEYREAD); - } + table->set_keyread(FALSE); table->file->ha_index_end(); if (error) { @@ -882,10 +874,7 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, converted (for example to upper case) */ if (field->part_of_key.is_set(idx)) - { - table->key_read= 1; - table->file->extra(HA_EXTRA_KEYREAD); - } + table->set_keyread(TRUE); return 1; } } diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index db99890235a..2ac4e13af9f 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -5021,7 +5021,7 @@ ER_UNKNOWN_STORAGE_ENGINE 42000 # When using this error code, use ER(ER_WARN_DEPRECATED_SYNTAX_WITH_VER) # for the message string. See, for example, code in mysql_priv.h. ER_WARN_DEPRECATED_SYNTAX - eng "'%s' is deprecated; use '%s' instead" + eng "'%s' is deprecated and will be removed in a future release. Please use %s instead" ger "'%s' ist veraltet. Bitte benutzen Sie '%s'" por "'%s' é desatualizado. Use '%s' em seu lugar" spa "'%s' está desaprobado, use '%s' en su lugar" diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index b5f227e5550..9dba279d579 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5021,7 +5021,7 @@ ER_UNKNOWN_STORAGE_ENGINE 42000 # When using this error code, use ER(ER_WARN_DEPRECATED_SYNTAX_WITH_VER) # for the message string. See, for example, code in mysql_priv.h. ER_WARN_DEPRECATED_SYNTAX - eng "'%s' is deprecated; use '%s' instead" + eng "'%s' is deprecated and will be removed in a future release. Please use %s instead" ger "'%s' ist veraltet. Bitte benutzen Sie '%s'" por "'%s' é desatualizado. Use '%s' em seu lugar" spa "'%s' está desaprobado, use '%s' en su lugar" diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc index 0da5e44b846..046ff931253 100644 --- a/sql/sp_cache.cc +++ b/sql/sp_cache.cc @@ -176,8 +176,9 @@ sp_head *sp_cache_lookup(sp_cache **cp, sp_name *name) sp_cache_invalidate() NOTE - This is called when a VIEW definition is modifed. We can't destroy sp_head - objects here as one may modify VIEW definitions from prelocking-free SPs. + This is called when a VIEW definition is created or modified (and in some + other contexts). We can't destroy sp_head objects here as one may modify + VIEW definitions from prelocking-free SPs. */ void sp_cache_invalidate() diff --git a/sql/sp_head.cc b/sql/sp_head.cc index efe87110194..f3ac5bfcf97 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1865,6 +1865,8 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) { bool err_status= FALSE; uint params = m_pcont->context_var_count(); + /* Query start time may be reset in a multi-stmt SP; keep this for later. */ + ulonglong utime_before_sp_exec= thd->utime_after_lock; sp_rcontext *save_spcont, *octx; sp_rcontext *nctx = NULL; bool save_enable_slow_log= false; @@ -2071,6 +2073,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) delete nctx; thd->spcont= save_spcont; + thd->utime_after_lock= utime_before_sp_exec; DBUG_RETURN(err_status); } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index e2efb91c1a9..452f13244fd 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2177,6 +2177,7 @@ void wait_for_condition(THD *thd, pthread_mutex_t *mutex, pthread_cond_t *cond) proc_info=thd->proc_info; thd_proc_info(thd, "Waiting for table"); DBUG_ENTER("wait_for_condition"); + DEBUG_SYNC(thd, "waiting_for_table"); if (!thd->killed) (void) pthread_cond_wait(cond, mutex); @@ -4598,7 +4599,20 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags) safe_to_ignore_table= prelock_handler.safely_trapped_errors(); } else + { tables->table= open_table(thd, tables, &new_frm_mem, &refresh, flags); + + /* + Skip further processing if there has been a fatal error while + trying to open a table. For example, this might happen due to + stack shortage, unknown definer in views, etc. + */ + if (!tables->table && thd->is_error()) + { + result= -1; + goto err; + } + } } else DBUG_PRINT("tcache", ("referenced table: '%s'.'%s' 0x%lx", diff --git a/sql/sql_class.cc b/sql/sql_class.cc index d37058d2167..4c604d0b5f7 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -608,10 +608,10 @@ bool THD::handle_condition(uint sql_errno, for (Internal_error_handler *error_handler= m_internal_handler; error_handler; - error_handler= m_internal_handler->m_prev_internal_handler) + error_handler= error_handler->m_prev_internal_handler) { - if (error_handler-> handle_condition(this, sql_errno, sqlstate, level, msg, - cond_hdl)) + if (error_handler->handle_condition(this, sql_errno, sqlstate, level, msg, + cond_hdl)) { return TRUE; } @@ -621,10 +621,12 @@ bool THD::handle_condition(uint sql_errno, } -void THD::pop_internal_handler() +Internal_error_handler *THD::pop_internal_handler() { DBUG_ASSERT(m_internal_handler != NULL); + Internal_error_handler *popped_handler= m_internal_handler; m_internal_handler= m_internal_handler->m_prev_internal_handler; + return popped_handler; } diff --git a/sql/sql_class.h b/sql/sql_class.h index ab86ac6df12..262332c7b17 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2229,7 +2229,7 @@ public: /** Remove the error handler last pushed. */ - void pop_internal_handler(); + Internal_error_handler *pop_internal_handler(); /** Raise an exception condition. diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 83da76bc7dc..91e81d3d389 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6747,10 +6747,7 @@ make_join_readinfo(JOIN *join, ulonglong options) case JT_CONST: // Only happens with left join if (table->covering_keys.is_set(tab->ref.key) && !table->no_keyread) - { - table->key_read=1; - table->file->extra(HA_EXTRA_KEYREAD); - } + table->set_keyread(TRUE); break; case JT_ALL: /* @@ -6811,10 +6808,7 @@ make_join_readinfo(JOIN *join, ulonglong options) if (tab->select && tab->select->quick && tab->select->quick->index != MAX_KEY && //not index_merge table->covering_keys.is_set(tab->select->quick->index)) - { - table->key_read=1; - table->file->extra(HA_EXTRA_KEYREAD); - } + table->set_keyread(TRUE); else if (!table->covering_keys.is_clear_all() && !(tab->select && tab->select->quick)) { // Only read index tree @@ -6898,11 +6892,7 @@ void JOIN_TAB::cleanup() limit= 0; if (table) { - if (table->key_read) - { - table->key_read= 0; - table->file->extra(HA_EXTRA_NO_KEYREAD); - } + table->set_keyread(FALSE); table->file->ha_index_or_rnd_end(); /* We need to reset this for next select @@ -9939,7 +9929,11 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, KEY_PART_INFO *key_part_info; Item **copy_func; MI_COLUMNDEF *recinfo; - uint total_uneven_bit_length= 0; + /* + total_uneven_bit_length is uneven bit length for visible fields + hidden_uneven_bit_length is uneven bit length for hidden fields + */ + uint total_uneven_bit_length= 0, hidden_uneven_bit_length= 0; bool force_copy_fields= param->force_copy_fields; /* Treat sum functions as normal ones when loose index scan is used. */ save_sum_fields|= param->precomputed_group_by; @@ -10218,6 +10212,14 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, */ param->hidden_field_count= fieldnr; null_count= 0; + /* + On last hidden field we store uneven bit length in + hidden_uneven_bit_length and proceed calculation of + uneven bits for visible fields into + total_uneven_bit_length variable. + */ + hidden_uneven_bit_length= total_uneven_bit_length; + total_uneven_bit_length= 0; } } DBUG_ASSERT(fieldnr == (uint) (reg_field - table->field)); @@ -10263,7 +10265,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, else null_count++; } - hidden_null_pack_length=(hidden_null_count+7)/8; + hidden_null_pack_length= (hidden_null_count + 7 + + hidden_uneven_bit_length) / 8; null_pack_length= (hidden_null_pack_length + (null_count + total_uneven_bit_length + 7) / 8); reclength+=null_pack_length; @@ -11780,16 +11783,11 @@ join_read_const_table(JOIN_TAB *tab, POSITION *pos) !table->no_keyread && (int) table->reginfo.lock_type <= (int) TL_READ_HIGH_PRIORITY) { - table->key_read=1; - table->file->extra(HA_EXTRA_KEYREAD); + table->set_keyread(TRUE); tab->index= tab->ref.key; } error=join_read_const(tab); - if (table->key_read) - { - table->key_read=0; - table->file->extra(HA_EXTRA_NO_KEYREAD); - } + table->set_keyread(FALSE); if (error) { tab->info="unique row not found"; @@ -12142,12 +12140,8 @@ join_read_first(JOIN_TAB *tab) { int error; TABLE *table=tab->table; - if (!table->key_read && table->covering_keys.is_set(tab->index) && - !table->no_keyread) - { - table->key_read=1; - table->file->extra(HA_EXTRA_KEYREAD); - } + if (table->covering_keys.is_set(tab->index) && !table->no_keyread) + table->set_keyread(TRUE); tab->table->status=0; tab->read_record.read_record=join_read_next; tab->read_record.table=table; @@ -12181,12 +12175,8 @@ join_read_last(JOIN_TAB *tab) { TABLE *table=tab->table; int error; - if (!table->key_read && table->covering_keys.is_set(tab->index) && - !table->no_keyread) - { - table->key_read=1; - table->file->extra(HA_EXTRA_KEYREAD); - } + if (table->covering_keys.is_set(tab->index) && !table->no_keyread) + table->set_keyread(TRUE); tab->table->status=0; tab->read_record.read_record=join_read_prev; tab->read_record.table=table; @@ -13604,11 +13594,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, If ref_key used index tree reading only ('Using index' in EXPLAIN), and best_key doesn't, then revert the decision. */ - if (!table->covering_keys.is_set(best_key) && table->key_read) - { - table->key_read= 0; - table->file->extra(HA_EXTRA_NO_KEYREAD); - } + if (!table->covering_keys.is_set(best_key)) + table->set_keyread(FALSE); if (!quick_created) { tab->index= best_key; @@ -13621,10 +13608,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, select->quick= 0; } if (table->covering_keys.is_set(best_key)) - { - table->key_read=1; - table->file->extra(HA_EXTRA_KEYREAD); - } + table->set_keyread(TRUE); table->file->ha_index_or_rnd_end(); if (join->select_options & SELECT_DESCRIBE) { @@ -13798,11 +13782,8 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order, We can only use 'Only index' if quick key is same as ref_key and in index_merge 'Only index' cannot be used */ - if (table->key_read && ((uint) tab->ref.key != select->quick->index)) - { - table->key_read=0; - table->file->extra(HA_EXTRA_NO_KEYREAD); - } + if (((uint) tab->ref.key != select->quick->index)) + table->set_keyread(FALSE); } else { @@ -13858,11 +13839,7 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order, tab->type=JT_ALL; // Read with normal read_record tab->read_first_record= join_init_read_record; tab->join->examined_rows+=examined_rows; - if (table->key_read) // Restore if we used indexes - { - table->key_read=0; - table->file->extra(HA_EXTRA_NO_KEYREAD); - } + table->set_keyread(FALSE); // Restore if we used indexes DBUG_RETURN(table->sort.found_records == HA_POS_ERROR); err: DBUG_RETURN(-1); @@ -14299,7 +14276,7 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count) { used_fields--; length+=field->fill_cache_field(copy); - if (copy->blob_field) + if (copy->type == CACHE_BLOB) (*blob_ptr++)=copy; if (field->real_maybe_null()) null_fields++; @@ -14314,8 +14291,8 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count) { /* must copy null bits */ copy->str= tables[i].table->null_flags; copy->length= tables[i].table->s->null_bytes; - copy->strip=0; - copy->blob_field=0; + copy->type=0; + copy->field=0; length+=copy->length; copy++; cache->fields++; @@ -14325,8 +14302,8 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count) { copy->str= (uchar*) &tables[i].table->null_row; copy->length=sizeof(tables[i].table->null_row); - copy->strip=0; - copy->blob_field=0; + copy->type=0; + copy->field=0; length+=copy->length; copy++; cache->fields++; @@ -14351,9 +14328,10 @@ used_blob_length(CACHE_FIELD **ptr) uint length,blob_length; for (length=0 ; *ptr ; ptr++) { - (*ptr)->blob_length=blob_length=(*ptr)->blob_field->get_length(); + Field_blob *field_blob= (Field_blob *) (*ptr)->field; + (*ptr)->blob_length=blob_length= field_blob->get_length(); length+=blob_length; - (*ptr)->blob_field->get_ptr(&(*ptr)->str); + field_blob->get_ptr(&(*ptr)->str); } return length; } @@ -14382,30 +14360,35 @@ store_record_in_cache(JOIN_CACHE *cache) cache->records++; for (copy=cache->field ; copy < end_field; copy++) { - if (copy->blob_field) + if (copy->type == CACHE_BLOB) { + Field_blob *blob_field= (Field_blob *) copy->field; if (last_record) { - copy->blob_field->get_image(pos, copy->length+sizeof(char*), - copy->blob_field->charset()); + blob_field->get_image(pos, copy->length+sizeof(char*), + blob_field->charset()); pos+=copy->length+sizeof(char*); } else { - copy->blob_field->get_image(pos, copy->length, // blob length - copy->blob_field->charset()); + blob_field->get_image(pos, copy->length, // blob length + blob_field->charset()); memcpy(pos+copy->length,copy->str,copy->blob_length); // Blob data pos+=copy->length+copy->blob_length; } } else { - if (copy->strip) + if (copy->type == CACHE_STRIPPED) { uchar *str,*end; - for (str=copy->str,end= str+copy->length; - end > str && end[-1] == ' ' ; - end--) ; + Field *field= copy->field; + if (field && field->maybe_null() && field->is_null()) + end= str= copy->str; + else + for (str=copy->str,end= str+copy->length; + end > str && end[-1] == ' ' ; + end--) ; length=(uint) (end-str); memcpy(pos+2, str, length); int2store(pos, length); @@ -14454,23 +14437,24 @@ read_cached_record(JOIN_TAB *tab) copy < end_field; copy++) { - if (copy->blob_field) + if (copy->type == CACHE_BLOB) { + Field_blob *blob_field= (Field_blob *) copy->field; if (last_record) { - copy->blob_field->set_image(pos, copy->length+sizeof(char*), - copy->blob_field->charset()); + blob_field->set_image(pos, copy->length+sizeof(char*), + blob_field->charset()); pos+=copy->length+sizeof(char*); } else { - copy->blob_field->set_ptr(pos, pos+copy->length); - pos+=copy->length+copy->blob_field->get_length(); + blob_field->set_ptr(pos, pos+copy->length); + pos+=copy->length + blob_field->get_length(); } } else { - if (copy->strip) + if (copy->type == CACHE_STRIPPED) { length= uint2korr(pos); memcpy(copy->str, pos+2, length); diff --git a/sql/sql_select.h b/sql/sql_select.h index 79758f08a69..df46af47b2c 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -98,6 +98,10 @@ typedef struct st_table_ref } TABLE_REF; + +#define CACHE_BLOB 1 /* blob field */ +#define CACHE_STRIPPED 2 /* field stripped of trailing spaces */ + /** CACHE_FIELD and JOIN_CACHE is used on full join to cache records in outer table @@ -106,8 +110,8 @@ typedef struct st_table_ref typedef struct st_cache_field { uchar *str; uint length, blob_length; - Field_blob *blob_field; - bool strip; + Field *field; + uint type; /**< category of the of the copied field (CACHE_BLOB et al.) */ } CACHE_FIELD; @@ -741,10 +745,11 @@ public: we need to check for errors executing it and react accordingly */ if (!res && table->in_use->is_error()) - res= 2; + res= 1; /* STORE_KEY_FATAL */ dbug_tmp_restore_column_map(table->write_set, old_map); null_key= to_field->is_null() || item->null_value; - return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res); + return ((err != 0 || res < 0 || res > 2) ? STORE_KEY_FATAL : + (store_key_result) res); } }; @@ -773,17 +778,17 @@ protected: if ((res= item->save_in_field(to_field, 1))) { if (!err) - err= res; + err= res < 0 ? 1 : res; /* 1=STORE_KEY_FATAL */ } /* Item::save_in_field() may call Item::val_xxx(). And if this is a subquery we need to check for errors executing it and react accordingly */ if (!err && to_field->table->in_use->is_error()) - err= 2; + err= 1; /* STORE_KEY_FATAL */ } null_key= to_field->is_null() || item->null_value; - return (err > 2 ? STORE_KEY_FATAL : (store_key_result) err); + return (err > 2 ? STORE_KEY_FATAL : (store_key_result) err); } }; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index b17edbdd234..fd6809a8f76 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -22,6 +22,7 @@ #include "sp_head.h" #include "sql_trigger.h" #include "sql_show.h" +#include "debug_sync.h" #ifdef __WIN__ #include <io.h> @@ -1893,22 +1894,10 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, pthread_mutex_lock(&LOCK_open); - /* - If we have the table in the definition cache, we don't have to check the - .frm file to find if the table is a normal table (not view) and what - engine to use. - */ - + /* Disable drop of enabled log tables, must be done before name locking */ for (table= tables; table; table= table->next_local) { - TABLE_SHARE *share; - table->db_type= NULL; - if ((share= get_cached_table_share(table->db, table->table_name))) - table->db_type= share->db_type(); - - /* Disable drop of enabled log tables */ - if (share && (share->table_category == TABLE_CATEGORY_PERFORMANCE) && - check_if_log_table(table->db_length, table->db, + if (check_if_log_table(table->db_length, table->db, table->table_name_length, table->table_name, 1)) { my_error(ER_BAD_LOG_STATEMENT, MYF(0), "DROP"); @@ -1927,7 +1916,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, { char *db=table->db; handlerton *table_type; - enum legacy_db_type frm_db_type; + enum legacy_db_type frm_db_type= DB_TYPE_UNKNOWN; DBUG_PRINT("table", ("table_l: '%s'.'%s' table: 0x%lx s: 0x%lx", table->db, table->table_name, (long) table->table, @@ -1992,7 +1981,6 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, built_query.append("`,"); } - table_type= table->db_type; if (!drop_temporary) { TABLE *locked_table; @@ -2019,9 +2007,9 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, table->internal_tmp_table ? FN_IS_TMP : 0); } + DEBUG_SYNC(thd, "rm_table_part2_before_delete_table"); if (drop_temporary || - ((table_type == NULL && - access(path, F_OK) && + ((access(path, F_OK) && ha_create_table_from_engine(thd, db, alias)) || (!drop_view && mysql_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE))) @@ -2037,15 +2025,25 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, else { char *end; - if (table_type == NULL) + /* + Cannot use the db_type from the table, since that might have changed + while waiting for the exclusive name lock. We are under LOCK_open, + so reading from the frm-file is safe. + */ + if (frm_db_type == DB_TYPE_UNKNOWN) { - mysql_frm_type(thd, path, &frm_db_type); - table_type= ha_resolve_by_legacy_type(thd, frm_db_type); + mysql_frm_type(thd, path, &frm_db_type); + DBUG_PRINT("info", ("frm_db_type %d from %s", frm_db_type, path)); } + table_type= ha_resolve_by_legacy_type(thd, frm_db_type); // Remove extension for delete *(end= path + path_length - reg_ext_length)= '\0'; + DBUG_PRINT("info", ("deleting table of type %d", + (table_type ? table_type->db_type : 0))); error= ha_delete_table(thd, table_type, path, db, table->table_name, !dont_log_query); + + /* No error if non existent table and 'IF EXIST' clause or view */ if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) && (if_exists || table_type == NULL)) { @@ -2091,6 +2089,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, on the table name. */ pthread_mutex_unlock(&LOCK_open); + DEBUG_SYNC(thd, "rm_table_part2_before_binlog"); thd->thread_specific_used|= tmp_table_deleted; error= 0; if (wrong_tables.length()) @@ -7167,6 +7166,7 @@ view_err: else create_info->data_file_name=create_info->index_file_name=0; + DEBUG_SYNC(thd, "alter_table_before_create_table_no_lock"); /* Create a table with a temporary name. With create_info->frm_only == 1 this creates a .frm file only. @@ -7367,6 +7367,7 @@ view_err: intern_close_table(new_table); my_free(new_table,MYF(0)); } + DEBUG_SYNC(thd, "alter_table_before_rename_result_table"); VOID(pthread_mutex_lock(&LOCK_open)); if (error) { @@ -7509,6 +7510,7 @@ view_err: thd_proc_info(thd, "end"); DBUG_EXECUTE_IF("sleep_alter_before_main_binlog", my_sleep(6000000);); + DEBUG_SYNC(thd, "alter_table_before_main_binlog"); ha_binlog_log_query(thd, create_info->db_type, LOGCOM_ALTER_TABLE, thd->query(), thd->query_length(), diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index aa2ed498de1..1b63d8493be 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -327,6 +327,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) TABLE *table; bool result= TRUE; String stmt_query; + Query_tables_list backup; bool need_start_waiting= FALSE; DBUG_ENTER("mysql_create_or_drop_trigger"); @@ -393,6 +394,12 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) { bool if_exists= thd->lex->drop_if_exists; + /* + Protect the query table list from the temporary and potentially + destructive changes necessary to open the trigger's table. + */ + thd->lex->reset_n_backup_query_tables_list(&backup); + if (add_table_for_trigger(thd, thd->lex->spname, if_exists, & tables)) goto end; @@ -512,6 +519,10 @@ end: VOID(pthread_mutex_unlock(&LOCK_open)); + /* Restore the query table list. Used only for drop trigger. */ + if (!create) + thd->lex->restore_backup_query_tables_list(&backup); + if (need_start_waiting) start_waiting_global_read_lock(thd); @@ -1625,10 +1636,6 @@ bool add_table_for_trigger(THD *thd, if (load_table_name_for_trigger(thd, trg_name, &trn_path, &tbl_name)) DBUG_RETURN(TRUE); - /* We need to reset statement table list to be PS/SP friendly. */ - lex->query_tables= 0; - lex->query_tables_last= &lex->query_tables; - *table= sp_add_to_query_tables(thd, lex, trg_name->m_db.str, tbl_name.str, TL_IGNORE); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index c9c4501f072..9ee3a1e01a7 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -399,10 +399,7 @@ int mysql_update(THD *thd, matching rows before updating the table! */ if (used_index < MAX_KEY && old_covering_keys.is_set(used_index)) - { - table->key_read=1; table->mark_columns_used_by_index(used_index); - } else { table->use_all_columns(); @@ -849,11 +846,7 @@ int mysql_update(THD *thd, err: delete select; free_underlaid_joins(thd, select_lex); - if (table->key_read) - { - table->key_read=0; - table->file->extra(HA_EXTRA_NO_KEYREAD); - } + table->set_keyread(FALSE); thd->abort_on_warning= 0; DBUG_RETURN(1); } @@ -1199,6 +1192,57 @@ reopen_tables: } +/** + Implementation of the safe update options during UPDATE IGNORE. This syntax + causes an UPDATE statement to ignore all errors. In safe update mode, + however, we must never ignore the ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE. There + is a special hook in my_message_sql that will otherwise delete all errors + when the IGNORE option is specified. + + In the future, all IGNORE handling should be used with this class and all + traces of the hack outlined below should be removed. + + - The parser detects IGNORE option and sets thd->lex->ignore= 1 + + - In JOIN::optimize, if this is set, then + thd->lex->current_select->no_error gets set. + + - In my_message_sql(), if the flag above is set then any error is + unconditionally converted to a warning. + + We are moving in the direction of using Internal_error_handler subclasses + to do all such error tweaking, please continue this effort if new bugs + appear. + */ +class Safe_dml_handler : public Internal_error_handler { + +private: + bool m_handled_error; + +public: + explicit Safe_dml_handler() : m_handled_error(FALSE) {} + + bool handle_condition(THD *thd, + uint sql_errno, + const char* sqlstate, + MYSQL_ERROR::enum_warning_level level, + const char* msg, + MYSQL_ERROR ** cond_hdl) + { + if (level == MYSQL_ERROR::WARN_LEVEL_ERROR && + sql_errno == ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE) + { + thd->stmt_da->set_error_status(thd, sql_errno, msg, sqlstate); + m_handled_error= TRUE; + return TRUE; + } + return FALSE; + } + + bool handled_error() { return m_handled_error; } + +}; + /* Setup multi-update handling and call SELECT to do the join */ @@ -1231,18 +1275,35 @@ bool mysql_multi_update(THD *thd, MODE_STRICT_ALL_TABLES)); List<Item> total_list; + + Safe_dml_handler handler; + bool using_handler= thd->options & OPTION_SAFE_UPDATES; + if (using_handler) + thd->push_internal_handler(&handler); + res= mysql_select(thd, &select_lex->ref_pointer_array, - table_list, select_lex->with_wild, - total_list, - conds, 0, (ORDER *) NULL, (ORDER *)NULL, (Item *) NULL, - (ORDER *)NULL, - options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK | - OPTION_SETUP_TABLES_DONE, - *result, unit, select_lex); - DBUG_PRINT("info",("res: %d report_error: %d", res, - (int) thd->is_error())); + table_list, select_lex->with_wild, + total_list, + conds, 0, (ORDER *) NULL, (ORDER *)NULL, (Item *) NULL, + (ORDER *)NULL, + options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK | + OPTION_SETUP_TABLES_DONE, + *result, unit, select_lex); + + if (using_handler) + { + Internal_error_handler *top_handler= thd->pop_internal_handler(); + DBUG_ASSERT(&handler == top_handler); + } + + DBUG_PRINT("info",("res: %d report_error: %d", res, (int) thd->is_error())); res|= thd->is_error(); - if (unlikely(res)) + /* + Todo: remove below code and make Safe_dml_handler do error processing + instead. That way we can return the actual error instead of + ER_UNKNOWN_ERROR. + */ + if (unlikely(res) && (!using_handler || !handler.handled_error())) { /* If we had a another error reported earlier then this will be ignored */ (*result)->send_error(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR)); diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 858b6ba43d7..6cce80dac85 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -400,17 +400,14 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, DBUG_ASSERT(!lex->proc_list.first && !lex->result && !lex->param_list.elements); - if (mode != VIEW_CREATE_NEW) + if (mode == VIEW_ALTER && fill_defined_view_parts(thd, view)) { - if (mode == VIEW_ALTER && - fill_defined_view_parts(thd, view)) - { - res= TRUE; - goto err; - } - sp_cache_invalidate(); + res= TRUE; + goto err; } + sp_cache_invalidate(); + if (!lex->definer) { /* diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 36a910b7a99..070bb4e70b2 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -4916,7 +4916,7 @@ create_table_option: | TYPE_SYM opt_equal storage_engines { Lex->create_info.db_type= $3; - WARN_DEPRECATED(yythd, "6.0", "TYPE=storage_engine", + WARN_DEPRECATED(yythd, "5.4.4", "TYPE=storage_engine", "'ENGINE=storage_engine'"); Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE; } diff --git a/sql/table.cc b/sql/table.cc index dce3e2301ec..5397e03add2 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4379,7 +4379,7 @@ void TABLE::mark_columns_used_by_index(uint index) MY_BITMAP *bitmap= &tmp_set; DBUG_ENTER("TABLE::mark_columns_used_by_index"); - (void) file->extra(HA_EXTRA_KEYREAD); + set_keyread(TRUE); bitmap_clear_all(bitmap); mark_columns_used_by_index_no_reset(index, bitmap); column_bitmaps_set(bitmap, bitmap); @@ -4402,8 +4402,7 @@ void TABLE::restore_column_maps_after_mark_index() { DBUG_ENTER("TABLE::restore_column_maps_after_mark_index"); - key_read= 0; - (void) file->extra(HA_EXTRA_NO_KEYREAD); + set_keyread(FALSE); default_column_bitmaps(); file->column_bitmaps_signal(); DBUG_VOID_RETURN; diff --git a/sql/table.h b/sql/table.h index 6723dfc40dd..46f05c6ddf4 100644 --- a/sql/table.h +++ b/sql/table.h @@ -899,6 +899,20 @@ struct TABLE inline bool needs_reopen_or_name_lock() { return s->version != refresh_version; } bool is_children_attached(void); + inline void set_keyread(bool flag) + { + DBUG_ASSERT(file); + if (flag && !key_read) + { + key_read= 1; + file->extra(HA_EXTRA_KEYREAD); + } + else if (!flag && key_read) + { + key_read= 0; + file->extra(HA_EXTRA_NO_KEYREAD); + } + } }; enum enum_schema_table_state |