Commit c4d2c4e8 authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-7964 - delete_dynamic() takes 0.12% in OLTP RO

delete_dynamic() was called 9-11x per OLTP RO query + 3x per BEGIN/COMMIT.

3 calls were performed by LEX_MASTER_INFO. Added condition to call those only
for CHANGE MASTER.

1 call was performed by lock_table_names()/Hash_set/my_hash_free(). Hash_set was
supposed to be used for DDL and LOCK TABLES to gather database names, while it
was initialized/freed for DML too. In fact Hash_set didn't do any useful job
here. Hash_set was removed and MDL requests are now added directly to the list.

The rest 5-7 calls are done by optimizer, mostly by Explain_query and friends.
Since dynamic arrays are used in most cases, they can hardly be optimized.

my_hash_free() overhead dropped 0.02 -> out of radar.
delete_dynamic() overhead dropped 0.12 -> 0.04.
parent 7cfa803d
...@@ -4174,12 +4174,6 @@ end: ...@@ -4174,12 +4174,6 @@ end:
DBUG_RETURN(error); DBUG_RETURN(error);
} }
extern "C" uchar *schema_set_get_key(const TABLE_LIST *table, size_t *length,
my_bool not_used __attribute__((unused)))
{
*length= table->db_length;
return (uchar*) table->db;
}
/** /**
Acquire upgradable (SNW, SNRW) metadata locks on tables used by Acquire upgradable (SNW, SNRW) metadata locks on tables used by
...@@ -4217,7 +4211,6 @@ lock_table_names(THD *thd, const DDL_options_st &options, ...@@ -4217,7 +4211,6 @@ lock_table_names(THD *thd, const DDL_options_st &options,
MDL_request_list mdl_requests; MDL_request_list mdl_requests;
TABLE_LIST *table; TABLE_LIST *table;
MDL_request global_request; MDL_request global_request;
Hash_set<TABLE_LIST> schema_set(schema_set_get_key);
ulong org_lock_wait_timeout= lock_wait_timeout; ulong org_lock_wait_timeout= lock_wait_timeout;
/* Check if we are using CREATE TABLE ... IF NOT EXISTS */ /* Check if we are using CREATE TABLE ... IF NOT EXISTS */
bool create_table; bool create_table;
...@@ -4243,9 +4236,17 @@ lock_table_names(THD *thd, const DDL_options_st &options, ...@@ -4243,9 +4236,17 @@ lock_table_names(THD *thd, const DDL_options_st &options,
DBUG_RETURN(true); DBUG_RETURN(true);
} }
if (! (flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK) && /* Scoped locks: Take intention exclusive locks on all involved schemas. */
schema_set.insert(table)) if (!(flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK))
DBUG_RETURN(TRUE); {
MDL_request *schema_request= new (thd->mem_root) MDL_request;
if (schema_request == NULL)
DBUG_RETURN(TRUE);
schema_request->init(MDL_key::SCHEMA, table->db, "",
MDL_INTENTION_EXCLUSIVE,
MDL_TRANSACTION);
mdl_requests.push_front(schema_request);
}
mdl_requests.push_front(&table->mdl_request); mdl_requests.push_front(&table->mdl_request);
} }
...@@ -4259,22 +4260,6 @@ lock_table_names(THD *thd, const DDL_options_st &options, ...@@ -4259,22 +4260,6 @@ lock_table_names(THD *thd, const DDL_options_st &options,
if (!(flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK)) if (!(flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK))
{ {
/*
Scoped locks: Take intention exclusive locks on all involved
schemas.
*/
Hash_set<TABLE_LIST>::Iterator it(schema_set);
while ((table= it++))
{
MDL_request *schema_request= new (thd->mem_root) MDL_request;
if (schema_request == NULL)
DBUG_RETURN(TRUE);
schema_request->init(MDL_key::SCHEMA, table->db, "",
MDL_INTENTION_EXCLUSIVE,
MDL_TRANSACTION);
mdl_requests.push_front(schema_request);
}
/* /*
Protect this statement against concurrent global read lock Protect this statement against concurrent global read lock
by acquiring global intention exclusive lock with statement by acquiring global intention exclusive lock with statement
......
...@@ -562,7 +562,7 @@ void lex_end(LEX *lex) ...@@ -562,7 +562,7 @@ void lex_end(LEX *lex)
lex->sphead= NULL; lex->sphead= NULL;
} }
lex->mi.reset(); lex->mi.reset(lex->sql_command == SQLCOM_CHANGE_MASTER);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -260,12 +260,15 @@ struct LEX_MASTER_INFO ...@@ -260,12 +260,15 @@ struct LEX_MASTER_INFO
my_init_dynamic_array(&repl_ignore_domain_ids, my_init_dynamic_array(&repl_ignore_domain_ids,
sizeof(ulong), 0, 16, MYF(0)); sizeof(ulong), 0, 16, MYF(0));
} }
void reset() void reset(bool is_change_master)
{ {
delete_dynamic(&repl_ignore_server_ids); if (unlikely(is_change_master))
/* Free all the array elements. */ {
delete_dynamic(&repl_do_domain_ids); delete_dynamic(&repl_ignore_server_ids);
delete_dynamic(&repl_ignore_domain_ids); /* Free all the array elements. */
delete_dynamic(&repl_do_domain_ids);
delete_dynamic(&repl_ignore_domain_ids);
}
host= user= password= log_file_name= ssl_key= ssl_cert= ssl_ca= host= user= password= log_file_name= ssl_key= ssl_cert= ssl_ca=
ssl_capath= ssl_cipher= relay_log_name= 0; ssl_capath= ssl_cipher= relay_log_name= 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment