文章详情

短信预约信息系统项目管理师 报名、考试、查分时间动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

PostgreSQL源码学习--插入数据#6

2020-08-14 17:13

关注

PostgreSQL源码学习--插入数据#6

本节介绍ExecModifyTable函数。

typedef struct ModifyTableState
{
	PlanState	ps;				
	CmdType		operation;		
	bool		canSetTag;		
	bool		mt_done;		
	PlanState **mt_plans;		
	int			mt_nplans;		
	int			mt_whichplan;	
	TupleTableSlot **mt_scans;	
	ResultRelInfo *resultRelInfo;	
	ResultRelInfo *rootResultRelInfo;	
	List	  **mt_arowmarks;	
	EPQState	mt_epqstate;	
	bool		fireBSTriggers; 
	List	   *mt_excludedtlist;	

	
	TupleTableSlot *mt_root_tuple_slot;

	
	struct PartitionTupleRouting *mt_partition_tuple_routing;

	
	struct TransitionCaptureState *mt_transition_capture;

	
	struct TransitionCaptureState *mt_oc_transition_capture;

	
	TupleConversionMap **mt_per_subplan_tupconv_maps;
} ModifyTableState;
static TupleTableSlot *
ExecModifyTable(PlanState *pstate);

CHECK_FOR_INTERRUPTS();


if (estate->es_epq_active != NULL)
	elog(ERROR, "ModifyTable should not be called during EvalPlanQual");


if (node->mt_done)
	return NULL;


if (node->fireBSTriggers)
{
	fireBSTriggers(node);
	node->fireBSTriggers = false;
}


resultRelInfo = node->resultRelInfo + node->mt_whichplan;
subplanstate = node->mt_plans[node->mt_whichplan];
junkfilter = resultRelInfo->ri_junkFilter;


saved_resultRelInfo = estate->es_result_relation_info;
estate->es_result_relation_info = resultRelInfo;


for (;;)
{
	
	ResetPerTupleExprContext(estate);
	
	
	if (pstate->ps_ExprContext)
		ResetExprContext(pstate->ps_ExprContext);
	
	
	planSlot = ExecProcNode(subplanstate);
	
	if (TupIsNull(planSlot))
	{
		
		node->mt_whichplan++;
		if (node->mt_whichplan < node->mt_nplans)
		{
			resultRelInfo++;
			subplanstate = node->mt_plans[node->mt_whichplan];
			junkfilter = resultRelInfo->ri_junkFilter;
			estate->es_result_relation_info = resultRelInfo;
			
			EvalPlanQualSetPlan(&node->mt_epqstate, subplanstate->plan,
							node->mt_arowmarks[node->mt_whichplan]);
			
			if (node->mt_transition_capture != NULL)
			{
				node->mt_transition_capture->tcs_map =
					tupconv_map_for_subplan(node, node->mt_whichplan);
			}
			if (node->mt_oc_transition_capture != NULL)
			{
				node->mt_oc_transition_capture->tcs_map =
					tupconv_map_for_subplan(node, node->mt_whichplan);
			}
			continue;
		}
		else
			break;
	}
	
	
	if (resultRelInfo->ri_usesFdwDirectModify)
	{
		Assert(resultRelInfo->ri_projectReturning);

		slot = ExecProcessReturning(resultRelInfo, NULL, planSlot);

		estate->es_result_relation_info = saved_resultRelInfo;
		return slot;
	}
	
	
	EvalPlanQualSetSlot(&node->mt_epqstate, planSlot);
	slot = planSlot;
	
	tupleid = NULL;
	oldtuple = NULL;
	
	if (junkfilter != NULL)
	{
		
		if (operation == CMD_UPDATE || operation == CMD_DELETE)
		{
			relkind = resultRelInfo->ri_RelationDesc->rd_rel->relkind;
			if (relkind == RELKIND_RELATION || relkind == RELKIND_MATVIEW)
			{
				datum = ExecGetJunkAttribute(slot,
								 junkfilter->jf_junkAttNo,
								 &isNull);
				
				if (isNull)
					elog(ERROR, "ctid is NULL");

				tupleid = (ItemPointer) DatumGetPointer(datum);
				tuple_ctid = *tupleid;	
				tupleid = &tuple_ctid;
			}
			
			
			else if (AttributeNumberIsValid(junkfilter->jf_junkAttNo))
			{
				datum = ExecGetJunkAttribute(slot,
								 junkfilter->jf_junkAttNo,
								 &isNull);
				
				if (isNull)
					elog(ERROR, "wholerow is NULL");

				oldtupdata.t_data = DatumGetHeapTupleHeader(datum);
				oldtupdata.t_len =
					HeapTupleHeaderGetDatumLength(oldtupdata.t_data);
				ItemPointerSetInvalid(&(oldtupdata.t_self));
				
				oldtupdata.t_tableOid =
					(relkind == RELKIND_VIEW) ? InvalidOid :
					RelationGetRelid(resultRelInfo->ri_RelationDesc);

				oldtuple = &oldtupdata;
			}
			else
				Assert(relkind == RELKIND_FOREIGN_TABLE);
		}
		
		
		if (operation != CMD_DELETE)
			slot = ExecFilterJunk(junkfilter, slot);
	}
	
	
	switch (operation)
	{
		case CMD_INSERT:
			
			if (proute)
				slot = ExecPrepareTupleRouting(node, estate, proute,
									   resultRelInfo, slot);
			slot = ExecInsert(node, slot, planSlot,
						  estate, node->canSetTag);
			
			if (proute)
				estate->es_result_relation_info = resultRelInfo;
			break;
		case CMD_UPDATE:
			slot = ExecUpdate(node, tupleid, oldtuple, slot, planSlot,
							  &node->mt_epqstate, estate, node->canSetTag);
			break;
		case CMD_DELETE:
			slot = ExecDelete(node, tupleid, oldtuple, planSlot,
							  &node->mt_epqstate, estate,
							  true, node->canSetTag,
							  false  , NULL, NULL);
			break;
		default:
			elog(ERROR, "unknown operation");
			break;
	}
	
	
	if (slot)
	{
		estate->es_result_relation_info = saved_resultRelInfo;
		return slot;
	}
}


	estate->es_result_relation_info = saved_resultRelInfo;


fireASTriggers(node);

node->mt_done = true;

return NULL;
阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯