📄 copyfuncs.c
字号:
/* ---------------- * _copyExpr * ---------------- */static Expr *_copyExpr(Expr *from){ Expr *newnode = makeNode(Expr); /* ---------------- * copy node superclass fields * ---------------- */ newnode->typeOid = from->typeOid; newnode->opType = from->opType; Node_Copy(from, newnode, oper); Node_Copy(from, newnode, args); return newnode;}/* ---------------- * _copyVar * ---------------- */static Var *_copyVar(Var *from){ Var *newnode = makeNode(Var); /* ---------------- * copy remainder of node * ---------------- */ newnode->varno = from->varno; newnode->varattno = from->varattno; newnode->vartype = from->vartype; newnode->vartypmod = from->vartypmod; newnode->varlevelsup = from->varlevelsup; newnode->varnoold = from->varnoold; newnode->varoattno = from->varoattno; return newnode;}/* ---------------- * _copyOper * ---------------- */static Oper *_copyOper(Oper *from){ Oper *newnode = makeNode(Oper); /* ---------------- * copy remainder of node * ---------------- */ newnode->opno = from->opno; newnode->opid = from->opid; newnode->opresulttype = from->opresulttype; newnode->opsize = from->opsize; /* * NOTE: shall we copy the cache structure or just the pointer ? * Alternatively we can set 'op_fcache' to NULL, in which case the * executor will initialize it when it needs it... */ newnode->op_fcache = from->op_fcache; return newnode;}/* ---------------- * _copyConst * ---------------- */static Const *_copyConst(Const *from){ static Oid cached_type; static bool cached_typbyval; Const *newnode = makeNode(Const); /* ---------------- * copy remainder of node * ---------------- */ newnode->consttype = from->consttype; newnode->constlen = from->constlen; /* ---------------- * XXX super cheesy hack until parser/planner * puts in the right values here. * * But I like cheese. * ---------------- */ if (!from->constisnull && cached_type != from->consttype) { HeapTuple typeTuple; Form_pg_type typeStruct; /* ---------------- * get the type tuple corresponding to the paramList->type, * If this fails, returnValue has been pre-initialized * to "null" so we just return it. * ---------------- */ typeTuple = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(from->consttype), 0, 0, 0); /* ---------------- * get the type length and by-value from the type tuple and * save the information in our one element cache. * ---------------- */ Assert(PointerIsValid(typeTuple)); typeStruct = (Form_pg_type) GETSTRUCT(typeTuple); cached_typbyval = (typeStruct)->typbyval ? true : false; cached_type = from->consttype; } from->constbyval = cached_typbyval; if (!from->constisnull) { /* ---------------- * copying the Datum in a const node is a bit trickier * because it might be a pointer and it might also be of * variable length... * ---------------- */ if (from->constbyval == true) { /* ---------------- * passed by value so just copy the datum. * ---------------- */ newnode->constvalue = from->constvalue; } else { /* ---------------- * not passed by value. datum contains a pointer. * ---------------- */ if (from->constlen != -1) { /* ---------------- * fixed length structure * ---------------- */ newnode->constvalue = PointerGetDatum(palloc(from->constlen)); memmove((char *) newnode->constvalue, (char *) from->constvalue, from->constlen); } else { /* ---------------- * variable length structure. here the length is stored * in the first int pointed to by the constval. * ---------------- */ int length; length = VARSIZE(from->constvalue); newnode->constvalue = PointerGetDatum(palloc(length)); memmove((char *) newnode->constvalue, (char *) from->constvalue, length); } } } else newnode->constvalue = from->constvalue; newnode->constisnull = from->constisnull; newnode->constbyval = from->constbyval; newnode->constisset = from->constisset; newnode->constiscast = from->constiscast; return newnode;}/* ---------------- * _copyParam * ---------------- */static Param *_copyParam(Param *from){ Param *newnode = makeNode(Param); /* ---------------- * copy remainder of node * ---------------- */ newnode->paramkind = from->paramkind; newnode->paramid = from->paramid; if (from->paramname != NULL) newnode->paramname = pstrdup(from->paramname); newnode->paramtype = from->paramtype; Node_Copy(from, newnode, param_tlist); return newnode;}/* ---------------- * _copyFunc * ---------------- */static Func *_copyFunc(Func *from){ Func *newnode = makeNode(Func); /* ---------------- * copy remainder of node * ---------------- */ newnode->funcid = from->funcid; newnode->functype = from->functype; newnode->funcisindex = from->funcisindex; newnode->funcsize = from->funcsize; newnode->func_fcache = from->func_fcache; Node_Copy(from, newnode, func_tlist); Node_Copy(from, newnode, func_planlist); return newnode;}/* ---------------- * _copyAggref * ---------------- */static Aggref *_copyAggref(Aggref *from){ Aggref *newnode = makeNode(Aggref); /* ---------------- * copy remainder of node * ---------------- */ newnode->aggname = pstrdup(from->aggname); newnode->basetype = from->basetype; newnode->aggtype = from->aggtype; Node_Copy(from, newnode, target); newnode->aggno = from->aggno; newnode->usenulls = from->usenulls; return newnode;}/* ---------------- * _copySubLink * ---------------- */static SubLink *_copySubLink(SubLink *from){ SubLink *newnode = makeNode(SubLink); /* ---------------- * copy remainder of node * ---------------- */ newnode->subLinkType = from->subLinkType; newnode->useor = from->useor; Node_Copy(from, newnode, lefthand); Node_Copy(from, newnode, oper); Node_Copy(from, newnode, subselect); return newnode;}/* ---------------- * _copyCaseExpr * ---------------- */static CaseExpr *_copyCaseExpr(CaseExpr *from){ CaseExpr *newnode = makeNode(CaseExpr); /* ---------------- * copy remainder of node * ---------------- */ newnode->casetype = from->casetype; Node_Copy(from, newnode, arg); Node_Copy(from, newnode, args); Node_Copy(from, newnode, defresult); return newnode;}/* ---------------- * _copyCaseWhen * ---------------- */static CaseWhen *_copyCaseWhen(CaseWhen *from){ CaseWhen *newnode = makeNode(CaseWhen); /* ---------------- * copy remainder of node * ---------------- */ Node_Copy(from, newnode, expr); Node_Copy(from, newnode, result); return newnode;}static Array *_copyArray(Array *from){ Array *newnode = makeNode(Array); /* ---------------- * copy remainder of node * ---------------- */ newnode->arrayelemtype = from->arrayelemtype; newnode->arrayelemlength = from->arrayelemlength; newnode->arrayelembyval = from->arrayelembyval; newnode->arrayndim = from->arrayndim; newnode->arraylow = from->arraylow; newnode->arrayhigh = from->arrayhigh; newnode->arraylen = from->arraylen; return newnode;}static ArrayRef *_copyArrayRef(ArrayRef *from){ ArrayRef *newnode = makeNode(ArrayRef); /* ---------------- * copy remainder of node * ---------------- */ newnode->refattrlength = from->refattrlength; newnode->refelemlength = from->refelemlength; newnode->refelemtype = from->refelemtype; newnode->refelembyval = from->refelembyval; Node_Copy(from, newnode, refupperindexpr); Node_Copy(from, newnode, reflowerindexpr); Node_Copy(from, newnode, refexpr); Node_Copy(from, newnode, refassgnexpr); return newnode;}/* **************************************************************** * relation.h copy functions * **************************************************************** *//* ---------------- * _copyRelOptInfo * ---------------- *//* * when you change this, also make sure to fix up xfunc_copyRelOptInfo in * planner/path/xfunc.c accordingly!!! * -- JMH, 8/2/93 */static RelOptInfo *_copyRelOptInfo(RelOptInfo *from){ RelOptInfo *newnode = makeNode(RelOptInfo); int i, len; /* ---------------- * copy remainder of node * ---------------- */ newnode->relids = listCopy(from->relids); newnode->indexed = from->indexed; newnode->pages = from->pages; newnode->tuples = from->tuples; newnode->size = from->size; newnode->width = from->width; Node_Copy(from, newnode, targetlist); Node_Copy(from, newnode, pathlist); Node_Copy(from, newnode, cheapestpath); newnode->pruneable = from->pruneable; if (from->classlist) { for (len = 0; from->classlist[len] != 0; len++) ; newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1)); for (i = 0; i < len; i++) newnode->classlist[i] = from->classlist[i]; newnode->classlist[len] = 0; } if (from->indexkeys) { for (len = 0; from->indexkeys[len] != 0; len++) ; newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1)); for (i = 0; i < len; i++) newnode->indexkeys[i] = from->indexkeys[i]; newnode->indexkeys[len] = 0; } newnode->relam = from->relam; newnode->indproc = from->indproc; Node_Copy(from, newnode, indpred); if (from->ordering) { for (len = 0; from->ordering[len] != 0; len++) ; newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1)); for (i = 0; i < len; i++) newnode->ordering[i] = from->ordering[i]; newnode->ordering[len] = 0; } Node_Copy(from, newnode, restrictinfo); Node_Copy(from, newnode, joininfo); Node_Copy(from, newnode, innerjoin); return newnode;}/* ---------------- * CopyPathFields * * This function copies the fields of the Path node. It is used by * all the copy functions for classes which inherit from Path. * ---------------- */static voidCopyPathFields(Path *from, Path *newnode){ newnode->pathtype = from->pathtype; /* * Modify the next line, since it causes the copying to cycle (i.e. * the parent points right back here! -- JMH, 7/7/92. Old version: * Node_Copy(from, newnode, parent); */ newnode->parent = from->parent; newnode->path_cost = from->path_cost; newnode->pathorder = makeNode(PathOrder); newnode->pathorder->ordtype = from->pathorder->ordtype; if (from->pathorder->ordtype == SORTOP_ORDER) { int len, i; Oid *ordering = from->pathorder->ord.sortop; if (ordering) { for (len = 0; ordering[len] != 0; len++) ; newnode->pathorder->ord.sortop = (Oid *) palloc(sizeof(Oid) * (len + 1)); for (i = 0; i < len; i++) newnode->pathorder->ord.sortop[i] = ordering[i]; newnode->pathorder->ord.sortop[len] = 0; } } else Node_Copy(from, newnode, pathorder->ord.merge); Node_Copy(from, newnode, pathkeys); newnode->outerjoincost = from->outerjoincost; newnode->joinid = listCopy(from->joinid); Node_Copy(from, newnode, loc_restrictinfo);}/* ---------------- * _copyPath * ---------------- */static Path *_copyPath(Path *from){ Path *newnode = makeNode(Path); CopyPathFields(from, newnode); return newnode;}/* ---------------- * _copyIndexPath * ---------------- */static IndexPath *_copyIndexPath(IndexPath *from){ IndexPath *newnode = makeNode(IndexPath); /* ---------------- * copy the node superclass fields * ---------------- */ CopyPathFields((Path *) from, (Path *) newnode); /* ---------------- * copy remainder of node * ---------------- */ newnode->indexid = listCopy(from->indexid); Node_Copy(from, newnode, indexqual); if (from->indexkeys) { int i, len; for (len = 0; from->indexkeys[len] != 0; len++) ; newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1)); for (i = 0; i < len; i++) newnode->indexkeys[i] = from->indexkeys[i]; newnode->indexkeys[len] = 0; } return newnode;}/* ---------------- * CopyNestPathFields * * This function copies the fields of the NestPath node. It is used by * all the copy functions for classes which inherit from NestPath. * ---------------- */static voidCopyNestPathFields(NestPath *from, NestPath *newnode){ Node_Copy(from, newnode, pathinfo); Node_Copy(from, newnode, outerjoinpath); Node_Copy(from, newnode, innerjoinpath);}/* ---------------- * _copyNestPath * ---------------- */static NestPath *_copyNestPath(NestPath *from){ NestPath *newnode = makeNode(NestPath); /* ---------------- * copy the node superclass fields * ---------------- */ CopyPathFields((Path *) from, (Path *) newnode); CopyNestPathFields(from, newnode); return newnode;}/* ---------------- * _copyMergePath * ---------------- */static MergePath *_copyMergePath(MergePath *from){ MergePath *newnode = makeNode(MergePath); /* ---------------- * copy the node superclass fields * ---------------- */ CopyPathFields((Path *) from, (Path *) newnode); CopyNestPathFields((NestPath *) from, (NestPath *) newnode); /* ---------------- * copy the remainder of the node * ---------------- */ Node_Copy(from, newnode, path_mergeclauses); Node_Copy(from, newnode, outersortkeys); Node_Copy(from, newnode, innersortkeys); return newnode;}/* ---------------- * _copyHashPath * ---------------- */static HashPath *_copyHashPath(HashPath *from){ HashPath *newnode = makeNode(HashPath); /* ---------------- * copy the node superclass fields * ---------------- */ CopyPathFields((Path *) from, (Path *) newnode); CopyNestPathFields((NestPath *) from, (NestPath *) newnode);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -