From b95c8ce530cbbd92b232324dc2c4376615bd1b5d Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Thu, 6 Mar 2014 16:19:12 +0400 Subject: MDEV-5675 - Performance: my_hash_sort_bin is called too often Reduced number of my_hash_sort_bin() calls from 4 to 1 per query. Reduced number of memory accesses done by my_hash_sort_bin(). Details: - let MDL subsystem use pre-calculated hash value for hash inserts and deletes - let table cache use pre-calculated MDL hash value - MDL namespace is excluded from hash value calculation, so that hash value can be used by table cache as is - hash value for MDL is calculated as resulting hash value + MDL namespace - extended hash implementation to accept user defined hash function --- sql/mdl.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'sql/mdl.h') diff --git a/sql/mdl.h b/sql/mdl.h index c7c445c75e1..6f31b46f17f 100644 --- a/sql/mdl.h +++ b/sql/mdl.h @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -347,12 +348,15 @@ public: m_ptr - 1); m_length= static_cast(strmake(m_ptr + m_db_name_length + 2, name, NAME_LEN) - m_ptr + 1); + m_hash_value= my_hash_sort(&my_charset_bin, (uchar*) m_ptr + 1, + m_length - 1); } void mdl_key_init(const MDL_key *rhs) { memcpy(m_ptr, rhs->m_ptr, rhs->m_length); m_length= rhs->m_length; m_db_name_length= rhs->m_db_name_length; + m_hash_value= rhs->m_hash_value; } bool is_equal(const MDL_key *rhs) const { @@ -392,15 +396,26 @@ public: { return & m_namespace_to_wait_state_name[(int)mdl_namespace()]; } + my_hash_value_type hash_value() const + { + return m_hash_value + mdl_namespace(); + } + my_hash_value_type tc_hash_value() const + { + return m_hash_value; + } private: uint16 m_length; uint16 m_db_name_length; + my_hash_value_type m_hash_value; char m_ptr[MAX_MDLKEY_LENGTH]; static PSI_stage_info m_namespace_to_wait_state_name[NAMESPACE_END]; private: MDL_key(const MDL_key &); /* not implemented */ MDL_key &operator=(const MDL_key &); /* not implemented */ + friend my_hash_value_type mdl_hash_function(const CHARSET_INFO *, + const uchar *, size_t); }; -- cgit v1.2.1