diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/filesort.cc | 1 | ||||
-rw-r--r-- | sql/ha_myisam.cc | 69 | ||||
-rw-r--r-- | sql/ha_myisam.h | 20 | ||||
-rw-r--r-- | sql/handler.cc | 2 | ||||
-rw-r--r-- | sql/handler.h | 2 | ||||
-rw-r--r-- | sql/key.cc | 9 | ||||
-rw-r--r-- | sql/mysql_priv.h | 2 | ||||
-rw-r--r-- | sql/mysqld.cc | 76 | ||||
-rw-r--r-- | sql/sql_base.cc | 7 | ||||
-rw-r--r-- | sql/sql_class.cc | 1 | ||||
-rw-r--r-- | sql/sql_class.h | 1 | ||||
-rw-r--r-- | sql/sql_insert.cc | 13 | ||||
-rw-r--r-- | sql/table.cc | 8 |
13 files changed, 159 insertions, 52 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc index 96ce57fc683..10984af5510 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -861,7 +861,6 @@ static int merge_index(SORTPARAM *param, uchar **sort_keys, buffpek+maxbuffer,1)) DBUG_RETURN(1); /* purecov: inspected */ DBUG_RETURN(0); - /* Was: DBUG_RETURN(my_b_write(outfile,last_ref,param->ref_length)); */ } /* merge_index */ diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 768e663bfa5..1c5356e0c32 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -31,10 +31,11 @@ #endif ulong myisam_sort_buffer_size; -myisam_recover_types myisam_recover_type= HA_RECOVER_NONE; +ulong myisam_recover_options= HA_RECOVER_NONE; +/* bits in myisam_recover_options */ const char *myisam_recover_names[] = -{ "NO","DEFAULT", "BACKUP"}; +{ "DEFAULT", "BACKUP", "FORCE"}; TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names),"", myisam_recover_names}; @@ -152,7 +153,7 @@ int ha_myisam::dump(THD* thd, int fd) my_off_t bytes_to_read = share->state.state.data_file_length; int data_fd = file->dfile; byte * buf = (byte*) my_malloc(blocksize, MYF(MY_WME)); - if(!buf) + if (!buf) return ENOMEM; int error = 0; @@ -342,19 +343,19 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt) char* backup_dir = thd->lex.backup_dir; char src_path[FN_REFLEN], dst_path[FN_REFLEN]; char* table_name = table->real_name; - if(!fn_format(src_path, table_name, backup_dir, MI_NAME_DEXT, 4 + 64)) + if (!fn_format(src_path, table_name, backup_dir, MI_NAME_DEXT, 4 + 64)) return HA_ADMIN_INVALID; int error = 0; const char* errmsg = ""; - if(my_copy(src_path, fn_format(dst_path, table->path, "", - MI_NAME_DEXT, 4), MYF(MY_WME))) - { - error = HA_ADMIN_FAILED; - errmsg = "failed in my_copy( Error %d)"; - goto err; - } + if (my_copy(src_path, fn_format(dst_path, table->path, "", + MI_NAME_DEXT, 4), MYF(MY_WME))) + { + error = HA_ADMIN_FAILED; + errmsg = "failed in my_copy( Error %d)"; + goto err; + } tmp_check_opt.init(); tmp_check_opt.quick = 1; @@ -373,26 +374,27 @@ 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 src_path[FN_REFLEN], dst_path[FN_REFLEN]; char* table_name = table->real_name; - if(!fn_format(dst_path, table_name, backup_dir, reg_ext, 4 + 64)) + if (!fn_format(dst_path, table_name, backup_dir, reg_ext, 4 + 64)) return HA_ADMIN_INVALID; - if(my_copy(fn_format(src_path, table->path,"", reg_ext, 4), + if (my_copy(fn_format(src_path, table->path,"", reg_ext, 4), dst_path, MYF(MY_WME | MY_HOLD_ORIGINAL_MODES ))) - { - return HA_ADMIN_FAILED; - } + { + return HA_ADMIN_FAILED; + } - if(!fn_format(dst_path, table_name, backup_dir, MI_NAME_DEXT, 4 + 64)) + if (!fn_format(dst_path, table_name, backup_dir, MI_NAME_DEXT, 4 + 64)) return HA_ADMIN_INVALID; - if(my_copy(fn_format(src_path, table->path,"", MI_NAME_DEXT, 4), - dst_path, - MYF(MY_WME | MY_HOLD_ORIGINAL_MODES )) ) + if (my_copy(fn_format(src_path, table->path,"", MI_NAME_DEXT, 4), + dst_path, + MYF(MY_WME | MY_HOLD_ORIGINAL_MODES )) ) return HA_ADMIN_FAILED; return HA_ADMIN_OK; @@ -572,6 +574,33 @@ bool ha_myisam::activate_all_index(THD *thd) DBUG_RETURN(error); } + +bool ha_myisam::check_and_repair(THD *thd, const char *name) +{ + int error=0; + HA_CHECK_OPT check_opt; + DBUG_ENTER("ha_myisam::auto_check_and_repair"); + + if (open(name, O_RDWR, HA_OPEN_WAIT_IF_LOCKED)) + DBUG_RETURN(1); + + check_opt.init(); + check_opt.flags=T_MEDIUM; + if (mi_is_crashed(file) || check(thd, &check_opt)) + { + check_opt.flags=(((myisam_recover_options & HA_RECOVER_BACKUP) ? + T_BACKUP_DATA : 0) | + (!(myisam_recover_options & HA_RECOVER_FORCE) ? + T_SAFE_REPAIR : 0)); + if (repair(thd, &check_opt)) + error=1; + } + if (close()) + error=1; + DBUG_RETURN(error); +} + + int ha_myisam::update_row(const byte * old_data, byte * new_data) { statistic_increment(ha_update_count,&LOCK_status); diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h index f1e5b217762..d33fc52c937 100644 --- a/sql/ha_myisam.h +++ b/sql/ha_myisam.h @@ -24,12 +24,14 @@ #include <myisam.h> #include <ft_global.h> -enum myisam_recover_types { HA_RECOVER_NONE, HA_RECOVER_DEFAULT, - HA_RECOVER_BACKUP}; +#define HA_RECOVER_NONE 0 // No automatic recover +#define HA_RECOVER_DEFAULT 1 // Automatic recover active +#define HA_RECOVER_BACKUP 2 // Make a backupfile on recover +#define HA_RECOVER_FORCE 4 // Recover even if we loose rows extern ulong myisam_sort_buffer_size; extern TYPELIB myisam_recover_typelib; -extern myisam_recover_types myisam_recover_type; +extern ulong myisam_recover_options; class ha_myisam: public handler { @@ -39,11 +41,12 @@ class ha_myisam: public handler public: ha_myisam(TABLE *table): handler(table), file(0), - int_option_flag(HA_READ_NEXT+HA_READ_PREV+HA_READ_RND_SAME+ - HA_KEYPOS_TO_RNDPOS+ HA_READ_ORDER+ HA_LASTKEY_ORDER+ - HA_HAVE_KEY_READ_ONLY+ HA_READ_NOT_EXACT_KEY+ - HA_LONGLONG_KEYS+ HA_NULL_KEY + - HA_DUPP_POS + HA_BLOB_KEY + HA_AUTO_PART_KEY) + int_option_flag(HA_READ_NEXT | HA_READ_PREV | HA_READ_RND_SAME | + HA_KEYPOS_TO_RNDPOS | HA_READ_ORDER | HA_LASTKEY_ORDER | + HA_HAVE_KEY_READ_ONLY | HA_READ_NOT_EXACT_KEY | + HA_LONGLONG_KEYS | HA_NULL_KEY | + HA_DUPP_POS | HA_BLOB_KEY | HA_AUTO_PART_KEY | + HA_CHECK_AND_REPAIR) {} ~ha_myisam() {} const char *table_type() const { return "MyISAM"; } @@ -100,6 +103,7 @@ class ha_myisam: public handler int check(THD* thd, HA_CHECK_OPT* check_opt); int analyze(THD* thd,HA_CHECK_OPT* check_opt); int repair(THD* thd, HA_CHECK_OPT* check_opt); + bool check_and_repair(THD *thd, const char *name); int optimize(THD* thd, HA_CHECK_OPT* check_opt); int restore(THD* thd, HA_CHECK_OPT* check_opt); int backup(THD* thd, HA_CHECK_OPT* check_opt); diff --git a/sql/handler.cc b/sql/handler.cc index 68d12a96f98..a0ec18d3614 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -594,7 +594,7 @@ int ha_create_table(const char *name, HA_CREATE_INFO *create_info, TABLE table; DBUG_ENTER("ha_create_table"); - if (openfrm(name,"",0,(uint) READ_ALL,&table)) + if (openfrm(name,"",0,(uint) READ_ALL, 0, &table)) DBUG_RETURN(1); if (update_create_info) { diff --git a/sql/handler.h b/sql/handler.h index 7f39b78deee..d256ee944e7 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -66,6 +66,7 @@ #define HA_NO_WRITE_DELAYED (HA_NOT_EXACT_COUNT*2) #define HA_PRIMARY_KEY_IN_READ_INDEX (HA_NO_WRITE_DELAYED*2) #define HA_DROP_BEFORE_CREATE (HA_PRIMARY_KEY_IN_READ_INDEX*2) +#define HA_CHECK_AND_REPAIR (HA_DROP_BEFORE_CREATE*2) /* Parameters for open() (in register form->filestat) */ /* HA_GET_INFO does a implicit HA_ABORT_IF_LOCKED */ @@ -248,6 +249,7 @@ public: virtual void update_create_info(HA_CREATE_INFO *create_info) {} virtual int check(THD* thd, HA_CHECK_OPT* check_opt ); virtual int repair(THD* thd, HA_CHECK_OPT* check_opt); + virtual bool check_and_repair(THD *thd, const char *name) {return 1;} virtual int optimize(THD* thd,HA_CHECK_OPT* check_opt); virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt); virtual int backup(THD* thd, HA_CHECK_OPT* check_opt); diff --git a/sql/key.cc b/sql/key.cc index df3f0fe25d5..8678202922e 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -243,7 +243,10 @@ void key_unpack(String *to,TABLE *table,uint idx) } -/* Return 1 if any field in a list is part of key */ +/* + Return 1 if any field in a list is part of key or the key uses a field + that is automaticly updated (like a timestamp) +*/ bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields) { @@ -255,6 +258,10 @@ bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields) key_part++) { Item_field *field; + + if (key_part->field == table->timestamp_field) + return 1; // Can't be used for update + f.rewind(); while ((field=(Item_field*) f++)) { diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index dd87f40efe9..c428cb2936b 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -531,7 +531,7 @@ int rea_create_table(my_string file_name,HA_CREATE_INFO *create_info, int format_number(uint inputflag,uint max_length,my_string pos,uint length, my_string *errpos); int openfrm(const char *name,const char *alias,uint filestat,uint prgflag, - TABLE *outparam); + uint ha_open_flags, TABLE *outparam); int closefrm(TABLE *table); db_type get_table_type(const char *name); int read_string(File file, gptr *to, uint length); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index aa3aa0b0bf4..90afdcd42d5 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -282,7 +282,7 @@ extern pthread_handler_decl(handle_slave,arg); #ifdef SET_RLIMIT_NOFILE static uint set_maximum_open_files(uint max_file_limit); #endif - +static ulong find_bit_type(const char *x, TYPELIB *bit_lib); /**************************************************************************** ** Code to end mysqld @@ -1064,6 +1064,7 @@ static void init_signals(void) sigaddset(&set,SIGTERM); sigaddset(&set,SIGHUP); signal(SIGTERM,SIG_DFL); // If it's blocked by parent + signal(SIGHUP,SIG_DFL); // If it's blocked by parent #ifdef SIGTSTP sigaddset(&set,SIGTSTP); #endif @@ -2568,6 +2569,8 @@ static void usage(void) Log slow queries to this log file. Defaults logging\n\ to hostname-slow.log\n\ --pid-file=path Pid file used by safe_mysqld\n\ + --myisam-recover[=option[,option...]] where options is one of DEAULT,\n\ + BACKUP or FORCE.\n\ --memlock Lock mysqld in memory\n\ -n, --new Use very new possible 'unsafe' functions\n\ -o, --old-protocol Use the old (3.20) protocol\n\ @@ -2856,13 +2859,13 @@ static void get_options(int argc,char **argv) default_table_type=DB_TYPE_ISAM; myisam_delay_key_write=0; myisam_concurrent_insert=0; - myisam_recover_type= HA_RECOVER_NONE; + myisam_recover_options= 0; break; case (int) OPT_SAFE: opt_specialflag|= SPECIAL_SAFE_MODE; myisam_delay_key_write=0; myisam_concurrent_insert=0; - myisam_recover_type= HA_RECOVER_NONE; // For now + myisam_recover_options= HA_RECOVER_NONE; // To be changed break; case (int) OPT_SKIP_CONCURRENT_INSERT: myisam_concurrent_insert=0; @@ -3026,13 +3029,14 @@ static void get_options(int argc,char **argv) #endif case OPT_MYISAM_RECOVER: { - int type; - if ((type=find_type(optarg, &myisam_recover_typelib, 2)) <= 0) + if (!optarg || !optarg[0]) + myisam_recover_options=HA_RECOVER_DEFAULT; + else if ((myisam_recover_options= + find_bit_type(optarg, &myisam_recover_typelib)) == ~(ulong) 0) { - fprintf(stderr,"Unknown option to myisam-recover: %s\n",optarg); + fprintf(stderr, "Unknown option to myisam-recover: %s\n",optarg); exit(1); } - myisam_recover_type=(myisam_recover_types) (type-1); break; } case OPT_MASTER_HOST: @@ -3568,6 +3572,64 @@ static uint set_maximum_open_files(uint max_file_limit) #endif + /* + Return a bitfield from a string of substrings separated by ',' + returns ~(ulong) 0 on error. + */ + +static ulong find_bit_type(const char *x, TYPELIB *bit_lib) +{ + bool found_end; + int found_count; + const char *end,*i,*j; + const char **array, *pos; + ulong found,found_int,bit; + DBUG_ENTER("find_bit_type"); + DBUG_PRINT("enter",("x: '%s'",x)); + + found=0; + found_end= 0; + pos=(my_string) x; + do + { + if (!*(end=strcend(pos,','))) /* Let end point at fieldend */ + { + while (end > pos && end[-1] == ' ') + end--; /* Skipp end-space */ + found_end=1; + } + found_int=0; found_count=0; + for (array=bit_lib->type_names, bit=1 ; (i= *array++) ; bit<<=1) + { + j=pos; + while (j != end) + { + if (toupper(*i++) != toupper(*j++)) + goto skipp; + } + found_int=bit; + if (! *i) + { + found_count=1; + break; + } + else if (j != pos) // Half field found + { + found_count++; // Could be one of two values + } +skipp: ; + } + if (found_count != 1) + DBUG_RETURN(~(ulong) 0); // No unique value + found|=found_int; + pos=end+1; + } while (! found_end); + + DBUG_PRINT("exit",("bit-field: %ld",(ulong) found)); + DBUG_RETURN(found); +} /* find_bit_type */ + + /***************************************************************************** ** Instantiate templates *****************************************************************************/ diff --git a/sql/sql_base.cc b/sql/sql_base.cc index eb3952be281..e216d771063 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -675,7 +675,7 @@ void close_thread_tables(THD *thd, bool locked) } thd->open_tables=0; /* Free tables to hold down open files */ - while (open_cache.records >= table_cache_size && unused_tables) + while (open_cache.records > table_cache_size && unused_tables) VOID(hash_delete(&open_cache,(byte*) unused_tables)); /* purecov: tested */ check_unused(); if (found_old_table) @@ -987,7 +987,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, else { /* Free cache if too big */ - while (open_cache.records >= table_cache_size && unused_tables) + while (open_cache.records > table_cache_size && unused_tables) VOID(hash_delete(&open_cache,(byte*) unused_tables)); /* purecov: tested */ /* make a new table */ @@ -1410,6 +1410,7 @@ static int open_unireg_entry(TABLE *entry,const char *db,const char *name, (uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX | HA_TRY_READ_ONLY), READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD, + ha_open_options, entry)) { DBUG_RETURN(1); @@ -1575,6 +1576,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db, (uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX | HA_TRY_READ_ONLY), READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD, + ha_open_options, tmp_table)) { DBUG_RETURN(0); @@ -1859,6 +1861,7 @@ int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields, DBUG_RETURN(-1); /* purecov: inspected */ if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM) item->split_sum_func(*sum_func_list); + thd->used_tables|=item->used_tables(); } } DBUG_RETURN(test(thd->fatal_error)); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 2db08045d89..31390066e2e 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -88,6 +88,7 @@ THD::THD() open_tables=temporary_tables=0; tmp_table=0; lock=locked_tables=0; + used_tables=0; cuted_fields=0L; options=thd_startup_options; update_lock_default= low_priority_updates ? TL_WRITE_LOW_PRIORITY : TL_WRITE; diff --git a/sql/sql_class.h b/sql/sql_class.h index 9e4293c7b62..2e3f9252377 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -263,6 +263,7 @@ public: ulonglong next_insert_id,last_insert_id,current_insert_id; ha_rows select_limit,offset_limit,default_select_limit,cuted_fields, max_join_size,sent_row_count; + table_map used_tables; ulong query_id,version, inactive_timeout,options,thread_id; long dbug_thread_id; pthread_t real_id; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 13feba9ab9c..26d110ba31c 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -140,6 +140,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields, if (!table) DBUG_RETURN(-1); thd->proc_info="init"; + thd->used_tables=0; save_time_stamp=table->time_stamp; values= its++; if (check_insert_fields(thd,table,fields,*values,1) || @@ -200,7 +201,10 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields, } else { - table->record[0][0]=table->record[2][0]; // Fix delete marker + if (thd->used_tables) // Column used in values() + restore_record(table,2); // Get empty record + else + table->record[0][0]=table->record[2][0]; // Fix delete marker if (fill_record(table->field,*values)) { if (values_list.elements != 1) @@ -1166,12 +1170,7 @@ select_insert::prepare(List<Item> &values) if (check_insert_fields(thd,table,*fields,values,1)) DBUG_RETURN(1); - if (fields->elements) - { - restore_record(table,2); // Get empty record - } - else - table->record[0][0]=table->record[2][0]; // Fix delete marker + restore_record(table,2); // Get empty record table->next_number_field=table->found_next_number_field; thd->count_cuted_fields=1; /* calc cuted fields */ thd->cuted_fields=0; diff --git a/sql/table.cc b/sql/table.cc index 66a2ef767b0..c7fe81c182c 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -40,7 +40,7 @@ static byte* get_field_name(Field *buff,uint *length, /* Open a .frm file */ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, - TABLE *outparam) + uint ha_open_flags, TABLE *outparam) { reg1 uint i; reg2 uchar *strpos; @@ -216,12 +216,12 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, ha_open(index_file, (db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR), (db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : - db_stat & HA_WAIT_IF_LOCKED || - specialflag & SPECIAL_WAIT_IF_LOCKED ? + (db_stat & HA_WAIT_IF_LOCKED || + specialflag & SPECIAL_WAIT_IF_LOCKED) ? HA_OPEN_WAIT_IF_LOCKED : (db_stat & (HA_ABORT_IF_LOCKED | HA_GET_INFO)) ? HA_OPEN_ABORT_IF_LOCKED : - HA_OPEN_IGNORE_IF_LOCKED) | ha_open_options))) + HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))) goto err_not_open; /* purecov: inspected */ } outparam->db_low_byte_first=outparam->file->low_byte_first(); |