From 7b047a31a09a7999353232cb6407b4e6338d5b70 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 8 Nov 2010 13:43:54 +0200 Subject: [PATCH 1/2] Make SQLString reallocation addaptive Avoid doing reallocs Prealloc some strings / provide extension allocation size to some strings This gave a 25 % speedup in some mysql-test-run tests. mysys/safemalloc.c: More DBUG_PRINT sql/net_serv.cc: Make all mallocs() look the similar. (just-for-safety fix) sql/protocol.cc: Ensure that communication packet buffer is allocated. (It's freed by stored precedures and some DLL statements) sql/sp.cc: Fixed valgrind warning sql/sql_select.cc: Set extent allocation for buffer that has a lot of append() calls. sql/sql_show.cc: Fixed wrong usage of string buffer. Old code worked in test suite 'just-by-chance' sql/sql_string.cc: Call realloc_with_extra_if_needed() in append() functions. sql/sql_string.h: Added 'extra_alloc' member, to specify chunck size for realloc(). extra_alloc is addaptive to catch cases where preallocation of buffers is not done properly. Simplified free() to allow compiler to optimize things better (and to keep things consistent). Fixed shrink() to take into account the extra memory added to the Alloced_length in realloc(). This saves us a realloc() per query. sql/sql_test.cc: Set extent allocation for buffer that has a lot of append() calls. sql/table.cc: Set extent allocation for buffer that has a lot of append() calls. --- mysys/safemalloc.c | 4 ++++ sql/net_serv.cc | 4 ++-- sql/protocol.cc | 3 +++ sql/sp.cc | 2 +- sql/sql_select.cc | 1 + sql/sql_show.cc | 2 +- sql/sql_string.cc | 18 ++++++++--------- sql/sql_string.h | 48 +++++++++++++++++++++++++++++----------------- sql/sql_test.cc | 3 ++- sql/table.cc | 4 +++- 10 files changed, 56 insertions(+), 33 deletions(-) diff --git a/mysys/safemalloc.c b/mysys/safemalloc.c index 0d0ae2dabe5..0e489263c69 100644 --- a/mysys/safemalloc.c +++ b/mysys/safemalloc.c @@ -224,6 +224,8 @@ void *_myrealloc(register void *ptr, register size_t size, struct st_irem *irem; char *data; DBUG_ENTER("_myrealloc"); + DBUG_PRINT("my",("ptr: 0x%lx size: %lu my_flags: %d", (long) ptr, + (ulong) size, MyFlags)); if (!ptr && (MyFlags & MY_ALLOW_ZERO_PTR)) DBUG_RETURN(_mymalloc(size, filename, lineno, MyFlags)); @@ -245,6 +247,8 @@ void *_myrealloc(register void *ptr, register size_t size, (void) fflush(stderr); DBUG_RETURN((uchar*) NULL); } + DBUG_PRINT("my", ("old_size: %lu -> new_size: %lu", + (ulong) irem->datasize, (ulong) size)); if ((data= _mymalloc(size,filename,lineno,MyFlags))) /* Allocate new area */ { diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 4796a5601bf..6a4079b1fef 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -116,7 +116,7 @@ my_bool my_net_init(NET *net, Vio* vio) net->vio = vio; my_net_local_init(net); /* Set some limits */ if (!(net->buff=(uchar*) my_malloc((size_t) net->max_packet+ - NET_HEADER_SIZE + COMP_HEADER_SIZE, + NET_HEADER_SIZE + COMP_HEADER_SIZE +1, MYF(MY_WME)))) DBUG_RETURN(1); net->buff_end=net->buff+net->max_packet; @@ -580,7 +580,7 @@ net_real_write(NET *net,const uchar *packet, size_t len) uchar *b; uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE; if (!(b= (uchar*) my_malloc(len + NET_HEADER_SIZE + - COMP_HEADER_SIZE, MYF(MY_WME)))) + COMP_HEADER_SIZE + 1, MYF(MY_WME)))) { net->error= 2; net->last_errno= ER_OUT_OF_RESOURCES; diff --git a/sql/protocol.cc b/sql/protocol.cc index 8a9d712077d..70b171fa652 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -632,6 +632,9 @@ bool Protocol::send_fields(List *list, uint flags) uint count= 0; #endif + /* We have to reallocate it here as a stored procedure may have reset it */ + (void) local_packet->alloc(thd->variables.net_buffer_length); + while ((item=it++)) { char *pos; diff --git a/sql/sp.cc b/sql/sp.cc index ebf2b3c360d..68e2f19fd47 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -785,7 +785,7 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp, { Parser_state parser_state; - if (parser_state.init(thd, defstr.c_ptr(), defstr.length())) + if (parser_state.init(thd, defstr.c_ptr_safe(), defstr.length())) { ret= SP_INTERNAL_ERROR; goto end; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e185996126d..e6be979becb 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -15997,6 +15997,7 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array, char buff[256]; String str(buff,sizeof(buff),&my_charset_bin); str.length(0); + str.extra_allocation(1024); item->print(&str, QT_ORDINARY); item_field->name= sql_strmake(str.ptr(),str.length()); } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 8f1f938d36e..265c86f55e7 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -4329,7 +4329,7 @@ static int get_schema_column_record(THD *thd, TABLE_LIST *tables, base_type [(dimension)] [unsigned] [zerofill]. For DATA_TYPE column we extract only base type. */ - tmp_buff= strchr(type.ptr(), '('); + tmp_buff= strchr(type.c_ptr_safe(), '('); if (!tmp_buff) /* if there is no dimention part then check the presence of diff --git a/sql/sql_string.cc b/sql/sql_string.cc index eafd8502706..b359b2a7168 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -411,7 +411,7 @@ bool String::append(const String &s) { if (s.length()) { - if (realloc(str_length+s.length())) + if (realloc_with_extra_if_needed(str_length+s.length())) return TRUE; memcpy(Ptr+str_length,s.ptr(),s.length()); str_length+=s.length(); @@ -436,7 +436,7 @@ bool String::append(const char *s,uint32 arg_length) { uint32 add_length=arg_length * str_charset->mbmaxlen; uint dummy_errors; - if (realloc(str_length+ add_length)) + if (realloc_with_extra_if_needed(str_length+ add_length)) return TRUE; str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset, s, arg_length, &my_charset_latin1, @@ -447,7 +447,7 @@ bool String::append(const char *s,uint32 arg_length) /* For an ASCII compatinble string we can just append. */ - if (realloc(str_length+arg_length)) + if (realloc_with_extra_if_needed(str_length+arg_length)) return TRUE; memcpy(Ptr+str_length,s,arg_length); str_length+=arg_length; @@ -478,14 +478,14 @@ bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs) { uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen; uint dummy_errors; - if (realloc(str_length + add_length)) + if (realloc_with_extra_if_needed(str_length + add_length)) return TRUE; str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset, s, arg_length, cs, &dummy_errors); } else { - if (realloc(str_length + arg_length)) + if (realloc_with_extra_if_needed(str_length + arg_length)) return TRUE; memcpy(Ptr + str_length, s, arg_length); str_length+= arg_length; @@ -497,7 +497,7 @@ bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs) #ifdef TO_BE_REMOVED bool String::append(FILE* file, uint32 arg_length, myf my_flags) { - if (realloc(str_length+arg_length)) + if (realloc_with_extra_if_needed(str_length+arg_length)) return TRUE; if (my_fread(file, (uchar*) Ptr + str_length, arg_length, my_flags)) { @@ -511,7 +511,7 @@ bool String::append(FILE* file, uint32 arg_length, myf my_flags) bool String::append(IO_CACHE* file, uint32 arg_length) { - if (realloc(str_length+arg_length)) + if (realloc_with_extra_if_needed(str_length+arg_length)) return TRUE; if (my_b_read(file, (uchar*) Ptr + str_length, arg_length)) { @@ -527,7 +527,7 @@ bool String::append_with_prefill(const char *s,uint32 arg_length, { int t_length= arg_length > full_length ? arg_length : full_length; - if (realloc(str_length + t_length)) + if (realloc_with_extra_if_needed(str_length + t_length)) return TRUE; t_length= full_length - arg_length; if (t_length > 0) @@ -636,7 +636,7 @@ bool String::replace(uint32 offset,uint32 arg_length, { if (diff) { - if (realloc(str_length+(uint32) diff)) + if (realloc_with_extra_if_needed(str_length+(uint32) diff)) return TRUE; bmove_upp((uchar*) Ptr+str_length+diff, (uchar*) Ptr+str_length, str_length-offset-arg_length); diff --git a/sql/sql_string.h b/sql/sql_string.h index e595de47f99..dc9122a4fcb 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -53,23 +53,24 @@ uint convert_to_printable(char *to, size_t to_len, class String { char *Ptr; - uint32 str_length,Alloced_length; + uint32 str_length,Alloced_length, extra_alloc; bool alloced; CHARSET_INFO *str_charset; public: String() { - Ptr=0; str_length=Alloced_length=0; alloced=0; + Ptr=0; str_length=Alloced_length=extra_alloc=0; alloced=0; str_charset= &my_charset_bin; } String(uint32 length_arg) { - alloced=0; Alloced_length=0; (void) real_alloc(length_arg); + alloced=0; Alloced_length= extra_alloc= 0; (void) real_alloc(length_arg); str_charset= &my_charset_bin; } String(const char *str, CHARSET_INFO *cs) { - Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0; + Ptr=(char*) str; str_length= (uint32) strlen(str); + Alloced_length= extra_alloc= 0; alloced=0; str_charset=cs; } /* @@ -79,18 +80,18 @@ public: */ String(const char *str,uint32 len, CHARSET_INFO *cs) { - Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0; + Ptr=(char*) str; str_length=len; Alloced_length= extra_alloc=0; alloced=0; str_charset=cs; } String(char *str,uint32 len, CHARSET_INFO *cs) { - Ptr=(char*) str; Alloced_length=str_length=len; alloced=0; + Ptr=(char*) str; Alloced_length=str_length=len; extra_alloc= 0; alloced=0; str_charset=cs; } String(const String &str) { Ptr=str.Ptr ; str_length=str.str_length ; - Alloced_length=str.Alloced_length; alloced=0; + Alloced_length=str.Alloced_length; extra_alloc= 0; alloced=0; str_charset=str.str_charset; } static void *operator new(size_t size, MEM_ROOT *mem_root) throw () @@ -106,8 +107,10 @@ public: inline CHARSET_INFO *charset() const { return str_charset; } inline uint32 length() const { return str_length;} inline uint32 alloced_length() const { return Alloced_length;} + inline uint32 extra_allocation() const { return extra_alloc;} inline char& operator [] (uint32 i) const { return Ptr[i]; } inline void length(uint32 len) { str_length=len ; } + inline void extra_allocation(uint32 len) { extra_alloc= len; } inline bool is_empty() const { return (str_length == 0); } inline void mark_as_const() { Alloced_length= 0;} inline const char *ptr() const { return Ptr; } @@ -136,23 +139,21 @@ public: { DBUG_ASSERT(&str != this); free(); - Ptr=(char*) str.ptr()+offset; str_length=arg_length; alloced=0; + Ptr=(char*) str.ptr()+offset; str_length=arg_length; if (str.Alloced_length) Alloced_length=str.Alloced_length-offset; - else - Alloced_length=0; str_charset=str.str_charset; } inline void set(char *str,uint32 arg_length, CHARSET_INFO *cs) { free(); - Ptr=(char*) str; str_length=Alloced_length=arg_length ; alloced=0; + Ptr=(char*) str; str_length=Alloced_length=arg_length; str_charset=cs; } inline void set(const char *str,uint32 arg_length, CHARSET_INFO *cs) { free(); - Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0; + Ptr=(char*) str; str_length=arg_length; str_charset=cs; } bool set_ascii(const char *str, uint32 arg_length); @@ -203,11 +204,11 @@ public: if (alloced) { alloced=0; - Alloced_length=0; my_free(Ptr,MYF(0)); - Ptr=0; - str_length=0; /* Safety */ } + Alloced_length= extra_alloc= 0; + Ptr=0; + str_length=0; /* Safety */ } inline bool alloc(uint32 arg_length) { @@ -217,9 +218,21 @@ public: } bool real_alloc(uint32 arg_length); // Empties old string bool realloc(uint32 arg_length); - inline void shrink(uint32 arg_length) // Shrink buffer + bool realloc_with_extra(uint32 arg_length) + { + if (extra_alloc < 4096) + extra_alloc= extra_alloc*2+128; + return realloc(arg_length + extra_alloc); + } + bool realloc_with_extra_if_needed(uint32 arg_length) { if (arg_length < Alloced_length) + return 0; + return realloc_with_extra(arg_length); + } + inline void shrink(uint32 arg_length) // Shrink buffer + { + if (ALIGN_SIZE(arg_length+1) < Alloced_length) { char *new_ptr; if (!(new_ptr=(char*) my_realloc(Ptr,arg_length,MYF(0)))) @@ -246,7 +259,6 @@ public: DBUG_ASSERT(!s.uses_buffer_owned_by(this)); free(); Ptr=s.Ptr ; str_length=s.str_length ; Alloced_length=s.Alloced_length; - alloced=0; } return *this; } @@ -281,7 +293,7 @@ public: } else { - if (realloc(str_length+1)) + if (realloc_with_extra(str_length + 1)) return 1; Ptr[str_length++]=chr; } diff --git a/sql/sql_test.cc b/sql/sql_test.cc index 541fcc155af..185c0a02799 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -57,9 +57,10 @@ print_where(COND *cond,const char *info, enum_query_type query_type) { if (cond) { - char buff[256]; + char buff[1024]; String str(buff,(uint32) sizeof(buff), system_charset_info); str.length(0); + str.extra_allocation(1024); cond->print(&str, query_type); str.append('\0'); DBUG_LOCK_FILE; diff --git a/sql/table.cc b/sql/table.cc index 7a2581d5ab8..45c1f5ab378 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -3328,11 +3328,13 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def) is backward compatible. */ } - char buffer[STRING_BUFFER_USUAL_SIZE]; + char buffer[1024]; for (i=0 ; i < table_def->count; i++, field_def++) { String sql_type(buffer, sizeof(buffer), system_charset_info); sql_type.length(0); + /* Allocate min 256 characters at once */ + sql_type.extra_allocation(256); if (i < table->s->fields) { Field *field= table->field[i]; From ff3da0f963b28d128005da8ca5d0c93a72d34b27 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 28 Feb 2011 12:48:50 +0200 Subject: [PATCH 2/2] Change TABLE->alias to String for less memory reallocation Changed some String.ptr() -> String.c_ptr() for String that are not guaranteed to end with \0 Removed some c_ptr() usage from parameters to functions that takes ptr & length Use preallocate buffers to avoid calling malloc() for most operations. sql/event_db_repository.cc: alias is now a String sql/event_scheduler.cc: c_ptr -> c_ptr_safe() to avoid warnings from valgrind. sql/events.cc: c_ptr -> c_ptr_safe() to avoid warnings from valgrind. c_ptr -> ptr() as function takes ptr & length sql/field.cc: alias is now a String sql/field.h: alias is now a String sql/ha_partition.cc: alias is now a String sql/handler.cc: alias is now a String ptr() -> c_ptr() as string is not guaranteed to be \0 terminated sql/item.cc: Store error parameter in separarte buffer to ensure correct error message sql/item_func.cc: ptr() -> c_ptr_safe() as string is not guaranteed to be \0 terminated sql/item_sum.h: Use my_strtod() instead of my_atof() to not have to make string \0 terminated sql/lock.cc: alias is now a String sql/log.cc: c_ptr() -> ptr() as function takes ptr & length sql/log_event.cc: c_ptr_quick() -> ptr() as we only want to get the pointer to String buffer sql/opt_range.cc: ptr() -> c_ptr() as string is not guaranteed to be \0 terminated sql/opt_table_elimination.cc: alias is now a String sql/set_var.cc: ptr() -> c_ptr() as string is not guaranteed to be \0 terminated c_ptr() -> c_ptr_safe() to avoid warnings from valgrind. c_ptr() -> ptr() as function takes ptr & length Simplify some code. sql/sp.cc: c_ptr() -> ptr() as function takes ptr & length sql/sp_rcontext.cc: alias is now a String sql/sql_base.cc: alias is now a String. Here we win a realloc() for most alias usage. sql/sql_class.cc: Use size descriptor for printf() to avoid accessing bytes outside of buffer sql/sql_insert.cc: Change allocation of TABLE as it's now contains a String _ptr() -> ptr() as function takes ptr & length sql/sql_load.cc: Use preallocate buffers to avoid calling malloc() for most operations. sql/sql_parse.cc: Use c_ptr_safe() to ensure string is \0 terminated. sql/sql_plugin.cc: c_ptr_quick() -> ptr() as function takes ptr & length sql/sql_select.cc: alias is now a String sql/sql_show.cc: alias is now a String sql/sql_string.h: Added move() function to change who owns the string (owner does the free) sql/sql_table.cc: alias is now a String c_ptr() -> c_ptr_safe() to avoid warnings from valgrind. sql/sql_test.cc: c_ptr() -> c_ptr_safe() to avoid warnings from valgrind. alias is now a String sql/sql_trigger.cc: c_ptr() -> c_ptr_safe() to avoid warnings from valgrind. Use field->init() to setup pointers to alias. sql/sql_update.cc: alias is now a String sql/sql_view.cc: ptr() -> c_ptr_safe() as string is not guaranteed to be \0 terminated sql/sql_yacc.yy: r() -> c_ptr() as string is not guaranteed to be \0 terminated sql/table.cc: alias is now a String sql/table.h: alias is now a String storage/federatedx/ha_federatedx.cc: Remove extra 1 byte alloc that is automaticly done by strmake() Ensure that error message ends with \0 storage/maria/ha_maria.cc: alias is now a String storage/myisam/ha_myisam.cc: alias is now a String --- sql/event_db_repository.cc | 2 +- sql/event_scheduler.cc | 2 +- sql/events.cc | 4 +- sql/field.cc | 4 +- sql/field.h | 9 +++- sql/ha_partition.cc | 6 ++- sql/handler.cc | 8 ++-- sql/item.cc | 27 +++++++----- sql/item_func.cc | 4 +- sql/item_sum.h | 9 +++- sql/lock.cc | 2 +- sql/log.cc | 4 +- sql/log_event.cc | 2 +- sql/opt_range.cc | 5 ++- sql/opt_table_elimination.cc | 9 ++-- sql/set_var.cc | 20 +++++---- sql/sp.cc | 4 +- sql/sp_rcontext.cc | 2 +- sql/sql_base.cc | 64 +++++++++++++++-------------- sql/sql_class.cc | 6 +-- sql/sql_insert.cc | 14 ++++--- sql/sql_load.cc | 15 ++++--- sql/sql_parse.cc | 3 +- sql/sql_plugin.cc | 2 +- sql/sql_select.cc | 22 ++++++---- sql/sql_show.cc | 6 +-- sql/sql_string.h | 9 ++++ sql/sql_table.cc | 6 +-- sql/sql_test.cc | 8 ++-- sql/sql_trigger.cc | 7 +--- sql/sql_update.cc | 3 +- sql/sql_view.cc | 4 +- sql/sql_yacc.yy | 2 +- sql/table.cc | 28 +++++++------ sql/table.h | 2 +- storage/federatedx/ha_federatedx.cc | 6 ++- storage/maria/ha_maria.cc | 6 +-- storage/myisam/ha_myisam.cc | 6 +-- 38 files changed, 198 insertions(+), 144 deletions(-) diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc index d1fa971847b..c1a64446c12 100644 --- a/sql/event_db_repository.cc +++ b/sql/event_db_repository.cc @@ -212,7 +212,7 @@ mysql_event_fill_row(THD *thd, Safety: this can only happen if someone started the server and then altered mysql.event. */ - my_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED, MYF(0), table->alias, + my_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED, MYF(0), table->alias.c_ptr(), (int) ET_FIELD_COUNT, table->s->fields); DBUG_RETURN(TRUE); } diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index 8446fe75c8f..4d6636eedb2 100755 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -100,7 +100,7 @@ Event_worker_thread::print_warnings(THD *thd, Event_job_data *et) err_msg.append(err->msg, strlen(err->msg), system_charset_info); DBUG_ASSERT(err->level < 3); (sql_print_message_handlers[err->level])("%*s", err_msg.length(), - err_msg.c_ptr()); + err_msg.c_ptr_safe()); } DBUG_VOID_RETURN; } diff --git a/sql/events.cc b/sql/events.cc index 1b794edb5ec..3713266aaa6 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -480,7 +480,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, } /* If the definer is not set or set to CURRENT_USER, the value of CURRENT_USER will be written into the binary log as the definer for the SQL thread. */ - ret= write_bin_log(thd, TRUE, log_query.c_ptr(), log_query.length()); + ret= write_bin_log(thd, TRUE, log_query.ptr(), log_query.length()); } } pthread_mutex_unlock(&LOCK_event_metadata); @@ -779,7 +779,7 @@ send_show_create_event(THD *thd, Event_timed *et, Protocol *protocol) protocol->store(et->name.str, et->name.length, system_charset_info); protocol->store(sql_mode.str, sql_mode.length, system_charset_info); protocol->store(tz_name->ptr(), tz_name->length(), system_charset_info); - protocol->store(show_str.c_ptr(), show_str.length(), + protocol->store(show_str.ptr(), show_str.length(), et->creation_ctx->get_client_cs()); protocol->store(et->creation_ctx->get_client_cs()->csname, strlen(et->creation_ctx->get_client_cs()->csname), diff --git a/sql/field.cc b/sql/field.cc index 741df0cc270..32c4d1949a8 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1536,9 +1536,9 @@ void Field::make_field(Send_field *field) } else field->org_table_name= field->db_name= ""; - if (orig_table && orig_table->alias) + if (orig_table && orig_table->alias.ptr()) { - field->table_name= orig_table->alias; + field->table_name= orig_table->alias.ptr(); field->org_col_name= field_name; } else diff --git a/sql/field.h b/sql/field.h index ca400caac59..0161f69ac4d 100644 --- a/sql/field.h +++ b/sql/field.h @@ -131,7 +131,8 @@ public: */ struct st_table *table; // Pointer for table struct st_table *orig_table; // Pointer to original table - const char **table_name, *field_name; + const char * const *table_name; + const char *field_name; /** reference to the list of options or NULL */ engine_option_value *option_list; void *option_struct; /* structure with parsed options */ @@ -551,10 +552,14 @@ public: return (op_result == E_DEC_OVERFLOW); } int warn_if_overflow(int op_result); + void set_table_name(String *alias) + { + table_name= &alias->Ptr; + } void init(TABLE *table_arg) { orig_table= table= table_arg; - table_name= &table_arg->alias; + set_table_name(&table_arg->alias); } /* maximum possible display length */ diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index a27dfc0e851..9722cc2deb4 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -1097,7 +1097,8 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, error != HA_ADMIN_ALREADY_DONE && error != HA_ADMIN_TRY_ALTER) { - print_admin_msg(thd, "error", table_share->db.str, table->alias, + print_admin_msg(thd, "error", table_share->db.str, + table->alias.c_ptr(), opt_op_name[flag], "Subpartition %s returned error", sub_elem->partition_name); @@ -1124,7 +1125,8 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, error != HA_ADMIN_ALREADY_DONE && error != HA_ADMIN_TRY_ALTER) { - print_admin_msg(thd, "error", table_share->db.str, table->alias, + print_admin_msg(thd, "error", table_share->db.str, + table->alias.c_ptr(), opt_op_name[flag], "Partition %s returned error", part_elem->partition_name); } diff --git a/sql/handler.cc b/sql/handler.cc index 48add3a1e53..59bfbb68452 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2009,7 +2009,8 @@ int ha_delete_table(THD *thd, handlerton *table_type, const char *path, dummy_share.db.length= strlen(db); dummy_share.table_name.str= (char*) alias; dummy_share.table_name.length= strlen(alias); - dummy_table.alias= alias; + dummy_table.alias.set(alias, dummy_share.table_name.length, + table_alias_charset); file->change_table_ptr(&dummy_table, &dummy_share); @@ -2852,11 +2853,12 @@ void handler::print_error(int error, myf errflag) { const char* engine= table_type(); if (temporary) - my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.ptr(), engine); + my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.c_ptr(), + engine); else { SET_FATAL_ERROR; - my_error(ER_GET_ERRMSG, MYF(0), error, str.ptr(), engine); + my_error(ER_GET_ERRMSG, MYF(0), error, str.c_ptr(), engine); } } else diff --git a/sql/item.cc b/sql/item.cc index 090286b179c..660e68b901c 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -735,7 +735,8 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) } if (cs->ctype) { - uint orig_len= length; + const char *str_start= str; + /* This will probably need a better implementation in the future: a function in CHARSET_INFO structure. @@ -745,16 +746,20 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) length--; str++; } - if (orig_len != length && !is_autogenerated_name) + if (str != str_start && !is_autogenerated_name) { + char buff[SAFE_NAME_LEN]; + strmake(buff, str_start, + min(sizeof(buff)-1, length + (int) (str-str_start))); + if (length == 0) push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY), - str + length - orig_len); + buff); else push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES), - str + length - orig_len); + buff); } } if (!my_charset_same(cs, system_charset_info)) @@ -2493,14 +2498,12 @@ double_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end) tmp= my_strntod(cs, (char*) cptr, end - cptr, &end, &error); if (error || (end != org_end && !check_if_only_end_space(cs, end, org_end))) { - /* - We can use str_value.ptr() here as Item_string is gurantee to put an - end \0 here. - */ + char buff[80]; + strmake(buff, cptr, min(sizeof(buff)-1, (size_t) (org_end-cptr))); push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE", - cptr); + buff); } return tmp; } @@ -2509,8 +2512,10 @@ double_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end) double Item_string::val_real() { DBUG_ASSERT(fixed == 1); - return double_from_string_with_check (str_value.charset(), str_value.ptr(), - (char *) str_value.ptr() + str_value.length()); + return double_from_string_with_check(str_value.charset(), + str_value.ptr(), + (char *) str_value.ptr() + + str_value.length()); } diff --git a/sql/item_func.cc b/sql/item_func.cc index 19f0f3ac344..56ef66fc26a 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -5787,7 +5787,7 @@ Item_func_sp::func_name() const qname.append('.'); } append_identifier(thd, &qname, m_name->m_name.str, m_name->m_name.length); - return qname.ptr(); + return qname.c_ptr_safe(); } @@ -5843,7 +5843,7 @@ Item_func_sp::init_result_field(THD *thd) */ share= dummy_table->s; - dummy_table->alias = ""; + dummy_table->alias.set("", 0, table_alias_charset); dummy_table->maybe_null = maybe_null; dummy_table->in_use= thd; dummy_table->copy_blobs= TRUE; diff --git a/sql/item_sum.h b/sql/item_sum.h index b5516792676..46e5ae76ab1 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -1274,8 +1274,13 @@ public: void make_unique(); double val_real() { - String *res; res=val_str(&str_value); - return res ? my_atof(res->c_ptr()) : 0.0; + int error; + const char *end; + String *res; + if (!(res= val_str(&str_value))) + return 0.0; + end= res->ptr() + res->length(); + return (my_strtod(res->ptr(), (char**) &end, &error)); } longlong val_int() { diff --git a/sql/lock.cc b/sql/lock.cc index 566275c5ea2..7c569bf7cfc 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -903,7 +903,7 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, *write_lock_used=table; if (table->db_stat & HA_READ_ONLY) { - my_error(ER_OPEN_AS_READONLY,MYF(0),table->alias); + my_error(ER_OPEN_AS_READONLY,MYF(0),table->alias.c_ptr()); /* Clear the lock type of the lock data that are stored already. */ sql_lock->lock_count= (uint) (locks - sql_lock->locks); reset_lock_data(sql_lock); diff --git a/sql/log.cc b/sql/log.cc index 07d9890ff78..93a9383f731 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1751,7 +1751,7 @@ static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv) log_query.append(thd->lex->ident.str, thd->lex->ident.length)) DBUG_RETURN(1); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); - Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(), + Query_log_event qinfo(thd, log_query.ptr(), log_query.length(), TRUE, TRUE, errcode); DBUG_RETURN(mysql_bin_log.write(&qinfo)); } @@ -1773,7 +1773,7 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv) log_query.append(thd->lex->ident.str, thd->lex->ident.length)) DBUG_RETURN(1); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); - Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(), + Query_log_event qinfo(thd, log_query.ptr(), log_query.length(), TRUE, TRUE, errcode); DBUG_RETURN(mysql_bin_log.write(&qinfo)); } diff --git a/sql/log_event.cc b/sql/log_event.cc index fa7bb01077d..32552bfe85f 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -568,7 +568,7 @@ append_query_string(CHARSET_INFO *csinfo, if (to->reserve(orig_len + from->length()*2+3)) return 1; - beg= to->c_ptr_quick() + to->length(); + beg= (char*) to->ptr() + to->length(); ptr= beg; if (csinfo->escape_with_backslash_is_dangerous) ptr= str_to_hex(ptr, from->ptr(), from->length()); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 51bc076ed00..c312ce7cb09 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -11274,7 +11274,8 @@ static void print_sel_tree(PARAM *param, SEL_TREE *tree, key_map *tree_map, if (!tmp.length()) tmp.append(STRING_WITH_LEN("(empty)")); - DBUG_PRINT("info", ("SEL_TREE: 0x%lx (%s) scans: %s", (long) tree, msg, tmp.ptr())); + DBUG_PRINT("info", ("SEL_TREE: 0x%lx (%s) scans: %s", (long) tree, msg, + tmp.c_ptr())); DBUG_VOID_RETURN; } @@ -11297,7 +11298,7 @@ static void print_ror_scans_arr(TABLE *table, const char *msg, } if (!tmp.length()) tmp.append(STRING_WITH_LEN("(empty)")); - DBUG_PRINT("info", ("ROR key scans (%s): %s", msg, tmp.ptr())); + DBUG_PRINT("info", ("ROR key scans (%s): %s", msg, tmp.c_ptr())); DBUG_VOID_RETURN; } diff --git a/sql/opt_table_elimination.cc b/sql/opt_table_elimination.cc index 174dcbf9c13..fdf818abb8e 100644 --- a/sql/opt_table_elimination.cc +++ b/sql/opt_table_elimination.cc @@ -1778,7 +1778,7 @@ static void mark_as_eliminated(JOIN *join, TABLE_LIST *tbl) JOIN_TAB *tab= tbl->table->reginfo.join_tab; if (!(join->const_table_map & tab->table->map)) { - DBUG_PRINT("info", ("Eliminated table %s", table->alias)); + DBUG_PRINT("info", ("Eliminated table %s", table->alias.c_ptr())); tab->type= JT_CONST; join->eliminated_tables |= table->map; join->const_table_map|= table->map; @@ -1813,7 +1813,7 @@ void Dep_analysis_context::dbug_print_deps() fprintf(DBUG_FILE, " equality%ld: %s -> %s.%s\n", (long)(eq_mod - equality_mods), str.c_ptr(), - eq_mod->field->table->table->alias, + eq_mod->field->table->table->alias.c_ptr(), eq_mod->field->field->field_name); } else @@ -1831,12 +1831,13 @@ void Dep_analysis_context::dbug_print_deps() if ((table_dep= table_deps[i])) { /* Print table */ - fprintf(DBUG_FILE, " table %s\n", table_dep->table->alias); + fprintf(DBUG_FILE, " table %s\n", table_dep->table->alias.c_ptr()); /* Print fields */ for (Dep_value_field *field_dep= table_dep->fields; field_dep; field_dep= field_dep->next_table_field) { - fprintf(DBUG_FILE, " field %s.%s ->", table_dep->table->alias, + fprintf(DBUG_FILE, " field %s.%s ->", + table_dep->table->alias.c_ptr(), field_dep->field->field_name); uint ofs= field_dep->bitmap_offset; for (uint bit= ofs; bit < ofs + n_equality_mods; bit++) diff --git a/sql/set_var.cc b/sql/set_var.cc index 95fd2d05f31..fb3b951532f 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -973,7 +973,7 @@ bool sys_var_str::check(THD *thd, set_var *var) if ((res=(*check_func)(thd, var)) < 0) my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), - name, var->value->str_value.ptr()); + name, var->value->str_value.c_ptr()); return res; } @@ -2264,11 +2264,15 @@ bool sys_var_character_set::check(THD *thd, set_var *var) } tmp= NULL; } - else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) && - !(tmp=get_old_charset_by_name(res->c_ptr()))) + else { - my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr()); - return 1; + const char *name= res->c_ptr_safe(); + if (!(tmp=get_charset_by_csname(name,MY_CS_PRIMARY,MYF(0))) && + !(tmp=get_old_charset_by_name(name))) + { + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), name); + return 1; + } } } else // INT_RESULT @@ -2605,7 +2609,7 @@ static int sys_check_log_path(THD *thd, set_var *var) if (!(res= var->value->val_str(&str))) goto err; - log_file_str= res->c_ptr(); + log_file_str= res->c_ptr_safe(); bzero(&f_stat, sizeof(MY_STAT)); path_length= unpack_filename(path, log_file_str); @@ -3068,7 +3072,7 @@ bool sys_var_thd_lc_time_names::check(THD *thd, set_var *var) my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); return 1; } - const char *locale_str= res->c_ptr(); + const char *locale_str= res->c_ptr_safe(); if (!(locale_match= my_locale_by_name(locale_str))) { my_printf_error(ER_UNKNOWN_ERROR, @@ -4100,7 +4104,7 @@ bool sys_var_thd_optimizer_switch::check(THD *thd, set_var *var) optimizer_switch_typelib.count, thd->variables.optimizer_switch, global_system_variables.optimizer_switch, - res->c_ptr_safe(), res->length(), NULL, + res->ptr(), res->length(), NULL, &error, &error_len, ¬_used); if (error_len) { diff --git a/sql/sp.cc b/sql/sp.cc index 68e2f19fd47..d2c732c2100 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -1104,7 +1104,7 @@ sp_create_routine(THD *thd, int type, sp_head *sp) (sp->m_explicit_name ? sp->m_db.length : 0), sp->m_name.str, sp->m_name.length, sp->m_params.str, sp->m_params.length, - retstr.c_ptr(), retstr.length(), + retstr.ptr(), retstr.length(), sp->m_body.str, sp->m_body.length, sp->m_chistics, &(thd->lex->definer->user), &(thd->lex->definer->host))) @@ -1116,7 +1116,7 @@ sp_create_routine(THD *thd, int type, sp_head *sp) thd->variables.sql_mode= saved_mode; /* Such a statement can always go directly to binlog, no trans cache */ if (thd->binlog_query(THD::MYSQL_QUERY_TYPE, - log_query.c_ptr(), log_query.length(), + log_query.ptr(), log_query.length(), FALSE, FALSE, 0)) ret= SP_INTERNAL_ERROR; thd->variables.sql_mode= 0; diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index be8f705a53e..686e1a1346f 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -118,7 +118,7 @@ sp_rcontext::init_var_table(THD *thd) return TRUE; m_var_table->copy_blobs= TRUE; - m_var_table->alias= ""; + m_var_table->alias.set("", 0, table_alias_charset); return FALSE; } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index c6260d0a857..b5876db7f45 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1474,12 +1474,11 @@ void close_temporary_tables(THD *thd) /* Better add "if exists", in case a RESET MASTER has been done */ const char stub[]= "DROP /*!40005 TEMPORARY */ TABLE IF EXISTS "; - uint stub_len= sizeof(stub) - 1; - char buf[256]; - String s_query= String(buf, sizeof(buf), system_charset_info); + char buf[FN_REFLEN]; + String s_query(buf, sizeof(buf), system_charset_info); bool found_user_tables= FALSE; - memcpy(buf, stub, stub_len); + s_query.copy(stub, sizeof(stub)-1, system_charset_info); /* Insertion sort of temp tables by pseudo_thread_id to build ordered list @@ -1533,19 +1532,25 @@ void close_temporary_tables(THD *thd) { bool save_thread_specific_used= thd->thread_specific_used; my_thread_id save_pseudo_thread_id= thd->variables.pseudo_thread_id; + char db_buf[FN_REFLEN]; + String db(db_buf, sizeof(db_buf), system_charset_info); + /* Set pseudo_thread_id to be that of the processed table */ thd->variables.pseudo_thread_id= tmpkeyval(thd, table); - String db; - db.append(table->s->db.str); + + db.copy(table->s->db.str, table->s->db.length, system_charset_info); + /* Reset s_query() if changed by previous loop */ + s_query.length(sizeof(stub)-1); + /* Loop forward through all tables that belong to a common database within the sublist of common pseudo_thread_id to create single DROP query */ - for (s_query.length(stub_len); + for (; table && is_user_table(table) && tmpkeyval(thd, table) == thd->variables.pseudo_thread_id && table->s->db.length == db.length() && - strcmp(table->s->db.str, db.ptr()) == 0; + memcmp(table->s->db.str, db.ptr(), db.length()) == 0; table= next) { /* @@ -1849,7 +1854,7 @@ int drop_temporary_table(THD *thd, TABLE_LIST *table_list) /* Table might be in use by some outer statement. */ if (table->query_id && table->query_id != thd->query_id) { - my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias); + my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias.c_ptr()); DBUG_RETURN(-1); } @@ -1872,7 +1877,7 @@ void close_temporary_table(THD *thd, TABLE *table, DBUG_ENTER("close_temporary_table"); DBUG_PRINT("tmptable", ("closing table: '%s'.'%s' 0x%lx alias: '%s'", table->s->db.str, table->s->table_name.str, - (long) table, table->alias)); + (long) table, table->alias.c_ptr())); /* When closing a MERGE parent or child table, detach the children @@ -2606,7 +2611,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, ("query_id: %lu server_id: %u pseudo_thread_id: %lu", (ulong) table->query_id, (uint) thd->server_id, (ulong) thd->variables.pseudo_thread_id)); - my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias); + my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias.c_ptr()); DBUG_RETURN(0); } table->query_id= thd->query_id; @@ -2643,7 +2648,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, When looking for a usable TABLE, ignore MERGE children, as they belong to their parent and cannot be used explicitly. */ - if (!my_strcasecmp(system_charset_info, table->alias, alias) && + if (!my_strcasecmp(system_charset_info, table->alias.c_ptr(), alias) && table->query_id != thd->query_id && /* skip tables already used */ !(thd->prelocked_mode && table->query_id) && !table->parent) @@ -2999,13 +3004,9 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, table->alias_name_used= my_strcasecmp(table_alias_charset, table->s->table_name.str, alias); /* Fix alias if table name changes */ - if (strcmp(table->alias, alias)) - { - uint length=(uint) strlen(alias)+1; - table->alias= (char*) my_realloc((char*) table->alias, length, - MYF(MY_WME)); - memcpy((char*) table->alias, alias, length); - } + if (strcmp(table->alias.c_ptr(), alias)) + table->alias.copy(alias, strlen(alias), table->alias.charset()); + /* These variables are also set in reopen_table() */ table->tablenr=thd->current_tablenr++; table->used_fields=0; @@ -3089,7 +3090,7 @@ bool reopen_table(TABLE *table) #ifdef EXTRA_DEBUG if (table->db_stat) sql_print_error("Table %s had a open data handler in reopen_table", - table->alias); + table->alias.c_ptr()); #endif bzero((char*) &table_list, sizeof(TABLE_LIST)); table_list.db= table->s->db.str; @@ -3100,7 +3101,7 @@ bool reopen_table(TABLE *table) DBUG_RETURN(1); // Thread was killed if (open_unireg_entry(thd, &tmp, &table_list, - table->alias, + table->alias.c_ptr(), table->s->table_cache_key.str, table->s->table_cache_key.length, thd->mem_root, 0)) @@ -3141,14 +3142,14 @@ bool reopen_table(TABLE *table) VOID(closefrm(table, 1)); // close file, free everything *table= tmp; + table->alias.move(tmp.alias); table->default_column_bitmaps(); table->file->change_table_ptr(table, table->s); - DBUG_ASSERT(table->alias != 0); + DBUG_ASSERT(table->alias.ptr() != 0); for (field=table->field ; *field ; field++) { - (*field)->table= (*field)->orig_table= table; - (*field)->table_name= &table->alias; + (*field)->init(table); } for (key=0 ; key < table->s->keys ; key++) { @@ -3275,7 +3276,7 @@ static bool reattach_merge(THD *thd, TABLE **err_tables_p) DBUG_PRINT("tcache", ("MERGE parent, attach children")); if(table->file->extra(HA_EXTRA_ATTACH_CHILDREN)) { - my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias); + my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias.c_ptr()); error= TRUE; /* Remove table from open_tables. */ *prv_p= next; @@ -3368,7 +3369,8 @@ bool reopen_tables(THD *thd, bool get_locks, bool mark_share_as_old) if (!tables || (!db_stat && reopen_table(table))) { my_error(ER_CANT_REOPEN_TABLE, MYF(0), - table->alias ? table->alias : table->s->table_name.str); + table->alias.ptr() ? table->alias.c_ptr() : + table->s->table_name.str); /* If we could not allocate 'tables', we may close open tables here. If a MERGE table is affected, detach the children first. @@ -3565,7 +3567,8 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock) char *key= table->s->table_cache_key.str; uint key_length= table->s->table_cache_key.length; - DBUG_PRINT("loop", ("table_name: %s", table->alias ? table->alias : "")); + DBUG_PRINT("loop", ("table_name: %s", + table->alias.ptr() ? table->alias.c_ptr() : "")); HASH_SEARCH_STATE state; for (TABLE *search= (TABLE*) hash_first(&open_cache, (uchar*) key, key_length, &state); @@ -4359,7 +4362,7 @@ void detach_merge_children(TABLE *table, bool clear_refs) Set alias to "" to ensure that table is not used if we are in LOCK TABLES */ - ((char*) child_l->table->alias)[0]= 0; + child_l->table->alias.length(0); /* Clear the table reference to force new assignment at next open. */ child_l->table= NULL; @@ -4912,7 +4915,7 @@ static bool check_lock_and_start_stmt(THD *thd, TABLE *table, if ((int) lock_type >= (int) TL_WRITE_ALLOW_READ && (int) table->reginfo.lock_type < (int) TL_WRITE_ALLOW_READ) { - my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->alias); + my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->alias.c_ptr()); DBUG_RETURN(1); } if ((error=table->file->start_stmt(thd, lock_type))) @@ -6024,7 +6027,8 @@ find_field_in_table(THD *thd, TABLE *table, const char *name, uint length, Field **field_ptr, *field; uint cached_field_index= *cached_field_index_ptr; DBUG_ENTER("find_field_in_table"); - DBUG_PRINT("enter", ("table: '%s', field name: '%s'", table->alias, name)); + DBUG_PRINT("enter", ("table: '%s', field name: '%s'", table->alias.c_ptr(), + name)); /* We assume here that table->field < NO_CACHED_FIELD_INDEX = UINT_MAX */ if (cached_field_index < table->s->fields && diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 20898d68500..57462bbddf8 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -4033,8 +4033,8 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg, int errcode) { DBUG_ENTER("THD::binlog_query"); - DBUG_PRINT("enter", ("qtype: %s query: '%s'", - show_query_type(qtype), query_arg)); + DBUG_PRINT("enter", ("qtype: %s query: '%-.*s'", + show_query_type(qtype), (int) query_len, query_arg)); DBUG_ASSERT(query_arg && mysql_bin_log.is_open()); /* @@ -4070,7 +4070,7 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg, { sql_print_warning("%s Statement: %.*s", ER(ER_BINLOG_UNSAFE_STATEMENT), - MYSQL_ERRMSG_SIZE, query_arg); + (int) min(MYSQL_ERRMSG_SIZE, query_len), query_arg); binlog_flags|= BINLOG_FLAG_UNSAFE_STMT_PRINTED; } } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 3c2f90e8080..9477d2ca971 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2074,6 +2074,7 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd) TABLE *copy; TABLE_SHARE *share; uchar *bitmap; + char *copy_tmp; DBUG_ENTER("Delayed_insert::get_local_table"); /* First request insert thread to get a lock */ @@ -2106,14 +2107,15 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd) the other record buffers and alignment are unnecessary. */ thd_proc_info(client_thd, "allocating local table"); - copy= (TABLE*) client_thd->alloc(sizeof(*copy)+ - (share->fields+1)*sizeof(Field**)+ - share->reclength + - share->column_bitmap_size*3); - if (!copy) + copy_tmp= (char*) client_thd->alloc(sizeof(*copy)+ + (share->fields+1)*sizeof(Field**)+ + share->reclength + + share->column_bitmap_size*3); + if (!copy_tmp) goto error; /* Copy the TABLE object. */ + copy= new (copy_tmp) TABLE; *copy= *table; /* We don't need to change the file handler here */ /* Assign the pointers for the field pointers array and the record. */ @@ -3502,7 +3504,7 @@ int select_create::write_to_binlog(bool is_trans, int errcode) Avoid to use thd->binlog_query() twice, otherwise it will print the unsafe warning twice. */ - Query_log_event ev(thd, query.c_ptr_safe(), query.length(), is_trans, + Query_log_event ev(thd, query.ptr(), query.length(), is_trans, FALSE, errcode); return mysql_bin_log.write(&ev); } diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 366c01b1754..75d9179c3bd 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -604,11 +604,15 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, size_t pl= 0; List fv; Item *item, *val; - String pfield, pfields; int n; const char *tbl= table_name_arg; const char *tdb= (thd->db != NULL ? thd->db : db_arg); - String string_buf; + char name_buffer[SAFE_NAME_LEN*2]; + char command_buffer[1024]; + String string_buf(name_buffer, sizeof(name_buffer), + system_charset_info); + String pfields(command_buffer, sizeof(command_buffer), + system_charset_info); if (!thd->db || strcmp(db_arg, thd->db)) { @@ -617,7 +621,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, prefix table name with database name so that it becomes a FQ name. */ - string_buf.set_charset(system_charset_info); + string_buf.length(0); string_buf.append(db_arg); string_buf.append("`"); string_buf.append("."); @@ -638,6 +642,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, /* prepare fields-list and SET if needed; print_query won't do that for us. */ + pfields.length(0); if (!thd->lex->field_list.is_empty()) { List_iterator li(thd->lex->field_list); @@ -682,8 +687,8 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, } } - p= pfields.c_ptr_safe(); - pl= strlen(p); + p= pfields.c_ptr_safe(); + pl= pfields.length(); if (!(load_data_query= (char *)thd->alloc(lle.get_query_buffer_length() + 1 + pl))) return TRUE; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f997bbcfaaf..b26fbfae68e 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5082,9 +5082,8 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) String str(buff,(uint32) sizeof(buff), system_charset_info); str.length(0); thd->lex->unit.print(&str, QT_ORDINARY); - str.append('\0'); push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, - ER_YES, str.ptr()); + ER_YES, str.c_ptr_safe()); } if (res) result->abort(); diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index dd908e1b60e..58cc7dc93a9 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -303,7 +303,7 @@ static const char *item_val_str(struct st_mysql_value *value, Lets be nice and create a temporary string since the buffer was too small */ - return current_thd->strmake(res->c_ptr_quick(), res->length()); + return current_thd->strmake(res->ptr(), res->length()); } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e6be979becb..94cc6a15c40 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6138,9 +6138,10 @@ static void add_not_null_conds(JOIN *join) */ if (notnull->fix_fields(join->thd, ¬null)) DBUG_VOID_RETURN; - DBUG_EXECUTE("where",print_where(notnull, - referred_tab->table->alias, - QT_ORDINARY);); + DBUG_EXECUTE("where", + print_where(notnull, + referred_tab->table->alias.c_ptr(), + QT_ORDINARY);); add_cond_and_fix(&referred_tab->select_cond, notnull); } } @@ -6399,7 +6400,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) } if (tmp || !cond || tab->type == JT_REF) { - DBUG_EXECUTE("where",print_where(tmp,tab->table->alias, QT_ORDINARY);); + DBUG_EXECUTE("where", + print_where(tmp,tab->table->alias.c_ptr(), + QT_ORDINARY);); SQL_SELECT *sel= tab->select= ((SQL_SELECT*) thd->memdup((uchar*) select, sizeof(*select))); @@ -6439,7 +6442,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) tab->select_cond= sel->cond= NULL; sel->head=tab->table; - DBUG_EXECUTE("where",print_where(tmp,tab->table->alias, QT_ORDINARY);); + DBUG_EXECUTE("where", + print_where(tmp,tab->table->alias.c_ptr(), + QT_ORDINARY);); if (tab->quick) { /* Use quick key read if it's a constant and it's not used @@ -10155,7 +10160,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, thd->mem_root= &table->mem_root; table->field=reg_field; - table->alias= table_alias; + table->alias.set(table_alias, strlen(table_alias), table_alias_charset); + table->reginfo.lock_type=TL_WRITE; /* Will be updated */ table->db_stat=HA_OPEN_KEYFILE+HA_OPEN_RNDFILE; table->map=1; @@ -10521,7 +10527,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, null_count=(null_count+7) & ~7; // move to next byte // fix table name in field entry - field->table_name= &table->alias; + field->set_table_name(&table->alias); } param->copy_field_end=copy; @@ -11239,7 +11245,7 @@ free_tmp_table(THD *thd, TABLE *entry) MEM_ROOT own_root= entry->mem_root; const char *save_proc_info; DBUG_ENTER("free_tmp_table"); - DBUG_PRINT("enter",("table: %s",entry->alias)); + DBUG_PRINT("enter",("table: %s",entry->alias.c_ptr())); save_proc_info=thd->proc_info; thd_proc_info(thd, "removing tmp table"); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index d8baab6e72c..4d717caaaea 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -816,7 +816,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) protocol->store(table_list->schema_table->table_name, system_charset_info); else - protocol->store(table_list->table->alias, system_charset_info); + protocol->store(table_list->table->alias.c_ptr(), system_charset_info); } if (table_list->view) @@ -1305,7 +1305,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, else { if (lower_case_table_names == 2) - alias= table->alias; + alias= table->alias.c_ptr(); else { alias= share->table_name.str; @@ -5661,7 +5661,7 @@ copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table) if (et.load_from_row(thd, event_table)) { - my_error(ER_CANNOT_LOAD_FROM_TABLE, MYF(0), event_table->alias); + my_error(ER_CANNOT_LOAD_FROM_TABLE, MYF(0), event_table->alias.c_ptr()); DBUG_RETURN(1); } diff --git a/sql/sql_string.h b/sql/sql_string.h index dc9122a4fcb..b154f0c1667 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -274,6 +274,14 @@ public: bool set_or_copy_aligned(const char *s, uint32 arg_length, CHARSET_INFO *cs); bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom, CHARSET_INFO *csto, uint *errors); + void move(String &s) + { + free(); + Ptr=s.Ptr ; str_length=s.str_length ; Alloced_length=s.Alloced_length; + extra_alloc= s.extra_alloc; + alloced= s.alloced; + s.alloced= 0; + } bool append(const String &s); bool append(const char *s); bool append(const char *s,uint32 arg_length); @@ -304,6 +312,7 @@ public: friend int sortcmp(const String *a,const String *b, CHARSET_INFO *cs); friend int stringcmp(const String *a,const String *b); friend String *copy_if_not_alloced(String *a,String *b,uint32 arg_length); + friend class Field; uint32 numchars(); int charpos(int i,uint32 offset=0); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 0ef18a237dd..13b2ea3ae98 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2113,7 +2113,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, { if (!foreign_key_error) my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), - wrong_tables.c_ptr()); + wrong_tables.c_ptr_safe()); else my_message(ER_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED), MYF(0)); error= 1; @@ -6955,7 +6955,7 @@ view_err: error= 0; push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), - table->alias); + table->alias.c_ptr()); } VOID(pthread_mutex_lock(&LOCK_open)); @@ -7023,7 +7023,7 @@ view_err: error= 0; push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), - table->alias); + table->alias.c_ptr()); } if (!error) diff --git a/sql/sql_test.cc b/sql/sql_test.cc index 185c0a02799..8e945d0893f 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -65,7 +65,7 @@ print_where(COND *cond,const char *info, enum_query_type query_type) str.append('\0'); DBUG_LOCK_FILE; (void) fprintf(DBUG_FILE,"\nWHERE:(%s) ",info); - (void) fputs(str.ptr(),DBUG_FILE); + (void) fputs(str.c_ptr_safe(),DBUG_FILE); (void) fputc('\n',DBUG_FILE); DBUG_UNLOCK_FILE; } @@ -157,7 +157,7 @@ void TEST_filesort(SORT_FIELD *sortorder,uint s_length) out.append('\0'); // Purify doesn't like c_ptr() DBUG_LOCK_FILE; VOID(fputs("\nInfo about FILESORT\n",DBUG_FILE)); - fprintf(DBUG_FILE,"Sortorder: %s\n",out.ptr()); + fprintf(DBUG_FILE,"Sortorder: %s\n",out.c_ptr_safe()); DBUG_UNLOCK_FILE; DBUG_VOID_RETURN; } @@ -192,7 +192,7 @@ TEST_join(JOIN *join) TABLE *form=tab->table; char key_map_buff[128]; fprintf(DBUG_FILE,"%-16.16s type: %-7s q_keys: %s refs: %d key: %d len: %d\n", - form->alias, + form->alias.c_ptr(), join_type_str[tab->type], tab->keys.print(key_map_buff), tab->ref.key_parts, @@ -216,7 +216,7 @@ TEST_join(JOIN *join) if (tab->ref.key_parts) { fprintf(DBUG_FILE, - " refs: %s\n", ref_key_parts[i].ptr()); + " refs: %s\n", ref_key_parts[i].c_ptr_safe()); } } DBUG_UNLOCK_FILE; diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index f6864add19f..d1e974a2c04 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -802,7 +802,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, stmt_query->append(stmt_definition.str, stmt_definition.length); - trg_def->str= stmt_query->c_ptr(); + trg_def->str= stmt_query->c_ptr_safe(); trg_def->length= stmt_query->length(); /* Create trigger definition file. */ @@ -1039,10 +1039,7 @@ void Table_triggers_list::set_table(TABLE *new_table) { trigger_table= new_table; for (Field **field= new_table->triggers->record1_field ; *field ; field++) - { - (*field)->table= (*field)->orig_table= new_table; - (*field)->table_name= &new_table->alias; - } + (*field)->init(new_table); } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index ccf1f5b83fe..31cb6f4f24b 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1602,7 +1602,8 @@ loop_end: do { Field_string *field= new Field_string(tbl->file->ref_length, 0, - tbl->alias, &my_charset_bin); + tbl->alias.c_ptr(), + &my_charset_bin); if (!field) DBUG_RETURN(1); field->init(tbl); diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 204100f6034..8b8b7f5c90e 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -848,7 +848,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, thd->variables.sql_mode|= sql_mode; } - DBUG_PRINT("info", ("View: %s", view_query.ptr())); + DBUG_PRINT("info", ("View: %s", view_query.c_ptr_safe())); /* fill structure */ view->source= thd->lex->create_view_select; @@ -1675,7 +1675,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) } if (non_existant_views.length()) { - my_error(ER_BAD_TABLE_ERROR, MYF(0), non_existant_views.c_ptr()); + my_error(ER_BAD_TABLE_ERROR, MYF(0), non_existant_views.c_ptr_safe()); } something_wrong= error || wrong_object_name || non_existant_views.length(); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 87a8dd278c2..e8890dde6cb 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -13111,7 +13111,7 @@ column_list_id: while ((point=iter++)) { if (!my_strcasecmp(system_charset_info, - point->column.ptr(), new_str->ptr())) + point->column.c_ptr(), new_str->c_ptr())) break; } lex->grant_tot_col|= lex->which_columns; diff --git a/sql/table.cc b/sql/table.cc index 45c1f5ab378..2b0ea97e452 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -2093,7 +2093,7 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, init_sql_alloc(&outparam->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0); - if (!(outparam->alias= my_strdup(alias, MYF(MY_WME)))) + if (outparam->alias.copy(alias, strlen(alias), table_alias_charset)) goto err; outparam->quick_keys.init(); outparam->covering_keys.init(); @@ -2430,7 +2430,7 @@ partititon_err: outparam->db_stat=0; thd->lex->view_prepare_mode= save_view_prepare_mode; free_root(&outparam->mem_root, MYF(0)); // Safe to call on bzero'd root - my_free((char*) outparam->alias, MYF(MY_ALLOW_ZERO_PTR)); + outparam->alias.free(); DBUG_RETURN (error); } @@ -2456,8 +2456,7 @@ int closefrm(register TABLE *table, bool free_share) table->file->extra(HA_EXTRA_PREPARE_FOR_DROP); error=table->file->close(); } - my_free((char*) table->alias, MYF(MY_ALLOW_ZERO_PTR)); - table->alias= 0; + table->alias.free(); if (table->expr_arena) table->expr_arena->free_items(); if (table->field) @@ -3294,7 +3293,7 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def) const TABLE_FIELD_TYPE *field_def= table_def->field; DBUG_ENTER("table_check_intact"); DBUG_PRINT("info",("table: %s expected_count: %d", - table->alias, table_def->count)); + table->alias.c_ptr(), table_def->count)); /* Whether the table definition has already been validated. */ if (table->s->table_field_def_cache == table_def) @@ -3309,14 +3308,15 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def) { report_error(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE, ER(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE), - table->alias, table_def->count, table->s->fields, + table->alias.c_ptr(), table_def->count, table->s->fields, table->s->mysql_version, MYSQL_VERSION_ID); DBUG_RETURN(TRUE); } else if (MYSQL_VERSION_ID == table->s->mysql_version) { report_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED, - ER(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED), table->alias, + ER(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED), + table->alias.c_ptr(), table_def->count, table->s->fields); DBUG_RETURN(TRUE); } @@ -3349,7 +3349,8 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def) */ report_error(0, "Incorrect definition of table %s.%s: " "expected column '%s' at position %d, found '%s'.", - table->s->db.str, table->alias, field_def->name.str, i, + table->s->db.str, table->alias.c_ptr(), + field_def->name.str, i, field->field_name); } field->sql_type(sql_type); @@ -3375,7 +3376,8 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def) { report_error(0, "Incorrect definition of table %s.%s: " "expected column '%s' at position %d to have type " - "%s, found type %s.", table->s->db.str, table->alias, + "%s, found type %s.", table->s->db.str, + table->alias.c_ptr(), field_def->name.str, i, field_def->type.str, sql_type.c_ptr_safe()); error= TRUE; @@ -3385,7 +3387,8 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def) report_error(0, "Incorrect definition of table %s.%s: " "expected the type of column '%s' at position %d " "to have character set '%s' but the type has no " - "character set.", table->s->db.str, table->alias, + "character set.", table->s->db.str, + table->alias.c_ptr(), field_def->name.str, i, field_def->cset.str); error= TRUE; } @@ -3395,7 +3398,8 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def) report_error(0, "Incorrect definition of table %s.%s: " "expected the type of column '%s' at position %d " "to have character set '%s' but found " - "character set '%s'.", table->s->db.str, table->alias, + "character set '%s'.", table->s->db.str, + table->alias.c_ptr(), field_def->name.str, i, field_def->cset.str, field->charset()->csname); error= TRUE; @@ -3406,7 +3410,7 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def) report_error(0, "Incorrect definition of table %s.%s: " "expected column '%s' at position %d to have type %s " " but the column is not found.", - table->s->db.str, table->alias, + table->s->db.str, table->alias.c_ptr(), field_def->name.str, i, field_def->type.str); error= TRUE; } diff --git a/sql/table.h b/sql/table.h index c31ab6b7471..aa4c0954a5a 100644 --- a/sql/table.h +++ b/sql/table.h @@ -720,7 +720,7 @@ struct st_table { Table_triggers_list *triggers; TABLE_LIST *pos_in_table_list;/* Element referring to this table */ ORDER *group; - const char *alias; /* alias or table name */ + String alias; /* alias or table name */ uchar *null_flags; my_bitmap_map *bitmap_init_value; MY_BITMAP def_read_set, def_write_set, def_vcol_set, tmp_set; diff --git a/storage/federatedx/ha_federatedx.cc b/storage/federatedx/ha_federatedx.cc index 2749034cba2..ecf974521e9 100644 --- a/storage/federatedx/ha_federatedx.cc +++ b/storage/federatedx/ha_federatedx.cc @@ -1583,7 +1583,7 @@ static FEDERATEDX_SHARE *get_share(const char *table_name, TABLE *table) tmp_share.table_name_length, ident_quote_char); if (!(share= (FEDERATEDX_SHARE *) memdup_root(&mem_root, (char*)&tmp_share, sizeof(*share))) || - !(share->select_query= (char*) strmake_root(&mem_root, query.ptr(), query.length() + 1))) + !(share->select_query= (char*) strmake_root(&mem_root, query.ptr(), query.length()))) goto error; share->mem_root= mem_root; @@ -3435,11 +3435,13 @@ bool ha_federatedx::get_error_message(int error, String* buf) buf->qs_append(remote_error_number); buf->append(STRING_WITH_LEN(": ")); buf->append(remote_error_buf); + /* Ensure string ends with \0 */ + (void) buf->c_ptr_safe(); remote_error_number= 0; remote_error_buf[0]= '\0'; } - DBUG_PRINT("exit", ("message: %s", buf->ptr())); + DBUG_PRINT("exit", ("message: %s", buf->c_ptr_safe())); DBUG_RETURN(FALSE); } diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index 67be01e2db9..4b4537f8312 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -1093,7 +1093,7 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) param.thd= thd; param.op_name= "check"; param.db_name= table->s->db.str; - param.table_name= table->alias; + param.table_name= table->alias.c_ptr(); param.testflag= check_opt->flags | T_CHECK | T_SILENT; param.stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method); @@ -1192,7 +1192,7 @@ int ha_maria::analyze(THD *thd, HA_CHECK_OPT * check_opt) param.thd= thd; param.op_name= "analyze"; param.db_name= table->s->db.str; - param.table_name= table->alias; + param.table_name= table->alias.c_ptr(); param.testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS | T_DONT_CHECK_CHECKSUM); param.using_global_keycache= 1; @@ -1486,7 +1486,7 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize) _ma_copy_nontrans_state_information(file); param->db_name= table->s->db.str; - param->table_name= table->alias; + param->table_name= table->alias.c_ptr(); param->tmpfile_createflag= O_RDWR | O_TRUNC; param->using_global_keycache= 1; param->thd= thd; diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 39791ff254c..583c8b5395a 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -809,7 +809,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) param.thd = thd; param.op_name = "check"; param.db_name= table->s->db.str; - param.table_name= table->alias; + param.table_name= table->alias.c_ptr(); param.testflag = check_opt->flags | T_CHECK | T_SILENT; param.stats_method= (enum_handler_stats_method)thd->variables.myisam_stats_method; @@ -902,7 +902,7 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) param.thd = thd; param.op_name= "analyze"; param.db_name= table->s->db.str; - param.table_name= table->alias; + param.table_name= table->alias.c_ptr(); param.testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS | T_DONT_CHECK_CHECKSUM); param.using_global_keycache = 1; @@ -1127,7 +1127,7 @@ int ha_myisam::repair(THD *thd, HA_CHECK ¶m, bool do_optimize) DBUG_ENTER("ha_myisam::repair"); param.db_name= table->s->db.str; - param.table_name= table->alias; + param.table_name= table->alias.c_ptr(); param.tmpfile_createflag = O_RDWR | O_TRUNC; param.using_global_keycache = 1; param.thd= thd;