Two cases, one XMIN uncommitted transactions, xmin is a transaction has been submitted.
For xmin uncommitted transactions that just insert the current tuple has not been submitted to:
1) the tuple is not legitimate, ie bad tuple returned HEAPTUPLE_DEAD
2) The tuple is generated by the current transaction: At this point the transaction is not recorded in this or just delete locked or delete abort a delete it, then return HAPTUPLE_INSERT_IN_PROGRESS; if the record has been deleted, then returns HEAPTUPLE_DELETE_IN_PROGRESS
3) the tuple is generated by other transactions, tuple header mark uncommitted: HEAP_INSERT_IN_POGRESS
4) the tuple is generated other transactions, clog display xmin submitted: tuple is marked as head HEAP_XMIN_COMMITTED.
5) In other cases, this xmin transaction does not submit, abort or damaged: return HEAPTUPLE_DEAD
for the transaction xmin has been submitted, that the current tuple insert has been submitted:
1) Xmax did not submit returns HEAPTUPLE_LIVE
2) tuple only be locked with: xmax uncommitted: return HEAPTUPLE_LIVE
3) delete tuple is: return HEAPTUPLE_DELETE_IN_PROGRESS
4) clog found in xmax submitted: mark tuple head HEAP_XMAX_COMMITTED
5) other circumstances delete does not submit: HEAPTUPLE_LIVE
6) the rest of the case, tuple.t_xmax> = OldestXmin expressed Affairs also see the value of insert: HEAPTUPLE_RECENTLY_DEAD
7) other cases have been submitted XMAX: Return HEAPTUPLE_DEAD
HeapTupleSatisfiesVacuum
{
HeapTupleHeader tuple = htup->t_data;
if (!HeapTupleHeaderXminCommitted(tuple))//未提交
{
if (HeapTupleHeaderXminInvalid(tuple))//元组不合法,坏的元组
return HEAPTUPLE_DEAD;
else if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmin(tuple)))
{//当前事务产生的元组
if (tuple->t_infomask & HEAP_XMAX_INVALID)//未被删除,当前事务正在insert
return HEAPTUPLE_INSERT_IN_PROGRESS;
//元组被锁住,未被删除 或者
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask) || HeapTupleHeaderIsOnlyLocked(tuple))
return HEAPTUPLE_INSERT_IN_PROGRESS;
//insert后当前事务又删除
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetUpdateXid(tuple)))
return HEAPTUPLE_DELETE_IN_PROGRESS;
//delete的子事务被abort,即insert正在进行
return HEAPTUPLE_INSERT_IN_PROGRESS;
}
else if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmin(tuple)))
{//其他事务正在insert
return HEAPTUPLE_INSERT_IN_PROGRESS;
}//从clog中读取tuple的事务状态,为提交则标记提交
else if (TransactionIdDidCommit(HeapTupleHeaderGetRawXmin(tuple)))
SetHintBits(tuple, buffer, HEAP_XMIN_COMMITTED,HeapTupleHeaderGetRawXmin(tuple));
else
{
//真的tuple未提交、abort或者损坏
SetHintBits(tuple, buffer, HEAP_XMIN_INVALID,InvalidTransactionId);
return HEAPTUPLE_DEAD;
}
//此时,xmin已提交了。
}
/*
* Okay, the inserter committed, so it was good at some point. Now what
* about the deleting transaction?
*/
if (tuple->t_infomask & HEAP_XMAX_INVALID)
return HEAPTUPLE_LIVE;//未被删除则该记录是活的
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
{//只是锁住,未进行delete
if (!(tuple->t_infomask & HEAP_XMAX_COMMITTED))
{//delete事务未提交
if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmax(tuple)))
return HEAPTUPLE_LIVE;
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,InvalidTransactionId);
}
return HEAPTUPLE_LIVE;
}
//delete未提交
if (!(tuple->t_infomask & HEAP_XMAX_COMMITTED))
{
if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmax(tuple)))
return HEAPTUPLE_DELETE_IN_PROGRESS;//delete正在进行
else if (TransactionIdDidCommit(HeapTupleHeaderGetRawXmax(tuple)))//从clog中检查delete提交了
SetHintBits(tuple, buffer, HEAP_XMAX_COMMITTED,HeapTupleHeaderGetRawXmax(tuple));
else
{
//真的未提交、abort或者损坏
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,InvalidTransactionId);
return HEAPTUPLE_LIVE;
}
//此时delete已提交
}
//有事务还可能看到他
//tuple->t_choice.t_heap.t_xmax >= OldestXmin
if (!TransactionIdPrecedes(HeapTupleHeaderGetRawXmax(tuple), OldestXmin))
return HEAPTUPLE_RECENTLY_DEAD;
/* Otherwise, it's dead and removable */
return HEAPTUPLE_DEAD;
}