diff options
author | Alexander Barkov <bar@mariadb.com> | 2018-11-14 13:55:05 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2018-11-14 13:56:18 +0400 |
commit | 45769429d9a3bfa37ead21aa0d36214f980a00d7 (patch) | |
tree | 4d5f351088880b443b11f13f81209fc433c1784c /sql/sql_type_int.h | |
parent | f718477714aedd9fd598990169db6f512c9cae64 (diff) | |
download | mariadb-git-45769429d9a3bfa37ead21aa0d36214f980a00d7.tar.gz |
MDEV-17698 MEMORY engine performance regression
Diffstat (limited to 'sql/sql_type_int.h')
-rw-r--r-- | sql/sql_type_int.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sql/sql_type_int.h b/sql/sql_type_int.h index 1eda5651df5..7433bd5249f 100644 --- a/sql/sql_type_int.h +++ b/sql/sql_type_int.h @@ -24,12 +24,25 @@ class Longlong_hybrid protected: longlong m_value; bool m_unsigned; + int cmp_signed(const Longlong_hybrid& other) const + { + return m_value < other.m_value ? -1 : m_value == other.m_value ? 0 : 1; + } + int cmp_unsigned(const Longlong_hybrid& other) const + { + return (ulonglong) m_value < (ulonglong) other.m_value ? -1 : + m_value == other.m_value ? 0 : 1; + } public: Longlong_hybrid(longlong nr, bool unsigned_flag) :m_value(nr), m_unsigned(unsigned_flag) { } longlong value() const { return m_value; } bool is_unsigned() const { return m_unsigned; } + bool is_unsigned_outside_of_signed_range() const + { + return m_unsigned && ((ulonglong) m_value) > (ulonglong) LONGLONG_MAX; + } bool neg() const { return m_value < 0 && !m_unsigned; } ulonglong abs() const { @@ -39,6 +52,21 @@ public: return ((ulonglong) LONGLONG_MAX) + 1; return m_value < 0 ? -m_value : m_value; } + int cmp(const Longlong_hybrid& other) const + { + if (m_unsigned == other.m_unsigned) + return m_unsigned ? cmp_unsigned(other) : cmp_signed(other); + if (is_unsigned_outside_of_signed_range()) + return 1; + if (other.is_unsigned_outside_of_signed_range()) + return -1; + /* + The unsigned argument is in the range 0..LONGLONG_MAX. + The signed argument is in the range LONGLONG_MIN..LONGLONG_MAX. + Safe to compare as signed. + */ + return cmp_signed(other); + } }; #endif // SQL_TYPE_INT_INCLUDED |