PostgreSQL源码学习更新数据#1,2
本节介绍heapam_tuple_update和table_tuple_update函数。
heapam_tuple_update函数
//src/backend/access/heap/heapam_handler.cstatic TM_Result
heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
LockTupleMode *lockmode, bool *update_indexes)
{
bool shouldFree = true;
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
TM_Result result;
/* 设置tableoid */
slot->tts_tableOid = RelationGetRelid(relation);
tuple->t_tableOid = slot->tts_tableOid;
result = heap_update(relation, otid, tuple, cid, crosscheck, wait,
tmfd, lockmode);
/* 复制新tuple的tid到slot的tts_tid中 */
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
/* 判断新的元组是否需要索引节点(用了HOT就不需要)*/
*update_indexes = result == TM_Ok && !HeapTupleIsHeapOnly(tuple);
if (shouldFree)
pfree(tuple);
return result;
}
table_tuple_update函数
//src/include/access/tableam.hstatic inline TM_Result
table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
bool *update_indexes)
{
/* 默认的表存储引擎的话,rd_tableam赋值为heapam_methods,
其tuple_update指向的就是heapam_tuple_update函数 */
return rel->rd_tableam->tuple_update(rel, otid, slot,
cid, snapshot, crosscheck,
wait, tmfd,
lockmode, update_indexes);
}
以上是 PostgreSQL源码学习更新数据#1,2 的全部内容, 来源链接: utcz.com/z/534092.html