row_search_mvcc(...)//获取记录
{...
/* We are
ready to look at a possible new index entry in the result
set: the cursor is now placed on a user
record */
if (prebuilt->select_lock_type
!= LOCK_NONE) {//如果需要加锁,则加锁的语义来自上层
...
} else {//不需要加锁
/*
This is a non-locking consistent read: if necessary, fetch a previous version
of the record */
if
(trx->isolation_level == TRX_ISO_READ_UNCOMMITTED)
{ //如果是读未提交,则什么也不做
/* Do nothing: we let a non-locking SELECT read the latest version of
the record */
}
else if (index == clust_index) { //否则,才需要检查“rec”是否满足可见性,不满足则找出满足可见性要求的旧版本
//所以,读未提交什么也不做,就是在说当前的rec是符合的,能被读到的,根本不用到回滚段找出旧版本(所得即所“可见”)
/* Fetch a previous version of
the row if the current one is not visible in the snapshot;
if we have a very high force recovery level
set, we try to avoid crashes by skipping this lookup */
if (srv_force_recovery < 5
&& !lock_clust_rec_cons_read_sees(rec,
index, offsets, trx_get_read_view(trx))) {
rec_t*old_vers;
/* The following call returns ‘offsets‘ associated with ‘old_vers‘ */
err = row_sel_build_prev_vers_for_mysql(trx->read_view,
clust_index, prebuilt, rec, &offsets, &heap,
&old_vers,
need_vrow ? &vrow : NULL, &mtr);
if (err != DB_SUCCESS) {
goto lock_wait_or_error;
}
if (old_vers == NULL) {
/* The row did not exist yet in the read view */
goto next_rec;
}
rec = old_vers;
}
}
else {
/* We are looking into a non-clustered
index, and to get the right version of the record we
have to look also into the clustered index:
this is necessary, because we can only get the undo
information via the clustered index record.
*/
...
}
}
}
...}