⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 executils.c

📁 关系型数据库 Postgresql 6.5.2
💻 C
📖 第 1 页 / 共 3 页
字号:
/*------------------------------------------------------------------------- * * execUtils.c *	  miscellanious executor utility routines * * Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION *	  $Header: /usr/local/cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.45 1999/05/25 16:08:39 momjian Exp $ * *------------------------------------------------------------------------- *//* * INTERFACE ROUTINES *		ExecAssignNodeBaseInfo	\ *		ExecAssignDebugHooks	 >	preforms misc work done in all the *		ExecAssignExprContext	/	init node routines. * *		ExecGetTypeInfo			  |  old execCStructs interface *		ExecMakeTypeInfo		  |  code from the version 1 *		ExecOrderTypeInfo		  |  lisp system.  These should *		ExecSetTypeInfo			  |  go away or be updated soon. *		ExecFreeTypeInfo		  |  -cim 11/1/89 *		ExecTupleAttributes		/ * *		QueryDescGetTypeInfo - moved here from main.c *								am not sure what uses it -cim 10/12/89 * *		ExecGetIndexKeyInfo		\ *		ExecOpenIndices			 | referenced by InitPlan, EndPlan, *		ExecCloseIndices		 | ExecAppend, ExecReplace *		ExecFormIndexTuple		 | *		ExecInsertIndexTuple	/ * *	 NOTES *		This file has traditionally been the place to stick misc. *		executor support stuff that doesn't really go anyplace else. * */#include "postgres.h"#include "access/genam.h"#include "access/heapam.h"#include "access/itup.h"#include "catalog/catname.h"#include "catalog/index.h"#include "catalog/pg_type.h"#include "commands/command.h"#include "executor/execdebug.h"#include "executor/executor.h"#include "fmgr.h"#include "optimizer/clauses.h"#include "parser/parsetree.h"#include "utils/lsyscache.h"#include "utils/mcxt.h"static void ExecGetIndexKeyInfo(Form_pg_index indexTuple, int *numAttsOutP,					AttrNumber **attsOutP, FuncIndexInfoPtr fInfoP);/* ---------------------------------------------------------------- *		global counters for number of tuples processed, retrieved, *		appended, replaced, deleted. * ---------------------------------------------------------------- */int			NTupleProcessed;int			NTupleRetrieved;int			NTupleReplaced;int			NTupleAppended;int			NTupleDeleted;int			NIndexTupleInserted;extern int	NIndexTupleProcessed;		/* have to be defined in the										 * access method level so that the										 * cinterface.a will link ok. *//* ---------------------------------------------------------------- *						statistic functions * ---------------------------------------------------------------- *//* ---------------------------------------------------------------- *		ResetTupleCount * ---------------------------------------------------------------- */#ifdef NOT_USEDvoidResetTupleCount(void){	NTupleProcessed = 0;	NTupleRetrieved = 0;	NTupleAppended = 0;	NTupleDeleted = 0;	NTupleReplaced = 0;	NIndexTupleProcessed = 0;}#endif/* ---------------------------------------------------------------- *		PrintTupleCount * ---------------------------------------------------------------- */#ifdef NOT_USEDvoidDisplayTupleCount(FILE *statfp){	if (NTupleProcessed > 0)		fprintf(statfp, "!\t%d tuple%s processed, ", NTupleProcessed,				(NTupleProcessed == 1) ? "" : "s");	else	{		fprintf(statfp, "!\tno tuples processed.\n");		return;	}	if (NIndexTupleProcessed > 0)		fprintf(statfp, "%d indextuple%s processed, ", NIndexTupleProcessed,				(NIndexTupleProcessed == 1) ? "" : "s");	if (NIndexTupleInserted > 0)		fprintf(statfp, "%d indextuple%s inserted, ", NIndexTupleInserted,				(NIndexTupleInserted == 1) ? "" : "s");	if (NTupleRetrieved > 0)		fprintf(statfp, "%d tuple%s retrieved. ", NTupleRetrieved,				(NTupleRetrieved == 1) ? "" : "s");	if (NTupleAppended > 0)		fprintf(statfp, "%d tuple%s appended. ", NTupleAppended,				(NTupleAppended == 1) ? "" : "s");	if (NTupleDeleted > 0)		fprintf(statfp, "%d tuple%s deleted. ", NTupleDeleted,				(NTupleDeleted == 1) ? "" : "s");	if (NTupleReplaced > 0)		fprintf(statfp, "%d tuple%s replaced. ", NTupleReplaced,				(NTupleReplaced == 1) ? "" : "s");	fprintf(statfp, "\n");}#endif/* ---------------------------------------------------------------- *				 miscellanious init node support functions * *		ExecAssignNodeBaseInfo	- assigns the baseid field of the node *		ExecAssignDebugHooks	- assigns the node's debugging hooks *		ExecAssignExprContext	- assigns the node's expression context * ---------------------------------------------------------------- *//* ---------------- *		ExecAssignNodeBaseInfo * *		as it says, this assigns the baseid field of the node and *		increments the counter in the estate.  In addition, it initializes *		the base_parent field of the basenode. * ---------------- */voidExecAssignNodeBaseInfo(EState *estate, CommonState *cstate, Plan *parent){	int			baseId;	baseId = estate->es_BaseId;	cstate->cs_base_id = baseId;	estate->es_BaseId = baseId + 1;}/* ---------------- *		ExecAssignExprContext * *		This initializes the ExprContext field.  It is only necessary *		to do this for nodes which use ExecQual or ExecTargetList *		because those routines depend on econtext.	Other nodes which *		dont have to evaluate expressions don't need to do this. * ---------------- */voidExecAssignExprContext(EState *estate, CommonState *commonstate){	ExprContext *econtext;	econtext = makeNode(ExprContext);	econtext->ecxt_scantuple = NULL;	/* scan tuple slot */	econtext->ecxt_innertuple = NULL;	/* inner tuple slot */	econtext->ecxt_outertuple = NULL;	/* outer tuple slot */	econtext->ecxt_relation = NULL;		/* relation */	econtext->ecxt_relid = 0;	/* relid */	econtext->ecxt_param_list_info = estate->es_param_list_info;	econtext->ecxt_param_exec_vals = estate->es_param_exec_vals;	econtext->ecxt_range_table = estate->es_range_table;		/* range table */	commonstate->cs_ExprContext = econtext;}/* ---------------------------------------------------------------- *		Result slot tuple type and ProjectionInfo support * ---------------------------------------------------------------- *//* ---------------- *		ExecAssignResultType * ---------------- */voidExecAssignResultType(CommonState *commonstate,					 TupleDesc tupDesc){	TupleTableSlot *slot;	slot = commonstate->cs_ResultTupleSlot;	slot->ttc_tupleDescriptor = tupDesc;}/* ---------------- *		ExecAssignResultTypeFromOuterPlan * ---------------- */voidExecAssignResultTypeFromOuterPlan(Plan *node, CommonState *commonstate){	Plan	   *outerPlan;	TupleDesc	tupDesc;	outerPlan = outerPlan(node);	tupDesc = ExecGetTupType(outerPlan);	ExecAssignResultType(commonstate, tupDesc);}/* ---------------- *		ExecAssignResultTypeFromTL * ---------------- */voidExecAssignResultTypeFromTL(Plan *node, CommonState *commonstate){	List	   *targetList;	int			i;	int			len;	List	   *tl;	TargetEntry *tle;	List	   *fjtl;	TupleDesc	origTupDesc;	targetList = node->targetlist;	origTupDesc = ExecTypeFromTL(targetList);	len = ExecTargetListLength(targetList);	fjtl = NIL;	tl = targetList;	i = 0;	while (tl != NIL || fjtl != NIL)	{		if (fjtl != NIL)		{			tle = lfirst(fjtl);			fjtl = lnext(fjtl);		}		else		{			tle = lfirst(tl);			tl = lnext(tl);		}#ifdef SETS_FIXED		if (!tl_is_resdom(tle))		{			Fjoin	   *fj = (Fjoin *) lfirst(tle);			/* it is a FJoin */			fjtl = lnext(tle);			tle = fj->fj_innerNode;		}#endif		i++;	}	if (len > 0)	{		ExecAssignResultType(commonstate,							 origTupDesc);	}	else		ExecAssignResultType(commonstate,							 (TupleDesc) NULL);}/* ---------------- *		ExecGetResultType * ---------------- */TupleDescExecGetResultType(CommonState *commonstate){	TupleTableSlot *slot = commonstate->cs_ResultTupleSlot;	return slot->ttc_tupleDescriptor;}/* ---------------- *		ExecFreeResultType * ---------------- */#ifdef NOT_USEDvoidExecFreeResultType(CommonState *commonstate){	TupleTableSlot *slot;	TupleDesc	tupType;	slot = commonstate->cs_ResultTupleSlot;	tupType = slot->ttc_tupleDescriptor;	ExecFreeTypeInfo(tupType);}#endif/* ---------------- *		ExecAssignProjectionInfo		  forms the projection information from the node's targetlist * ---------------- */voidExecAssignProjectionInfo(Plan *node, CommonState *commonstate){	ProjectionInfo *projInfo;	List	   *targetList;	int			len;	targetList = node->targetlist;	len = ExecTargetListLength(targetList);	projInfo = makeNode(ProjectionInfo);	projInfo->pi_targetlist = targetList;	projInfo->pi_len = len;	projInfo->pi_tupValue = (len <= 0) ? NULL : (Datum *) palloc(sizeof(Datum) * len);	projInfo->pi_exprContext = commonstate->cs_ExprContext;	projInfo->pi_slot = commonstate->cs_ResultTupleSlot;	commonstate->cs_ProjInfo = projInfo;}/* ---------------- *		ExecFreeProjectionInfo * ---------------- */voidExecFreeProjectionInfo(CommonState *commonstate){	ProjectionInfo *projInfo;	/* ----------------	 *	get projection info.  if NULL then this node has	 *	none so we just return.	 * ----------------	 */	projInfo = commonstate->cs_ProjInfo;	if (projInfo == NULL)		return;	/* ----------------	 *	clean up memory used.	 * ----------------	 */	if (projInfo->pi_tupValue != NULL)		pfree(projInfo->pi_tupValue);	pfree(projInfo);	commonstate->cs_ProjInfo = NULL;}/* ---------------- *		ExecFreeExprContext * ---------------- */voidExecFreeExprContext(CommonState *commonstate){	ExprContext *econtext;	/* ----------------	 *	get expression context.  if NULL then this node has	 *	none so we just return.	 * ----------------	 */	econtext = commonstate->cs_ExprContext;	if (econtext == NULL)		return;	/* ----------------	 *	clean up memory used.	 * ----------------	 */	pfree(econtext);	commonstate->cs_ExprContext = NULL;}/* ---------------- *		ExecFreeTypeInfo * ---------------- */voidExecFreeTypeInfo(CommonState *commonstate){	TupleDesc	tupDesc;	tupDesc = commonstate->cs_ResultTupleSlot->ttc_tupleDescriptor;	if (tupDesc == NULL)		return;	/* ----------------	 *	clean up memory used.	 * ----------------	 */	FreeTupleDesc(tupDesc);	commonstate->cs_ResultTupleSlot->ttc_tupleDescriptor = NULL;}/* ----------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -