diff options
Diffstat (limited to 'sql/table.cc')
-rw-r--r-- | sql/table.cc | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/sql/table.cc b/sql/table.cc index de5a71f6af1..375f7a3f65f 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -44,7 +44,6 @@ #include "sql_cte.h" #include "ha_sequence.h" #include "sql_show.h" -#include <atomic> /* For MySQL 5.7 virtual fields */ #define MYSQL57_GENERATED_FIELD 128 @@ -70,8 +69,6 @@ LEX_CSTRING GENERAL_LOG_NAME= {STRING_WITH_LEN("general_log")}; LEX_CSTRING SLOW_LOG_NAME= {STRING_WITH_LEN("slow_log")}; LEX_CSTRING TRANSACTION_REG_NAME= {STRING_WITH_LEN("transaction_registry")}; -LEX_CSTRING MYSQL_USER_NAME= {STRING_WITH_LEN("user")}; -LEX_CSTRING MYSQL_DB_NAME= {STRING_WITH_LEN("db")}; LEX_CSTRING MYSQL_PROC_NAME= {STRING_WITH_LEN("proc")}; /* @@ -250,6 +247,13 @@ TABLE_CATEGORY get_table_category(const LEX_CSTRING *db, DBUG_ASSERT(db != NULL); DBUG_ASSERT(name != NULL); +#ifdef WITH_WSREP + if (my_strcasecmp(system_charset_info, db->str, "mysql") == 0 && + my_strcasecmp(system_charset_info, name->str, "wsrep_streaming_log") == 0) + { + return TABLE_CATEGORY_INFORMATION; + } +#endif /* WITH_WSREP */ if (is_infoschema_db(db)) return TABLE_CATEGORY_INFORMATION; @@ -325,7 +329,8 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name, share->can_do_row_logging= 1; if (share->table_category == TABLE_CATEGORY_LOG) share->no_replicate= 1; - if (my_strnncoll(table_alias_charset, (uchar*) db, 6, + if (key_length > 6 && + my_strnncoll(table_alias_charset, (const uchar*) key, 6, (const uchar*) "mysql", 6) == 0) share->not_usable_by_query_cache= 1; @@ -338,6 +343,9 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name, mysql_mutex_init(key_TABLE_SHARE_LOCK_ha_data, &share->LOCK_ha_data, MY_MUTEX_INIT_FAST); + DBUG_EXECUTE_IF("simulate_big_table_id", + if (last_table_id < UINT_MAX32) + last_table_id= UINT_MAX32 - 1;); /* There is one reserved number that cannot be used. Remember to change this when 6-byte global table id's are introduced. @@ -346,7 +354,8 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name, { share->table_map_id= last_table_id.fetch_add(1, std::memory_order_relaxed); - } while (unlikely(share->table_map_id == ~0UL)); + } while (unlikely(share->table_map_id == ~0UL || + share->table_map_id == 0)); } DBUG_RETURN(share); } @@ -432,6 +441,7 @@ void TABLE_SHARE::destroy() ha_share= NULL; // Safety } + delete_stat_values_for_table_share(this); delete sequence; free_root(&stats_cb.mem_root, MYF(0)); stats_cb.stats_can_be_read= FALSE; @@ -1076,7 +1086,7 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table, while (pos < end) { uint type, expr_length; - if (table->s->mysql_version >= 100202) + if (table->s->frm_version >= FRM_VER_EXPRESSSIONS) { uint field_nr, name_length; /* see pack_expression() for how data is stored */ @@ -2309,7 +2319,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, uint pk_part_length= key_first_info->key_part[i].store_length; if (keyinfo->ext_key_part_map & 1<<i) { - if (ext_key_length + pk_part_length > MAX_KEY_LENGTH) + if (ext_key_length + pk_part_length > MAX_DATA_LENGTH_FOR_KEY) { add_keyparts_for_this_key= i; break; @@ -2319,9 +2329,9 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, } } - if (add_keyparts_for_this_key < (keyinfo->ext_key_parts - - keyinfo->user_defined_key_parts)) - { + if (add_keyparts_for_this_key < keyinfo->ext_key_parts - + keyinfo->user_defined_key_parts) + { share->ext_key_parts-= keyinfo->ext_key_parts; key_part_map ext_key_part_map= keyinfo->ext_key_part_map; keyinfo->ext_key_parts= keyinfo->user_defined_key_parts; @@ -2472,7 +2482,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, if (!(key_part->key_part_flag & (HA_BLOB_PART | HA_VAR_LENGTH_PART | HA_BIT_PART)) && key_part->type != HA_KEYTYPE_FLOAT && - key_part->type == HA_KEYTYPE_DOUBLE) + key_part->type != HA_KEYTYPE_DOUBLE) key_part->key_part_flag|= HA_CAN_MEMCMP; } keyinfo->usable_key_parts= usable_parts; // Filesort @@ -3163,10 +3173,12 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, { enum open_frm_error error; uint records, i, bitmap_size, bitmap_count; + const char *tmp_alias; bool error_reported= FALSE; uchar *record, *bitmaps; Field **field_ptr; uint8 save_context_analysis_only= thd->lex->context_analysis_only; + TABLE_SHARE::enum_v_keys check_set_initialized= share->check_set_initialized; DBUG_ENTER("open_table_from_share"); DBUG_PRINT("enter",("name: '%s.%s' form: %p", share->db.str, share->table_name.str, outparam)); @@ -3190,8 +3202,14 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, init_sql_alloc(&outparam->mem_root, "table", TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); - if (outparam->alias.copy(alias->str, alias->length, table_alias_charset)) + /* + We have to store the original alias in mem_root as constraints and virtual + functions may store pointers to it + */ + if (!(tmp_alias= strmake_root(&outparam->mem_root, alias->str, alias->length))) goto err; + + outparam->alias.set(tmp_alias, alias->length, table_alias_charset); outparam->quick_keys.init(); outparam->covering_keys.init(); outparam->intersect_keys.init(); @@ -3280,6 +3298,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, } (*field_ptr)= 0; // End marker + DEBUG_SYNC(thd, "TABLE_after_field_clone"); + outparam->vers_write= share->versioned; if (share->found_next_number_field) @@ -3528,6 +3548,16 @@ partititon_err: } outparam->mark_columns_used_by_virtual_fields(); + if (!check_set_initialized && + share->check_set_initialized == TABLE_SHARE::V_KEYS) + { + // copy PART_INDIRECT_KEY_FLAG that was set meanwhile by *some* thread + for (uint i= 0 ; i < share->fields ; i++) + { + if (share->field[i]->flags & PART_INDIRECT_KEY_FLAG) + outparam->field[i]->flags|= PART_INDIRECT_KEY_FLAG; + } + } if (db_stat) { @@ -3539,6 +3569,8 @@ partititon_err: share->no_replicate= TRUE; if (outparam->file->table_cache_type() & HA_CACHE_TBL_NOCACHE) share->not_usable_by_query_cache= TRUE; + if (outparam->file->ha_table_flags() & HA_CAN_ONLINE_BACKUPS) + share->online_backup= 1; } if (share->no_replicate || !binlog_filter->db_ok(share->db.str)) @@ -3936,6 +3968,7 @@ void update_create_info_from_table(HA_CREATE_INFO *create_info, TABLE *table) create_info->table_options= share->db_create_options; create_info->avg_row_length= share->avg_row_length; create_info->row_type= share->row_type; + create_info->key_block_size= share->key_block_size; create_info->default_table_charset= share->table_charset; create_info->table_charset= 0; create_info->comment= share->comment; @@ -4615,7 +4648,7 @@ void TABLE::init(THD *thd, TABLE_LIST *tl) s->table_name.str, tl->alias.str); /* Fix alias if table name changes. */ - if (strcmp(alias.c_ptr(), tl->alias.str)) + if (!alias.alloced_length() || strcmp(alias.c_ptr(), tl->alias.str)) alias.copy(tl->alias.str, tl->alias.length, alias.charset()); tablenr= thd->current_tablenr++; @@ -6847,6 +6880,7 @@ void TABLE::mark_columns_used_by_virtual_fields(void) { MY_BITMAP *save_read_set; Field **vfield_ptr; + TABLE_SHARE::enum_v_keys v_keys= TABLE_SHARE::NO_V_KEYS; /* If there is virtual fields are already initialized */ if (s->check_set_initialized) @@ -6887,12 +6921,12 @@ void TABLE::mark_columns_used_by_virtual_fields(void) if (bitmap_is_set(&tmp_set, i)) { s->field[i]->flags|= PART_INDIRECT_KEY_FLAG; - field[i]->flags|= PART_INDIRECT_KEY_FLAG; + v_keys= TABLE_SHARE::V_KEYS; } } bitmap_clear_all(&tmp_set); } - s->check_set_initialized= 1; + s->check_set_initialized= v_keys; if (s->tmp_table == NO_TMP_TABLE) mysql_mutex_unlock(&s->LOCK_share); } @@ -8561,6 +8595,7 @@ bool TR_table::update(ulonglong start_id, ulonglong end_id) return true; store(FLD_BEGIN_TS, thd->transaction_time()); + thd->set_time(); timeval end_time= {thd->query_start(), int(thd->query_start_sec_part())}; store(FLD_TRX_ID, start_id); store(FLD_COMMIT_ID, end_id); @@ -8642,7 +8677,7 @@ bool TR_table::query(MYSQL_TIME &commit_time, bool backwards) if (res > 0) { MYSQL_TIME commit_ts; - if ((*this)[FLD_COMMIT_TS]->get_date(&commit_ts, 0)) + if ((*this)[FLD_COMMIT_TS]->get_date(&commit_ts, date_mode_t(0))) { found= false; break; |