-
Notifications
You must be signed in to change notification settings - Fork 505
PS-9647: MySQL Perf Improvements (readview) #5610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 8.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,6 +46,9 @@ class MVCC; | |||||||||||||
| /** Read view lists the trx ids of those transactions for which a consistent | ||||||||||||||
| read should not see the modifications to the database. */ | ||||||||||||||
|
|
||||||||||||||
| #define MAX_TOP_ACTIVE_BYTES 8192 | ||||||||||||||
| #define MAX_SHORT_ACTIVE_BYTES 65536 | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
|
|
||||||||||||||
| class ReadView { | ||||||||||||||
| /** This is similar to a std::vector but it is not a drop | ||||||||||||||
| in replacement. It is specific to ReadView. */ | ||||||||||||||
|
|
@@ -173,14 +176,33 @@ class ReadView { | |||||||||||||
|
|
||||||||||||||
| if (id >= m_low_limit_id) { | ||||||||||||||
| return (false); | ||||||||||||||
|
|
||||||||||||||
| } else if (m_ids.empty()) { | ||||||||||||||
| } else if (empty()) { | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| return (true); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const ids_t::value_type *p = m_ids.data(); | ||||||||||||||
| /* first search short bitmap */ | ||||||||||||||
| if (m_has_short_actives && id >= m_short_min_id) { | ||||||||||||||
| if (id > m_short_max_id) { | ||||||||||||||
| return false; | ||||||||||||||
| } | ||||||||||||||
| unsigned int trim_id = id & 0x7FFFF; | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| unsigned int trim_min_id = m_short_min_id & 0x7FFFF; | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| unsigned int array_index = (trim_id >> 3); | ||||||||||||||
| unsigned int array_min_index = (trim_min_id >> 3); | ||||||||||||||
| array_index = (MAX_SHORT_ACTIVE_BYTES + array_index - array_min_index) % | ||||||||||||||
| MAX_TOP_ACTIVE_BYTES; | ||||||||||||||
| unsigned int array_remainder = trim_id & (0x7); | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| int is_value_set = top_active[array_index] & (1 << (7 - array_remainder)); | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| if (is_value_set) { | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| return false; | ||||||||||||||
| } else { | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| return true; | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+196
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const ids_t::value_type *p = m_long_ids.data(); | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
|
|
||||||||||||||
| return (!std::binary_search(p, p + m_ids.size(), id)); | ||||||||||||||
| return (!std::binary_search(p, p + m_long_ids.size(), id)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
|
|
@@ -235,7 +257,18 @@ class ReadView { | |||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| @return true if there are no transaction ids in the snapshot */ | ||||||||||||||
| bool empty() const { return (m_ids.empty()); } | ||||||||||||||
| bool empty() const { | ||||||||||||||
| bool long_empty = m_long_ids.empty(); | ||||||||||||||
| if (long_empty) { | ||||||||||||||
| if (!m_has_short_actives) { | ||||||||||||||
| return true; | ||||||||||||||
| } else { | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| return false; | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+263
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| } else { | ||||||||||||||
| return false; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| Clones a read view object. The resulting read view has identical change | ||||||||||||||
|
|
@@ -264,17 +297,19 @@ class ReadView { | |||||||||||||
| fprintf(file, "Read view low limit trx n:o " TRX_ID_FMT "\n", | ||||||||||||||
| low_limit_no()); | ||||||||||||||
| print_limits(file); | ||||||||||||||
| fprintf(file, "Read view individually stored trx ids:\n"); | ||||||||||||||
| for (ulint i = 0; i < m_ids.size(); i++) | ||||||||||||||
| fprintf(file, "Read view trx id " TRX_ID_FMT "\n", m_ids.data()[i]); | ||||||||||||||
| fprintf(file, "Read view individually stored long trx ids:\n"); | ||||||||||||||
| for (ulint i = 0; i < m_long_ids.size(); i++) | ||||||||||||||
| fprintf(file, "Read view trx id " TRX_ID_FMT "\n", m_long_ids.data()[i]); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| bool is_cloned() const noexcept { return (m_cloned); } | ||||||||||||||
|
|
||||||||||||||
| private: | ||||||||||||||
| /** | ||||||||||||||
| Copy the transaction ids from the source vector */ | ||||||||||||||
| inline void copy_trx_ids(const trx_ids_t &trx_ids); | ||||||||||||||
| inline void copy_long_trx_ids(const trx_ids_t &trx_ids, | ||||||||||||||
| trx_id_t min_short_id); | ||||||||||||||
| inline void copy_short_trx_ids(); | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| Opens a read view where exactly the transactions serialized before this | ||||||||||||||
|
|
@@ -307,6 +342,7 @@ class ReadView { | |||||||||||||
| ReadView &operator=(const ReadView &); | ||||||||||||||
|
|
||||||||||||||
| private: | ||||||||||||||
| unsigned char top_active[MAX_TOP_ACTIVE_BYTES]; | ||||||||||||||
| /** The read should not see any transaction with trx id >= this | ||||||||||||||
| value. In other words, this is the "high water mark". */ | ||||||||||||||
| trx_id_t m_low_limit_id; | ||||||||||||||
|
|
@@ -322,7 +358,7 @@ class ReadView { | |||||||||||||
|
|
||||||||||||||
| /** Set of RW transactions that was active when this snapshot | ||||||||||||||
| was taken */ | ||||||||||||||
| ids_t m_ids; | ||||||||||||||
| ids_t m_long_ids; | ||||||||||||||
|
|
||||||||||||||
| /** The view does not need to see the undo logs for transactions | ||||||||||||||
| whose transaction number is strictly smaller (<) than this value: | ||||||||||||||
|
|
@@ -337,6 +373,10 @@ class ReadView { | |||||||||||||
| trx_id_t m_view_low_limit_no; | ||||||||||||||
| #endif /* UNIV_DEBUG */ | ||||||||||||||
|
|
||||||||||||||
| trx_id_t m_short_min_id; | ||||||||||||||
| trx_id_t m_short_max_id; | ||||||||||||||
| bool m_has_short_actives; | ||||||||||||||
|
|
||||||||||||||
| /** AC-NL-RO transaction view that has been "closed". */ | ||||||||||||||
| bool m_closed; | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -553,7 +553,11 @@ struct trx_sys_t { | |
| take a snapshot of these transactions whose changes are not visible to it. | ||
| We should remove transactions from the list before committing in memory and | ||
| releasing locks to ensure right order of removal and consistent snapshot. */ | ||
| trx_ids_t rw_trx_ids; | ||
| trx_ids_t long_rw_trx_ids; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| unsigned char short_rw_trx_ids_bitmap[MAX_SHORT_ACTIVE_BYTES]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| int short_rw_trx_valid_number; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| trx_id_t min_short_valid_id; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| trx_id_t max_short_valid_id; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| char pad7[ut::INNODB_CACHE_LINE_SIZE]; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macro
MAX_TOP_ACTIVE_BYTESused to declare a constant; consider using aconstexprconstant