📄 copyfuncs.c
字号:
/*------------------------------------------------------------------------- * * copyfuncs.c * Copy functions for Postgres tree nodes. * * NOTE: we currently support copying all node types found in parse and * plan trees. We do not support copying executor state trees; there * is no need for that, and no point in maintaining all the code that * would be needed. We also do not support copying Path trees, mainly * because the circular linkages between RelOptInfo and Path nodes can't * be handled easily in a simple depth-first traversal. * * * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.316.2.1 2005/11/14 23:54:32 tgl Exp $ * *------------------------------------------------------------------------- */#include "postgres.h"#include "nodes/parsenodes.h"#include "nodes/plannodes.h"#include "nodes/relation.h"#include "utils/datum.h"/* * Macros to simplify copying of different kinds of fields. Use these * wherever possible to reduce the chance for silly typos. Note that these * hard-wire the convention that the local variables in a Copy routine are * named 'newnode' and 'from'. *//* Copy a simple scalar field (int, float, bool, enum, etc) */#define COPY_SCALAR_FIELD(fldname) \ (newnode->fldname = from->fldname)/* Copy a field that is a pointer to some kind of Node or Node tree */#define COPY_NODE_FIELD(fldname) \ (newnode->fldname = copyObject(from->fldname))/* Copy a field that is a pointer to a Bitmapset */#define COPY_BITMAPSET_FIELD(fldname) \ (newnode->fldname = bms_copy(from->fldname))/* Copy a field that is a pointer to a C string, or perhaps NULL */#define COPY_STRING_FIELD(fldname) \ (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)/* Copy a field that is a pointer to a simple palloc'd object of size sz */#define COPY_POINTER_FIELD(fldname, sz) \ do { \ Size _size = (sz); \ newnode->fldname = palloc(_size); \ memcpy(newnode->fldname, from->fldname, _size); \ } while (0)/* **************************************************************** * 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){ COPY_SCALAR_FIELD(startup_cost); COPY_SCALAR_FIELD(total_cost); COPY_SCALAR_FIELD(plan_rows); COPY_SCALAR_FIELD(plan_width); COPY_NODE_FIELD(targetlist); COPY_NODE_FIELD(qual); COPY_NODE_FIELD(lefttree); COPY_NODE_FIELD(righttree); COPY_NODE_FIELD(initPlan); COPY_BITMAPSET_FIELD(extParam); COPY_BITMAPSET_FIELD(allParam); COPY_SCALAR_FIELD(nParamExec);}/* * _copyPlan */static Plan *_copyPlan(Plan *from){ Plan *newnode = makeNode(Plan); /* * copy 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 */ COPY_NODE_FIELD(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 */ COPY_NODE_FIELD(appendplans); COPY_SCALAR_FIELD(isTarget); return newnode;}/* * _copyBitmapAnd */static BitmapAnd *_copyBitmapAnd(BitmapAnd *from){ BitmapAnd *newnode = makeNode(BitmapAnd); /* * copy node superclass fields */ CopyPlanFields((Plan *) from, (Plan *) newnode); /* * copy remainder of node */ COPY_NODE_FIELD(bitmapplans); return newnode;}/* * _copyBitmapOr */static BitmapOr *_copyBitmapOr(BitmapOr *from){ BitmapOr *newnode = makeNode(BitmapOr); /* * copy node superclass fields */ CopyPlanFields((Plan *) from, (Plan *) newnode); /* * copy remainder of node */ COPY_NODE_FIELD(bitmapplans); 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){ CopyPlanFields((Plan *) from, (Plan *) newnode); COPY_SCALAR_FIELD(scanrelid);}/* * _copyScan */static Scan *_copyScan(Scan *from){ Scan *newnode = makeNode(Scan); /* * copy node superclass fields */ CopyScanFields((Scan *) from, (Scan *) newnode); return newnode;}/* * _copySeqScan */static SeqScan *_copySeqScan(SeqScan *from){ SeqScan *newnode = makeNode(SeqScan); /* * copy node superclass fields */ CopyScanFields((Scan *) from, (Scan *) newnode); return newnode;}/* * _copyIndexScan */static IndexScan *_copyIndexScan(IndexScan *from){ IndexScan *newnode = makeNode(IndexScan); /* * copy node superclass fields */ CopyScanFields((Scan *) from, (Scan *) newnode); /* * copy remainder of node */ COPY_SCALAR_FIELD(indexid); COPY_NODE_FIELD(indexqual); COPY_NODE_FIELD(indexqualorig); COPY_NODE_FIELD(indexstrategy); COPY_NODE_FIELD(indexsubtype); COPY_SCALAR_FIELD(indexorderdir); return newnode;}/* * _copyBitmapIndexScan */static BitmapIndexScan *_copyBitmapIndexScan(BitmapIndexScan *from){ BitmapIndexScan *newnode = makeNode(BitmapIndexScan); /* * copy node superclass fields */ CopyScanFields((Scan *) from, (Scan *) newnode); /* * copy remainder of node */ COPY_SCALAR_FIELD(indexid); COPY_NODE_FIELD(indexqual); COPY_NODE_FIELD(indexqualorig); COPY_NODE_FIELD(indexstrategy); COPY_NODE_FIELD(indexsubtype); return newnode;}/* * _copyBitmapHeapScan */static BitmapHeapScan *_copyBitmapHeapScan(BitmapHeapScan *from){ BitmapHeapScan *newnode = makeNode(BitmapHeapScan); /* * copy node superclass fields */ CopyScanFields((Scan *) from, (Scan *) newnode); /* * copy remainder of node */ COPY_NODE_FIELD(bitmapqualorig); return newnode;}/* * _copyTidScan */static TidScan *_copyTidScan(TidScan *from){ TidScan *newnode = makeNode(TidScan); /* * copy node superclass fields */ CopyScanFields((Scan *) from, (Scan *) newnode); /* * copy remainder of node */ COPY_NODE_FIELD(tideval); return newnode;}/* * _copySubqueryScan */static SubqueryScan *_copySubqueryScan(SubqueryScan *from){ SubqueryScan *newnode = makeNode(SubqueryScan); /* * copy node superclass fields */ CopyScanFields((Scan *) from, (Scan *) newnode); /* * copy remainder of node */ COPY_NODE_FIELD(subplan); return newnode;}/* * _copyFunctionScan */static FunctionScan *_copyFunctionScan(FunctionScan *from){ FunctionScan *newnode = makeNode(FunctionScan); /* * copy node superclass fields */ CopyScanFields((Scan *) from, (Scan *) newnode); 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){ CopyPlanFields((Plan *) from, (Plan *) newnode); COPY_SCALAR_FIELD(jointype); COPY_NODE_FIELD(joinqual);}/* * _copyJoin */static Join *_copyJoin(Join *from){ Join *newnode = makeNode(Join); /* * copy node superclass fields */ CopyJoinFields(from, newnode); return newnode;}/* * _copyNestLoop */static NestLoop *_copyNestLoop(NestLoop *from){ NestLoop *newnode = makeNode(NestLoop); /* * copy node superclass fields */ CopyJoinFields((Join *) from, (Join *) newnode); return newnode;}/* * _copyMergeJoin */static MergeJoin *_copyMergeJoin(MergeJoin *from){ MergeJoin *newnode = makeNode(MergeJoin); /* * copy node superclass fields */ CopyJoinFields((Join *) from, (Join *) newnode); /* * copy remainder of node */ COPY_NODE_FIELD(mergeclauses); return newnode;}/* * _copyHashJoin */static HashJoin *_copyHashJoin(HashJoin *from){ HashJoin *newnode = makeNode(HashJoin); /* * copy node superclass fields */ CopyJoinFields((Join *) from, (Join *) newnode); /* * copy remainder of node */ COPY_NODE_FIELD(hashclauses); return newnode;}/* * _copyMaterial */static Material *_copyMaterial(Material *from){ Material *newnode = makeNode(Material); /* * copy node superclass fields */ CopyPlanFields((Plan *) from, (Plan *) newnode); return newnode;}/* * _copySort */static Sort *_copySort(Sort *from){ Sort *newnode = makeNode(Sort); /* * copy node superclass fields */ CopyPlanFields((Plan *) from, (Plan *) newnode); COPY_SCALAR_FIELD(numCols); COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber)); COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid)); return newnode;}/* * _copyGroup */static Group *_copyGroup(Group *from){ Group *newnode = makeNode(Group); CopyPlanFields((Plan *) from, (Plan *) newnode); COPY_SCALAR_FIELD(numCols); COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber)); return newnode;}/* * _copyAgg */static Agg *_copyAgg(Agg *from){ Agg *newnode = makeNode(Agg); CopyPlanFields((Plan *) from, (Plan *) newnode); COPY_SCALAR_FIELD(aggstrategy); COPY_SCALAR_FIELD(numCols); if (from->numCols > 0) COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber)); COPY_SCALAR_FIELD(numGroups); return newnode;}/* * _copyUnique */static Unique *_copyUnique(Unique *from){ Unique *newnode = makeNode(Unique); /* * copy node superclass fields */ CopyPlanFields((Plan *) from, (Plan *) newnode); /* * copy remainder of node */ COPY_SCALAR_FIELD(numCols); COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber)); 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 */ return newnode;}/* * _copySetOp */static SetOp *_copySetOp(SetOp *from){ SetOp *newnode = makeNode(SetOp); /* * copy node superclass fields */ CopyPlanFields((Plan *) from, (Plan *) newnode); /* * copy remainder of node */ COPY_SCALAR_FIELD(cmd); COPY_SCALAR_FIELD(numCols); COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber)); COPY_SCALAR_FIELD(flagColIdx); return newnode;}/* * _copyLimit */static Limit *_copyLimit(Limit *from){ Limit *newnode = makeNode(Limit); /* * copy node superclass fields */ CopyPlanFields((Plan *) from, (Plan *) newnode); /* * copy remainder of node */ COPY_NODE_FIELD(limitOffset); COPY_NODE_FIELD(limitCount); return newnode;}/* **************************************************************** * primnodes.h copy functions * **************************************************************** *//* * _copyAlias */static Alias *_copyAlias(Alias *from){ Alias *newnode = makeNode(Alias); COPY_STRING_FIELD(aliasname); COPY_NODE_FIELD(colnames); return newnode;}/* * _copyRangeVar */static RangeVar *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -