diff options
Diffstat (limited to 'sql/ha_myisam.cc')
-rw-r--r-- | sql/ha_myisam.cc | 220 |
1 files changed, 114 insertions, 106 deletions
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index c89eb4426ff..87329c6f4af 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -233,7 +233,7 @@ int ha_myisam::open(const char *name, int mode, uint test_if_locked) info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST); if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED)) VOID(mi_extra(file, HA_EXTRA_WAIT_LOCK, 0)); - if (!table->db_record_offset) + if (!table->s->db_record_offset) int_table_flags|=HA_REC_NOT_IN_SEQ; if (file->s->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD)) int_table_flags|=HA_HAS_CHECKSUM; @@ -275,9 +275,9 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) thd->proc_info="Checking table"; myisamchk_init(¶m); param.thd = thd; - param.op_name = (char*)"check"; - param.db_name = table->table_cache_key; - param.table_name = table->table_name; + param.op_name = "check"; + param.db_name= table->s->db; + param.table_name= table->alias; param.testflag = check_opt->flags | T_CHECK | T_SILENT; if (!(table->db_stat & HA_READ_ONLY)) @@ -362,11 +362,11 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) myisamchk_init(¶m); param.thd = thd; - param.op_name = (char*) "analyze"; - param.db_name = table->table_cache_key; - param.table_name = table->table_name; - param.testflag=(T_FAST | T_CHECK | T_SILENT | T_STATISTICS | - T_DONT_CHECK_CHECKSUM); + param.op_name= "analyze"; + param.db_name= table->s->db; + param.table_name= table->alias; + param.testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS | + T_DONT_CHECK_CHECKSUM); param.using_global_keycache = 1; if (!(share->state.changed & STATE_NOT_ANALYZED)) @@ -388,9 +388,9 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt) { HA_CHECK_OPT tmp_check_opt; - char* backup_dir= thd->lex->backup_dir; + char *backup_dir= thd->lex->backup_dir; char src_path[FN_REFLEN], dst_path[FN_REFLEN]; - char* table_name = table->real_name; + const char *table_name= table->s->table_name; int error; const char* errmsg; DBUG_ENTER("restore"); @@ -399,11 +399,11 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt) MI_NAME_DEXT)) DBUG_RETURN(HA_ADMIN_INVALID); - if (my_copy(src_path, fn_format(dst_path, table->path, "", + if (my_copy(src_path, fn_format(dst_path, table->s->path, "", MI_NAME_DEXT, 4), MYF(MY_WME))) { - error = HA_ADMIN_FAILED; - errmsg = "Failed in my_copy (Error %d)"; + error= HA_ADMIN_FAILED; + errmsg= "Failed in my_copy (Error %d)"; goto err; } @@ -415,11 +415,11 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt) { MI_CHECK param; myisamchk_init(¶m); - param.thd = thd; - param.op_name = (char*)"restore"; - param.db_name = table->table_cache_key; - param.table_name = table->table_name; - param.testflag = 0; + param.thd= thd; + param.op_name= "restore"; + param.db_name= table->s->db; + param.table_name= table->s->table_name; + param.testflag= 0; mi_check_print_error(¶m, errmsg, my_errno); DBUG_RETURN(error); } @@ -428,9 +428,9 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt) int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt) { - char* backup_dir= thd->lex->backup_dir; + char *backup_dir= thd->lex->backup_dir; char src_path[FN_REFLEN], dst_path[FN_REFLEN]; - char* table_name = table->real_name; + const char *table_name= table->s->table_name; int error; const char *errmsg; DBUG_ENTER("ha_myisam::backup"); @@ -438,12 +438,13 @@ int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt) if (fn_format_relative_to_data_home(dst_path, table_name, backup_dir, reg_ext)) { - errmsg = "Failed in fn_format() for .frm file (errno: %d)"; - error = HA_ADMIN_INVALID; + errmsg= "Failed in fn_format() for .frm file (errno: %d)"; + error= HA_ADMIN_INVALID; goto err; } - if (my_copy(fn_format(src_path, table->path,"", reg_ext, MY_UNPACK_FILENAME), + if (my_copy(fn_format(src_path, table->s->path, "", reg_ext, + MY_UNPACK_FILENAME), dst_path, MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_DONT_OVERWRITE_FILE))) { @@ -461,7 +462,7 @@ int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt) goto err; } - if (my_copy(fn_format(src_path, table->path,"", MI_NAME_DEXT, + if (my_copy(fn_format(src_path, table->s->path, "", MI_NAME_DEXT, MY_UNPACK_FILENAME), dst_path, MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_DONT_OVERWRITE_FILE))) @@ -476,11 +477,11 @@ int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt) { MI_CHECK param; myisamchk_init(¶m); - param.thd = thd; - param.op_name = (char*)"backup"; - param.db_name = table->table_cache_key; - param.table_name = table->table_name; - param.testflag = 0; + param.thd= thd; + param.op_name= "backup"; + param.db_name= table->s->db; + param.table_name= table->s->table_name; + param.testflag = 0; mi_check_print_error(¶m,errmsg, my_errno); DBUG_RETURN(error); } @@ -497,10 +498,10 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) myisamchk_init(¶m); param.thd = thd; - param.op_name = (char*) "repair"; - param.testflag = ((check_opt->flags & ~(T_EXTEND)) | - T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM | - (check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT)); + param.op_name= "repair"; + param.testflag= ((check_opt->flags & ~(T_EXTEND)) | + T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM | + (check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT)); param.sort_buffer_length= check_opt->sort_buffer_size; start_records=file->state->records; while ((error=repair(thd,param,0)) && param.retry_repair) @@ -511,7 +512,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) { param.testflag&= ~T_RETRY_WITHOUT_QUICK; sql_print_information("Retrying repair of: '%s' without quick", - table->path); + table->s->path); continue; } param.testflag&= ~T_QUICK; @@ -519,7 +520,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) { param.testflag= (param.testflag & ~T_REP_BY_SORT) | T_REP; sql_print_information("Retrying repair of: '%s' with keycache", - table->path); + table->s->path); continue; } break; @@ -531,7 +532,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) sql_print_information("Found %s of %s rows when repairing '%s'", llstr(file->state->records, llbuff), llstr(start_records, llbuff2), - table->path); + table->s->path); } return error; } @@ -544,9 +545,9 @@ int ha_myisam::optimize(THD* thd, HA_CHECK_OPT *check_opt) myisamchk_init(¶m); param.thd = thd; - param.op_name = (char*) "optimize"; - param.testflag = (check_opt->flags | T_SILENT | T_FORCE_CREATE | - T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX); + param.op_name= "optimize"; + param.testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE | + T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX); param.sort_buffer_length= check_opt->sort_buffer_size; if ((error= repair(thd,param,1)) && param.retry_repair) { @@ -570,18 +571,18 @@ int ha_myisam::repair(THD *thd, MI_CHECK ¶m, bool optimize) ha_rows rows= file->state->records; DBUG_ENTER("ha_myisam::repair"); - param.db_name = table->table_cache_key; - param.table_name = table->table_name; + param.db_name= table->s->db; + param.table_name= table->alias; param.tmpfile_createflag = O_RDWR | O_TRUNC; param.using_global_keycache = 1; - param.thd=thd; - param.tmpdir=&mysql_tmpdir_list; - param.out_flag=0; + param.thd= thd; + param.tmpdir= &mysql_tmpdir_list; + param.out_flag= 0; strmov(fixed_name,file->filename); // Don't lock tables if we have used LOCK TABLE if (!thd->locked_tables && - mi_lock_database(file, table->tmp_table ? F_EXTRA_LCK : F_WRLCK)) + mi_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK)) { mi_check_print_error(¶m,ER(ER_CANT_LOCK),my_errno); DBUG_RETURN(HA_ADMIN_FAILED); @@ -740,9 +741,9 @@ int ha_myisam::assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt) MI_CHECK param; myisamchk_init(¶m); param.thd= thd; - param.op_name= (char*)"assign_to_keycache"; - param.db_name= table->table_cache_key; - param.table_name= table->table_name; + param.op_name= "assign_to_keycache"; + param.db_name= table->s->db; + param.table_name= table->s->table_name; param.testflag= 0; mi_check_print_error(¶m, errmsg); } @@ -808,10 +809,10 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt) MI_CHECK param; myisamchk_init(¶m); param.thd= thd; - param.op_name= (char*)"preload_keys"; - param.db_name= table->table_cache_key; - param.table_name= table->table_name; - param.testflag= 0; + param.op_name= "preload_keys"; + param.db_name= table->s->db; + param.table_name= table->s->table_name; + param.testflag= 0; mi_check_print_error(¶m, errmsg); DBUG_RETURN(error); } @@ -916,9 +917,9 @@ int ha_myisam::enable_indexes(uint mode) const char *save_proc_info=thd->proc_info; thd->proc_info="Creating index"; myisamchk_init(¶m); - param.op_name = (char*) "recreating_index"; - param.testflag = (T_SILENT | T_REP_BY_SORT | T_QUICK | - T_CREATE_MISSING_KEYS); + param.op_name= "recreating_index"; + param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK | + T_CREATE_MISSING_KEYS); param.myf_rw&= ~MY_WAIT_IF_FULL; param.sort_buffer_length= thd->variables.myisam_sort_buff_size; param.tmpdir=&mysql_tmpdir_list; @@ -983,8 +984,9 @@ int ha_myisam::indexes_are_disabled(void) void ha_myisam::start_bulk_insert(ha_rows rows) { DBUG_ENTER("ha_myisam::start_bulk_insert"); - THD *thd=current_thd; - ulong size= min(thd->variables.read_buff_size, table->avg_row_length*rows); + THD *thd= current_thd; + ulong size= min(thd->variables.read_buff_size, + table->s->avg_row_length*rows); DBUG_PRINT("info",("start_bulk_insert: rows %lu size %lu", (ulong) rows, size)); @@ -1052,18 +1054,18 @@ bool ha_myisam::check_and_repair(THD *thd) // Don't use quick if deleted rows if (!file->state->del && (myisam_recover_options & HA_RECOVER_QUICK)) check_opt.flags|=T_QUICK; - sql_print_warning("Checking table: '%s'",table->path); + sql_print_warning("Checking table: '%s'",table->s->path); old_query= thd->query; old_query_length= thd->query_length; pthread_mutex_lock(&LOCK_thread_count); - thd->query= table->real_name; - thd->query_length= strlen(table->real_name); + thd->query= (char*) table->s->table_name; + thd->query_length= strlen(table->s->table_name); pthread_mutex_unlock(&LOCK_thread_count); if ((marked_crashed= mi_is_crashed(file)) || check(thd, &check_opt)) { - sql_print_warning("Recovering table: '%s'",table->path); + sql_print_warning("Recovering table: '%s'",table->s->path); check_opt.flags= ((myisam_recover_options & HA_RECOVER_BACKUP ? T_BACKUP_DATA : 0) | (marked_crashed ? 0 : T_QUICK) | @@ -1237,25 +1239,25 @@ void ha_myisam::info(uint flag) } if (flag & HA_STATUS_CONST) { - max_data_file_length=info.max_data_file_length; - max_index_file_length=info.max_index_file_length; - create_time = info.create_time; - sortkey = info.sortkey; - ref_length=info.reflength; - table->db_options_in_use = info.options; - block_size=myisam_block_size; - table->keys_in_use.set_prefix(table->keys); - table->keys_in_use.intersect(info.key_map); - table->keys_for_keyread= table->keys_in_use; - table->keys_for_keyread.subtract(table->read_only_keys); - table->db_record_offset=info.record_offset; - if (table->key_parts) + TABLE_SHARE *share= table->s; + max_data_file_length= info.max_data_file_length; + max_index_file_length= info.max_index_file_length; + create_time= info.create_time; + sortkey= info.sortkey; + ref_length= info.reflength; + share->db_options_in_use= info.options; + block_size= myisam_block_size; + share->keys_in_use.set_prefix(share->keys); + share->keys_in_use.intersect(info.key_map); + share->keys_for_keyread.intersect(share->keys_in_use); + share->db_record_offset= info.record_offset; + if (share->key_parts) memcpy((char*) table->key_info[0].rec_per_key, (char*) info.rec_per_key, - sizeof(table->key_info[0].rec_per_key)*table->key_parts); - raid_type=info.raid_type; - raid_chunks=info.raid_chunks; - raid_chunksize=info.raid_chunksize; + sizeof(table->key_info[0].rec_per_key)*share->key_parts); + raid_type= info.raid_type; + raid_chunks= info.raid_chunks; + raid_chunksize= info.raid_chunksize; /* Set data_file_name and index_file_name to point at the symlink value @@ -1311,7 +1313,7 @@ int ha_myisam::delete_table(const char *name) int ha_myisam::external_lock(THD *thd, int lock_type) { - return mi_lock_database(file, !table->tmp_table ? + return mi_lock_database(file, !table->s->tmp_table ? lock_type : ((lock_type == F_UNLCK) ? F_UNLCK : F_EXTRA_LCK)); } @@ -1356,21 +1358,23 @@ int ha_myisam::create(const char *name, register TABLE *table_arg, MI_KEYDEF *keydef; MI_COLUMNDEF *recinfo,*recinfo_pos; HA_KEYSEG *keyseg; - uint options=table_arg->db_options_in_use; + TABLE_SHARE *share= table->s; + uint options= share->db_options_in_use; DBUG_ENTER("ha_myisam::create"); type=HA_KEYTYPE_BINARY; // Keep compiler happy if (!(my_multi_malloc(MYF(MY_WME), - &recinfo,(table_arg->fields*2+2)*sizeof(MI_COLUMNDEF), - &keydef, table_arg->keys*sizeof(MI_KEYDEF), + &recinfo,(share->fields*2+2)* + sizeof(MI_COLUMNDEF), + &keydef, share->keys*sizeof(MI_KEYDEF), &keyseg, - ((table_arg->key_parts + table_arg->keys) * + ((share->key_parts + share->keys) * sizeof(HA_KEYSEG)), NullS))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); pos=table_arg->key_info; - for (i=0; i < table_arg->keys ; i++, pos++) + for (i=0; i < share->keys ; i++, pos++) { keydef[i].flag= (pos->flags & (HA_NOSAME | HA_FULLTEXT | HA_SPATIAL)); keydef[i].key_alg= pos->algorithm == HA_KEY_ALG_UNDEF ? @@ -1431,7 +1435,7 @@ int ha_myisam::create(const char *name, register TABLE *table_arg, keydef[i].seg[j].flag|=HA_BLOB_PART; /* save number of bytes used to pack length */ keydef[i].seg[j].bit_start= (uint) (field->pack_length() - - table_arg->blob_ptr_size); + share->blob_ptr_size); } else if (field->type() == FIELD_TYPE_BIT) { @@ -1446,15 +1450,16 @@ int ha_myisam::create(const char *name, register TABLE *table_arg, if (table_arg->found_next_number_field) { - keydef[table_arg->next_number_index].flag|= HA_AUTO_KEY; - found_real_auto_increment= table_arg->next_number_key_offset == 0; + keydef[share->next_number_index].flag|= HA_AUTO_KEY; + found_real_auto_increment= share->next_number_key_offset == 0; } recpos=0; recinfo_pos=recinfo; - while (recpos < (uint) table_arg->reclength) + while (recpos < (uint) share->reclength) { Field **field,*found=0; - minpos=table_arg->reclength; length=0; + minpos= share->reclength; + length=0; for (field=table_arg->field ; *field ; field++) { @@ -1517,25 +1522,25 @@ int ha_myisam::create(const char *name, register TABLE *table_arg, } MI_CREATE_INFO create_info; bzero((char*) &create_info,sizeof(create_info)); - create_info.max_rows=table_arg->max_rows; - create_info.reloc_rows=table_arg->min_rows; + create_info.max_rows= share->max_rows; + create_info.reloc_rows= share->min_rows; create_info.with_auto_increment=found_real_auto_increment; create_info.auto_increment=(info->auto_increment_value ? info->auto_increment_value -1 : (ulonglong) 0); - create_info.data_file_length= ((ulonglong) table_arg->max_rows * - table_arg->avg_row_length); + create_info.data_file_length= ((ulonglong) share->max_rows * + share->avg_row_length); create_info.raid_type=info->raid_type; create_info.raid_chunks= (info->raid_chunks ? info->raid_chunks : RAID_DEFAULT_CHUNKS); - create_info.raid_chunksize=(info->raid_chunksize ? info->raid_chunksize : - RAID_DEFAULT_CHUNKSIZE); - create_info.data_file_name= info->data_file_name; - create_info.index_file_name=info->index_file_name; + create_info.raid_chunksize= (info->raid_chunksize ? info->raid_chunksize : + RAID_DEFAULT_CHUNKSIZE); + create_info.data_file_name= info->data_file_name; + create_info.index_file_name= info->index_file_name; /* TODO: Check that the following fn_format is really needed */ error=mi_create(fn_format(buff,name,"","",2+4), - table_arg->keys,keydef, + share->keys,keydef, (uint) (recinfo_pos-recinfo), recinfo, 0, (MI_UNIQUEDEF*) 0, &create_info, @@ -1562,26 +1567,29 @@ ulonglong ha_myisam::get_auto_increment() int error; byte key[MI_MAX_KEY_LENGTH]; - if (!table->next_number_key_offset) + if (!table->s->next_number_key_offset) { // Autoincrement at key-start ha_myisam::info(HA_STATUS_AUTO); return auto_increment_value; } /* it's safe to call the following if bulk_insert isn't on */ - mi_flush_bulk_insert(file, table->next_number_index); + mi_flush_bulk_insert(file, table->s->next_number_index); (void) extra(HA_EXTRA_KEYREAD); key_copy(key, table->record[0], - table->key_info + table->next_number_index, - table->next_number_key_offset); - error=mi_rkey(file,table->record[1],(int) table->next_number_index, - key,table->next_number_key_offset,HA_READ_PREFIX_LAST); + table->key_info + table->s->next_number_index, + table->s->next_number_key_offset); + error= mi_rkey(file,table->record[1],(int) table->s->next_number_index, + key,table->s->next_number_key_offset,HA_READ_PREFIX_LAST); if (error) nr= 1; else + { + /* Get data from record[1] */ nr= ((ulonglong) table->next_number_field-> - val_int_offset(table->rec_buff_length)+1); + val_int_offset(table->s->rec_buff_length)+1); + } extra(HA_EXTRA_NO_KEYREAD); return nr; } |