mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
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
This commit is contained in:
@ -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 &&
|
||||
|
Reference in New Issue
Block a user