From da85ad798708d045e7ba1963172daf81aeb80ab9 Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 14 Aug 2020 18:56:56 +0300 Subject: [PATCH] Optimize Sql_alloc - Remove 'dummy_for_valgrind' overrun marker as this doesn't help much. The element also distorts the sizes of objects a bit, which makes it harder to calculate gain in object sizes when doing size optimizations. - Replace usage of thd_get_current_thd() with _current_thd() - Avoid one extra call indirection when using thd_get_current_thd(), which is used by Sql_alloc, by replacing it with _current_thd() --- include/thread_pool_priv.h | 1 - sql/item.cc | 2 +- sql/mysqld.cc | 6 ++++++ sql/sql_alloc.h | 12 +++--------- sql/sql_class.cc | 11 ----------- storage/rocksdb/ha_rocksdb.cc | 2 +- 6 files changed, 11 insertions(+), 23 deletions(-) diff --git a/include/thread_pool_priv.h b/include/thread_pool_priv.h index 769c4a7d97d..7690f74e020 100644 --- a/include/thread_pool_priv.h +++ b/include/thread_pool_priv.h @@ -44,7 +44,6 @@ void thd_clear_errors(THD *thd); void thd_set_thread_stack(THD *thd, char *stack_start); void thd_lock_thread_count(THD *thd); void thd_close_connection(THD *thd); -THD *thd_get_current_thd(); void thd_lock_data(THD *thd); void thd_unlock_data(THD *thd); bool thd_is_transaction_active(THD *thd); diff --git a/sql/item.cc b/sql/item.cc index 9071455afc4..438c46894d5 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -447,10 +447,10 @@ Item::Item(): name(null_clex_str), orig_name(0), is_expensive_cache(-1) { DBUG_ASSERT(my_progname == NULL); // before main() + common_flags= IS_AUTO_GENERATED_NAME; marker= 0; maybe_null= with_window_func= with_field= in_rollup= with_param= 0; fixed= 1; - null_value= 0; join_tab_idx= MAX_TABLES; } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 4000e986441..43c4fee4cbe 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -663,6 +663,12 @@ static std::atomic shutdown_user; static thread_local THD *THR_THD; +/** + Get current THD object from thread local data + + @retval The THD object for the thread, NULL if not connection thread +*/ + MYSQL_THD _current_thd() { return THR_THD; } void set_current_thd(THD *thd) { THR_THD= thd; } diff --git a/sql/sql_alloc.h b/sql/sql_alloc.h index f475ecdff73..f5d2d4e8b1a 100644 --- a/sql/sql_alloc.h +++ b/sql/sql_alloc.h @@ -18,20 +18,18 @@ #include /* alloc_root, MEM_ROOT, TRASH */ -THD *thd_get_current_thd(); - -/* mysql standard class memory allocator */ +/* MariaDB standard class memory allocator */ class Sql_alloc { public: static void *operator new(size_t size) throw () { - return thd_alloc(thd_get_current_thd(), size); + return thd_alloc(_current_thd(), size); } static void *operator new[](size_t size) throw () { - return thd_alloc(thd_get_current_thd(), size); + return thd_alloc(_current_thd(), size); } static void *operator new[](size_t size, MEM_ROOT *mem_root) throw () { return alloc_root(mem_root, size); } @@ -42,9 +40,5 @@ public: static void operator delete[](void *, MEM_ROOT *) { /* never called */ } static void operator delete[](void *ptr, size_t size) { TRASH_FREE(ptr, size); } -#ifdef HAVE_valgrind - bool dummy_for_valgrind; - inline Sql_alloc() :dummy_for_valgrind(0) {} -#endif }; #endif /* SQL_ALLOC_INCLUDED */ diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 095988b5e00..5b4eb35ea27 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -325,17 +325,6 @@ bool Foreign_key::validate(List &table_fields) ** Thread specific functions ****************************************************************************/ -/** - Get current THD object from thread local data - - @retval The THD object for the thread, NULL if not connection thread -*/ -THD *thd_get_current_thd() -{ - return current_thd; -} - - extern "C" unsigned long long thd_query_id(const MYSQL_THD thd) { return((unsigned long long)thd->query_id); diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 43d9e60aa46..c0b87871f47 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -7812,7 +7812,7 @@ int ha_rocksdb::create(const char *const name, TABLE *const table_arg, } // FOREIGN KEY isn't supported yet - THD *const thd = my_core::thd_get_current_thd(); + THD *const thd = _current_thd(); if (contains_foreign_key(thd)) { my_error(ER_NOT_SUPPORTED_YET, MYF(0), "FOREIGN KEY for the RocksDB storage engine");