大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说PostgreSQL源码学习–更新数据#1,2,希望您对编程的造诣更进一步.
本节介绍heapam_tuple_update和table_tuple_update函数。
heapam_tuple_update函数
//src/backend/access/heap/heapam_handler.c
static 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;
}
代码100分
table_tuple_update函数
代码100分//src/include/access/tableam.h
static 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);
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/7961.html