Search code examples
mysqlinnodbmvcc

MySQL ReadView bug?


This is a question about code internal to the InnoDB storage engine in MySQL 8.0 source.

In the 'ReadView::prepare' method (file read/read0read.c):

m_up_limit_id = !m_ids.empty() ? m_ids.front() : m_low_limit_id;

in the 'changes_visible' method (file include/read0types.h):

if (id < m_up_limit_id || id == m_creator_trx_id) {
  return (true);
}
...
if (id >= m_low_limit_id) {
 return (false);
} else if (m_ids.empty()) {
  return (true);
}

The logic of m_ids.empty() is useless, id cannot be less than m_up_limit_id and greater than or equal to m_low_limit_id, because m_ids.empty(), then m_up_limit_id == m_low_limit_id, I don't know if my understanding is accurate, I hope to get an answer


Solution

  • I think the call to empty() is important. The set of active transactions might be empty. In other words, the ReadView is prepared at a time when there are no active transactions.

    If that is the case, the front() function cannot return a valid transaction id. The code in front() throws a debug assertion if it is called on an empty set.