From c4d2c4e844717d9d5b2c0e4f0f9cfc7cc2c24fa6 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Thu, 16 Apr 2015 18:38:26 +0400 Subject: [PATCH] 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. --- sql/sql_base.cc | 37 +++++++++++-------------------------- sql/sql_lex.cc | 2 +- sql/sql_lex.h | 13 ++++++++----- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 3baca81c2d5..262b0148dfb 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4174,12 +4174,6 @@ end: 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 @@ -4217,7 +4211,6 @@ lock_table_names(THD *thd, const DDL_options_st &options, MDL_request_list mdl_requests; TABLE_LIST *table; MDL_request global_request; - Hash_set schema_set(schema_set_get_key); ulong org_lock_wait_timeout= lock_wait_timeout; /* Check if we are using CREATE TABLE ... IF NOT EXISTS */ bool create_table; @@ -4243,9 +4236,17 @@ lock_table_names(THD *thd, const DDL_options_st &options, DBUG_RETURN(true); } - if (! (flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK) && - schema_set.insert(table)) - DBUG_RETURN(TRUE); + /* Scoped locks: Take intention exclusive locks on all involved schemas. */ + if (!(flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK)) + { + 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); } @@ -4259,22 +4260,6 @@ lock_table_names(THD *thd, const DDL_options_st &options, if (!(flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK)) { - /* - Scoped locks: Take intention exclusive locks on all involved - schemas. - */ - Hash_set::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 by acquiring global intention exclusive lock with statement diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index e5d261e02d4..775f462687c 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -562,7 +562,7 @@ void lex_end(LEX *lex) lex->sphead= NULL; } - lex->mi.reset(); + lex->mi.reset(lex->sql_command == SQLCOM_CHANGE_MASTER); DBUG_VOID_RETURN; } diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 64b07b1927d..7a149a09c1b 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -260,12 +260,15 @@ struct LEX_MASTER_INFO my_init_dynamic_array(&repl_ignore_domain_ids, sizeof(ulong), 0, 16, MYF(0)); } - void reset() + void reset(bool is_change_master) { - delete_dynamic(&repl_ignore_server_ids); - /* Free all the array elements. */ - delete_dynamic(&repl_do_domain_ids); - delete_dynamic(&repl_ignore_domain_ids); + if (unlikely(is_change_master)) + { + delete_dynamic(&repl_ignore_server_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= ssl_capath= ssl_cipher= relay_log_name= 0;