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

📄 copyfuncs.c

📁 关系型数据库 Postgresql 6.5.2
💻 C
📖 第 1 页 / 共 3 页
字号:
/*------------------------------------------------------------------------- * * copyfuncs.c *	  Copy functions for Postgres tree nodes. * * Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION *	  $Header: /usr/local/cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.82 1999/05/25 22:41:11 momjian Exp $ * *------------------------------------------------------------------------- */#include <stdio.h>#include <string.h>#include "postgres.h"#include "nodes/pg_list.h"#include "nodes/execnodes.h"#include "nodes/plannodes.h"#include "nodes/parsenodes.h"#include "nodes/primnodes.h"#include "nodes/relation.h"#include "utils/syscache.h"#include "utils/builtins.h"		/* for namecpy */#include "utils/elog.h"#include "utils/palloc.h"#include "catalog/pg_type.h"#include "storage/lmgr.h"#include "optimizer/planmain.h"#include "optimizer/subselect.h"/* * listCopy *	  this copy function only copies the "lcons-cells" of the list but not *	  its contents. (good for list of pointers as well as list of integers). */List *listCopy(List *list){	List	   *newlist = NIL;	List	   *l,			   *nl = NIL;	foreach(l, list)	{		if (newlist == NIL)			newlist = nl = lcons(lfirst(l), NIL);		else		{			lnext(nl) = lcons(lfirst(l), NIL);			nl = lnext(nl);		}	}	return newlist;}/* * Node_Copy *	  a macro to simplify calling of copyObject on the specified field */#define Node_Copy(from, newnode, field) \	newnode->field = copyObject(from->field)/* **************************************************************** *					 plannodes.h copy functions * **************************************************************** *//* ---------------- *		CopyPlanFields * *		This function copies the fields of the Plan node.  It is used by *		all the copy functions for classes which inherit from Plan. * ---------------- */static voidCopyPlanFields(Plan *from, Plan *newnode){	newnode->cost = from->cost;	newnode->plan_size = from->plan_size;	newnode->plan_width = from->plan_width;	newnode->plan_tupperpage = from->plan_tupperpage;	newnode->targetlist = copyObject(from->targetlist);	newnode->qual = copyObject(from->qual);	newnode->lefttree = copyObject(from->lefttree);	newnode->righttree = copyObject(from->righttree);	newnode->extParam = listCopy(from->extParam);	newnode->locParam = listCopy(from->locParam);	newnode->chgParam = listCopy(from->chgParam);	Node_Copy(from, newnode, initPlan);	if (from->subPlan != NULL)		newnode->subPlan = SS_pull_subplan((Node *) newnode->qual);	else		newnode->subPlan = NULL;	newnode->nParamExec = from->nParamExec;}/* ---------------- *		_copyPlan * ---------------- */static Plan *_copyPlan(Plan *from){	Plan	   *newnode = makeNode(Plan);	/* ----------------	 *	copy the node superclass fields	 * ----------------	 */	CopyPlanFields(from, newnode);	return newnode;}/* ---------------- *		_copyResult * ---------------- */static Result *_copyResult(Result *from){	Result	   *newnode = makeNode(Result);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	/* ----------------	 *	copy remainder of node	 * ----------------	 */	Node_Copy(from, newnode, resconstantqual);	/*	 * We must add subplans in resconstantqual to the new plan's subPlan	 * list	 */	newnode->plan.subPlan = nconc(newnode->plan.subPlan,							  SS_pull_subplan(newnode->resconstantqual));	return newnode;}/* ---------------- *		_copyAppend * ---------------- */static Append *_copyAppend(Append *from){	Append	   *newnode = makeNode(Append);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	/* ----------------	 *	copy remainder of node	 * ----------------	 */	Node_Copy(from, newnode, appendplans);	Node_Copy(from, newnode, unionrtables);	newnode->inheritrelid = from->inheritrelid;	Node_Copy(from, newnode, inheritrtable);	return newnode;}/* ---------------- *		CopyScanFields * *		This function copies the fields of the Scan node.  It is used by *		all the copy functions for classes which inherit from Scan. * ---------------- */static voidCopyScanFields(Scan *from, Scan *newnode){	newnode->scanrelid = from->scanrelid;	return;}/* ---------------- *		_copyScan * ---------------- */static Scan *_copyScan(Scan *from){	Scan	   *newnode = makeNode(Scan);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyScanFields((Scan *) from, (Scan *) newnode);	return newnode;}/* ---------------- *		_copySeqScan * ---------------- */static SeqScan *_copySeqScan(SeqScan *from){	SeqScan    *newnode = makeNode(SeqScan);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyScanFields((Scan *) from, (Scan *) newnode);	return newnode;}/* ---------------- *		_copyIndexScan * ---------------- */static IndexScan *_copyIndexScan(IndexScan *from){	IndexScan  *newnode = makeNode(IndexScan);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyScanFields((Scan *) from, (Scan *) newnode);	/* ----------------	 *	copy remainder of node	 * ----------------	 */	newnode->indxid = listCopy(from->indxid);	Node_Copy(from, newnode, indxqual);	Node_Copy(from, newnode, indxqualorig);	return newnode;}/* ---------------- *		CopyJoinFields * *		This function copies the fields of the Join node.  It is used by *		all the copy functions for classes which inherit from Join. * ---------------- */static voidCopyJoinFields(Join *from, Join *newnode){	/* nothing extra */	return;}/* ---------------- *		_copyJoin * ---------------- */static Join *_copyJoin(Join *from){	Join	   *newnode = makeNode(Join);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyJoinFields(from, newnode);	return newnode;}/* ---------------- *		_copyNestLoop * ---------------- */static NestLoop *_copyNestLoop(NestLoop *from){	NestLoop   *newnode = makeNode(NestLoop);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyJoinFields((Join *) from, (Join *) newnode);	return newnode;}/* ---------------- *		_copyMergeJoin * ---------------- */static MergeJoin *_copyMergeJoin(MergeJoin *from){	MergeJoin  *newnode = makeNode(MergeJoin);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyJoinFields((Join *) from, (Join *) newnode);	/* ----------------	 *	copy remainder of node	 * ----------------	 */	Node_Copy(from, newnode, mergeclauses);	return newnode;}/* ---------------- *		_copyHashJoin * ---------------- */static HashJoin *_copyHashJoin(HashJoin *from){	HashJoin   *newnode = makeNode(HashJoin);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyJoinFields((Join *) from, (Join *) newnode);	/* ----------------	 *	copy remainder of node	 * ----------------	 */	Node_Copy(from, newnode, hashclauses);	newnode->hashjoinop = from->hashjoinop;	return newnode;}/* ---------------- *		CopyNonameFields * *		This function copies the fields of the Noname node.  It is used by *		all the copy functions for classes which inherit from Noname. * ---------------- */static voidCopyNonameFields(Noname *from, Noname *newnode){	newnode->nonameid = from->nonameid;	newnode->keycount = from->keycount;	return;}/* ---------------- *		_copyNoname * ---------------- */static Noname *_copyNoname(Noname *from){	Noname	   *newnode = makeNode(Noname);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyNonameFields(from, newnode);	return newnode;}/* ---------------- *		_copyMaterial * ---------------- */static Material *_copyMaterial(Material *from){	Material   *newnode = makeNode(Material);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyNonameFields((Noname *) from, (Noname *) newnode);	return newnode;}/* ---------------- *		_copySort * ---------------- */static Sort *_copySort(Sort *from){	Sort	   *newnode = makeNode(Sort);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyNonameFields((Noname *) from, (Noname *) newnode);	return newnode;}/* ---------------- *		_copyGroup * ---------------- */static Group *_copyGroup(Group *from){	Group	   *newnode = makeNode(Group);	CopyPlanFields((Plan *) from, (Plan *) newnode);	newnode->tuplePerGroup = from->tuplePerGroup;	newnode->numCols = from->numCols;	newnode->grpColIdx = palloc(from->numCols * sizeof(AttrNumber));	memcpy(newnode->grpColIdx, from->grpColIdx, from->numCols * sizeof(AttrNumber));	return newnode;}/* --------------- *	_copyAgg * -------------- */static Agg *_copyAgg(Agg *from){	Agg		   *newnode = makeNode(Agg);	CopyPlanFields((Plan *) from, (Plan *) newnode);	/*	 * Cannot copy agg list; it must be rebuilt to point to subnodes of	 * new node.	 */	set_agg_tlist_references(newnode);	return newnode;}/* --------------- *	_copyGroupClause * -------------- */static GroupClause *_copyGroupClause(GroupClause *from){	GroupClause *newnode = makeNode(GroupClause);	newnode->grpOpoid = from->grpOpoid;	newnode->tleGroupref = from->tleGroupref;	return newnode;}/* ---------------- *		_copyUnique * ---------------- */static Unique *_copyUnique(Unique *from){	Unique	   *newnode = makeNode(Unique);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	CopyNonameFields((Noname *) from, (Noname *) newnode);	/* ----------------	 *	copy remainder of node	 * ----------------	 */	if (from->uniqueAttr)		newnode->uniqueAttr = pstrdup(from->uniqueAttr);	else		newnode->uniqueAttr = NULL;	newnode->uniqueAttrNum = from->uniqueAttrNum;	return newnode;}/* ---------------- *		_copyHash * ---------------- */static Hash *_copyHash(Hash *from){	Hash	   *newnode = makeNode(Hash);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	CopyPlanFields((Plan *) from, (Plan *) newnode);	/* ----------------	 *	copy remainder of node	 * ----------------	 */	Node_Copy(from, newnode, hashkey);	return newnode;}static SubPlan *_copySubPlan(SubPlan *from){	SubPlan    *newnode = makeNode(SubPlan);	Node_Copy(from, newnode, plan);	newnode->plan_id = from->plan_id;	Node_Copy(from, newnode, rtable);	newnode->setParam = listCopy(from->setParam);	newnode->parParam = listCopy(from->parParam);	Node_Copy(from, newnode, sublink);	return newnode;}/* **************************************************************** *					   primnodes.h copy functions * **************************************************************** *//* ---------------- *		_copyResdom * ---------------- */static Resdom *_copyResdom(Resdom *from){	Resdom	   *newnode = makeNode(Resdom);	newnode->resno = from->resno;	newnode->restype = from->restype;	newnode->restypmod = from->restypmod;	if (from->resname != NULL)		newnode->resname = pstrdup(from->resname);	newnode->reskey = from->reskey;	newnode->reskeyop = from->reskeyop;	newnode->resgroupref = from->resgroupref;	newnode->resjunk = from->resjunk;	return newnode;}static Fjoin *_copyFjoin(Fjoin *from){	Fjoin	   *newnode = makeNode(Fjoin);	/* ----------------	 *	copy node superclass fields	 * ----------------	 */	newnode->fj_initialized = from->fj_initialized;	newnode->fj_nNodes = from->fj_nNodes;	Node_Copy(from, newnode, fj_innerNode);	newnode->fj_results = (DatumPtr)		palloc((from->fj_nNodes) * sizeof(Datum));	memmove(from->fj_results,			newnode->fj_results,			(from->fj_nNodes) * sizeof(Datum));	newnode->fj_alwaysDone = (BoolPtr)		palloc((from->fj_nNodes) * sizeof(bool));	memmove(from->fj_alwaysDone,			newnode->fj_alwaysDone,			(from->fj_nNodes) * sizeof(bool));	return newnode;}

⌨️ 快捷键说明

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