PostgreSQL源码学习–更新数据#1,2

PostgreSQL源码学习–更新数据#1,2本节介绍heapam_tuple_update和table_tuple_update函数。 heapam_tuple_update函数 //src/backend/access/heap/heapa…

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

(0)
上一篇 2023-03-10
下一篇 2023-03-10

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注