MDEV-17491 micro optimize page_id_t further

Let us define page_id_t as a thin wrapper of uint64_t so that
the comparison operators can be simplified. This is a follow-up
to the original commit 14be81438098923e95bda6d635d638991e60116b.

The comparison operator for recv_sys.pages.emplace() turned out to be
a busy spot in a recovery benchmark. That data structure was introduced
in MDEV-19586 in commit 177a571e01e8ea949601aa1124ea86c376fd0472.
This commit is contained in:
Marko Mäkelä 2020-02-11 18:03:19 +02:00
parent f3dac59174
commit 8ccb3caafb
2 changed files with 39 additions and 73 deletions

View File

@ -2,7 +2,7 @@
Copyright (c) 1995, 2018, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2018, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2008, Google Inc. Copyright (c) 2008, Google Inc.
Copyright (c) 2013, 2019, MariaDB Corporation. Copyright (c) 2013, 2020, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described Google, Inc. Those modifications are gratefully acknowledged and are described
@ -7144,14 +7144,11 @@ buf_pool_check_no_pending_io(void)
@param[in,out] out the output stream @param[in,out] out the output stream
@param[in] page_id the page_id_t object to be printed @param[in] page_id the page_id_t object to be printed
@return the output stream */ @return the output stream */
std::ostream& std::ostream& operator<<(std::ostream &out, const page_id_t page_id)
operator<<(
std::ostream& out,
const page_id_t page_id)
{ {
out << "[page id: space=" << page_id.m_space out << "[page id: space=" << page_id.space()
<< ", page number=" << page_id.m_page_no << "]"; << ", page number=" << page_id.page_no() << "]";
return(out); return out;
} }
/** Print the given buf_pool_t object. /** Print the given buf_pool_t object.

View File

@ -1,7 +1,7 @@
/***************************************************************************** /*****************************************************************************
Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2019, MariaDB Corporation. Copyright (c) 2019, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
@ -135,80 +135,49 @@ this must be equal to srv_page_size */
/* @} */ /* @} */
/** Page identifier. */ /** Page identifier. */
class page_id_t { class page_id_t
{
public: public:
/** Constructor from (space, page_no).
@param[in] space tablespace id
@param[in] page_no page number */
page_id_t(ulint space, ulint page_no) : m_id(uint64_t{space} << 32 | page_no)
{
ut_ad(space <= 0xFFFFFFFFU);
ut_ad(page_no <= 0xFFFFFFFFU);
}
/** Constructor from (space, page_no). bool operator==(const page_id_t& rhs) const { return m_id == rhs.m_id; }
@param[in] space tablespace id bool operator!=(const page_id_t& rhs) const { return m_id != rhs.m_id; }
@param[in] page_no page number */
page_id_t(ulint space, ulint page_no)
: m_space(uint32_t(space)), m_page_no(uint32(page_no))
{
ut_ad(space <= 0xFFFFFFFFU);
ut_ad(page_no <= 0xFFFFFFFFU);
}
bool operator==(const page_id_t& rhs) const bool operator<(const page_id_t& rhs) const { return m_id < rhs.m_id; }
{
return m_space == rhs.m_space && m_page_no == rhs.m_page_no;
}
bool operator!=(const page_id_t& rhs) const { return !(*this == rhs); }
bool operator<(const page_id_t& rhs) const /** Retrieve the tablespace id.
{ @return tablespace id */
if (m_space == rhs.m_space) { uint32_t space() const { return static_cast<uint32_t>(m_id >> 32); }
return m_page_no < rhs.m_page_no;
}
return m_space < rhs.m_space; /** Retrieve the page number.
} @return page number */
uint32_t page_no() const { return static_cast<uint32_t>(m_id); }
/** Retrieve the tablespace id. /** Retrieve the fold value.
@return tablespace id */ @return fold value */
uint32_t space() const { return m_space; } ulint fold() const { return (space() << 20) + space() + page_no(); }
/** Retrieve the page number. /** Reset the page number only.
@return page number */ @param[in] page_no page number */
uint32_t page_no() const { return m_page_no; } void set_page_no(ulint page_no)
{
ut_ad(page_no <= 0xFFFFFFFFU);
m_id= (m_id & ~uint64_t{0} << 32) | page_no;
}
/** Retrieve the fold value. /** Set the FIL_NULL for the space and page_no */
@return fold value */ void set_corrupt_id() { m_id= ~uint64_t{0}; }
ulint fold() const { return (m_space << 20) + m_space + m_page_no; }
/** Reset the page number only.
@param[in] page_no page number */
void set_page_no(ulint page_no)
{
m_page_no = uint32_t(page_no);
ut_ad(page_no <= 0xFFFFFFFFU);
}
/** Set the FIL_NULL for the space and page_no */
void set_corrupt_id()
{
m_space = m_page_no = ULINT32_UNDEFINED;
}
private: private:
/** The page identifier */
/** Tablespace id. */ uint64_t m_id;
uint32_t m_space;
/** Page number. */
uint32_t m_page_no;
/** Declare the overloaded global operator<< as a friend of this
class. Refer to the global declaration for further details. Print
the given page_id_t object.
@param[in,out] out the output stream
@param[in] page_id the page_id_t object to be printed
@return the output stream */
friend
std::ostream&
operator<<(
std::ostream& out,
const page_id_t page_id);
}; };
#ifndef UNIV_INNOCHECKSUM #ifndef UNIV_INNOCHECKSUM