📄 createplan.c
字号:
} *nextsortop++ = InvalidOid; return result;}/* * set_noname_tlist_operators * Sets the key and keyop fields of resdom nodes in a target list. * * 'tlist' is the target list * 'pathkeys' is a list of N keys in the form((key1) (key2)...(keyn)), * corresponding to vars in the target list that are to * be sorted or hashed * 'operators' is the corresponding list of N sort or hash operators * * Returns the modified-in-place target list. */static List *set_noname_tlist_operators(List *tlist, List *pathkeys, Oid *operators){ int keyno = 1; Node *pathkey; Resdom *resdom; List *i; foreach(i, pathkeys) { pathkey = lfirst((List *) lfirst(i)); resdom = tlist_member((Var *) pathkey, tlist); if (resdom) { /* * Order the resdom pathkey and replace the operator OID for * each key with the regproc OID. */ resdom->reskey = keyno; resdom->reskeyop = get_opcode(operators[keyno - 1]); } keyno += 1; } return tlist;}/* * Copy cost and size info from a lower plan node to an inserted node. * This is not critical, since the decisions have already been made, * but it helps produce more reasonable-looking EXPLAIN output. */static voidcopy_costsize(Plan *dest, Plan *src){ if (src) { dest->cost = src->cost; dest->plan_size = src->plan_size; dest->plan_width = src->plan_width; } else { dest->cost = 0; dest->plan_size = 0; dest->plan_width = 0; }}/***************************************************************************** * * *****************************************************************************//* * make_noname * Create plan nodes to sort or materialize relations into noname. The * result returned for a sort will look like (SEQSCAN(SORT(plan_node))) * or (SEQSCAN(MATERIAL(plan_node))) * * 'tlist' is the target list of the scan to be sorted or hashed * 'pathkeys' is the list of keys which the sort or hash will be done on * 'operators' is the operators with which the sort or hash is to be done * (a list of operator OIDs) * 'plan_node' is the node which yields tuples for the sort * 'nonametype' indicates which operation(sort or hash) to perform */static Noname *make_noname(List *tlist, List *pathkeys, Oid *operators, Plan *plan_node, int nonametype){ List *noname_tlist; Noname *retval = NULL; /* Create a new target list for the noname, with keys set. */ noname_tlist = set_noname_tlist_operators(new_unsorted_tlist(tlist), pathkeys, operators); switch (nonametype) { case NONAME_SORT: retval = (Noname *) make_seqscan(tlist, NIL, _NONAME_RELATION_ID_, (Plan *) make_sort(noname_tlist, _NONAME_RELATION_ID_, plan_node, length(pathkeys))); break; case NONAME_MATERIAL: retval = (Noname *) make_seqscan(tlist, NIL, _NONAME_RELATION_ID_, (Plan *) make_material(noname_tlist, _NONAME_RELATION_ID_, plan_node, length(pathkeys))); break; default: elog(ERROR, "make_noname: unknown noname type %d", nonametype); } return retval;}SeqScan *make_seqscan(List *qptlist, List *qpqual, Index scanrelid, Plan *lefttree){ SeqScan *node = makeNode(SeqScan); Plan *plan = &node->plan; copy_costsize(plan, lefttree); plan->state = (EState *) NULL; plan->targetlist = qptlist; plan->qual = qpqual; plan->lefttree = lefttree; plan->righttree = NULL; node->scanrelid = scanrelid; node->scanstate = (CommonScanState *) NULL; return node;}static IndexScan *make_indexscan(List *qptlist, List *qpqual, Index scanrelid, List *indxid, List *indxqual, List *indxqualorig){ IndexScan *node = makeNode(IndexScan); Plan *plan = &node->scan.plan; copy_costsize(plan, NULL); plan->state = (EState *) NULL; plan->targetlist = qptlist; plan->qual = qpqual; plan->lefttree = NULL; plan->righttree = NULL; node->scan.scanrelid = scanrelid; node->indxid = indxid; node->indxqual = indxqual; node->indxqualorig = indxqualorig; node->scan.scanstate = (CommonScanState *) NULL; return node;}static NestLoop *make_nestloop(List *qptlist, List *qpqual, Plan *lefttree, Plan *righttree){ NestLoop *node = makeNode(NestLoop); Plan *plan = &node->join; /* * this cost estimate is entirely bogus... hopefully it will be * overwritten by caller. */ plan->cost = (lefttree ? lefttree->cost : 0) + (righttree ? righttree->cost : 0); plan->state = (EState *) NULL; plan->targetlist = qptlist; plan->qual = qpqual; plan->lefttree = lefttree; plan->righttree = righttree; node->nlstate = (NestLoopState *) NULL; return node;}static HashJoin *make_hashjoin(List *tlist, List *qpqual, List *hashclauses, Plan *lefttree, Plan *righttree){ HashJoin *node = makeNode(HashJoin); Plan *plan = &node->join; /* * this cost estimate is entirely bogus... hopefully it will be * overwritten by caller. */ plan->cost = (lefttree ? lefttree->cost : 0) + (righttree ? righttree->cost : 0); plan->state = (EState *) NULL; plan->targetlist = tlist; plan->qual = qpqual; plan->lefttree = lefttree; plan->righttree = righttree; node->hashclauses = hashclauses; node->hashdone = false; return node;}static Hash *make_hash(List *tlist, Var *hashkey, Plan *lefttree){ Hash *node = makeNode(Hash); Plan *plan = &node->plan; copy_costsize(plan, lefttree); plan->state = (EState *) NULL; plan->targetlist = tlist; plan->qual = NULL; plan->lefttree = lefttree; plan->righttree = NULL; node->hashkey = hashkey; return node;}static MergeJoin *make_mergejoin(List *tlist, List *qpqual, List *mergeclauses, Plan *righttree, Plan *lefttree){ MergeJoin *node = makeNode(MergeJoin); Plan *plan = &node->join; /* * this cost estimate is entirely bogus... hopefully it will be * overwritten by caller. */ plan->cost = (lefttree ? lefttree->cost : 0) + (righttree ? righttree->cost : 0); plan->state = (EState *) NULL; plan->targetlist = tlist; plan->qual = qpqual; plan->lefttree = lefttree; plan->righttree = righttree; node->mergeclauses = mergeclauses; return node;}Sort *make_sort(List *tlist, Oid nonameid, Plan *lefttree, int keycount){ Sort *node = makeNode(Sort); Plan *plan = &node->plan; copy_costsize(plan, lefttree); plan->cost += cost_sort(NULL, plan->plan_size, plan->plan_width); plan->state = (EState *) NULL; plan->targetlist = tlist; plan->qual = NIL; plan->lefttree = lefttree; plan->righttree = NULL; node->nonameid = nonameid; node->keycount = keycount; return node;}static Material *make_material(List *tlist, Oid nonameid, Plan *lefttree, int keycount){ Material *node = makeNode(Material); Plan *plan = &node->plan; copy_costsize(plan, lefttree); plan->state = (EState *) NULL; plan->targetlist = tlist; plan->qual = NIL; plan->lefttree = lefttree; plan->righttree = NULL; node->nonameid = nonameid; node->keycount = keycount; return node;}Agg *make_agg(List *tlist, Plan *lefttree){ Agg *node = makeNode(Agg); copy_costsize(&node->plan, lefttree); node->plan.state = (EState *) NULL; node->plan.qual = NULL; node->plan.targetlist = tlist; node->plan.lefttree = lefttree; node->plan.righttree = (Plan *) NULL; node->aggs = NIL; return node;}Group *make_group(List *tlist, bool tuplePerGroup, int ngrp, AttrNumber *grpColIdx, Sort *lefttree){ Group *node = makeNode(Group); copy_costsize(&node->plan, (Plan *) lefttree); node->plan.state = (EState *) NULL; node->plan.qual = NULL; node->plan.targetlist = tlist; node->plan.lefttree = (Plan *) lefttree; node->plan.righttree = (Plan *) NULL; node->tuplePerGroup = tuplePerGroup; node->numCols = ngrp; node->grpColIdx = grpColIdx; return node;}/* * A unique node always has a SORT node in the lefttree. * * the uniqueAttr argument must be a null-terminated string, * either the name of the attribute to select unique on * or "*" */Unique *make_unique(List *tlist, Plan *lefttree, char *uniqueAttr){ Unique *node = makeNode(Unique); Plan *plan = &node->plan; copy_costsize(plan, lefttree); plan->state = (EState *) NULL; plan->targetlist = tlist; plan->qual = NIL; plan->lefttree = lefttree; plan->righttree = NULL; node->nonameid = _NONAME_RELATION_ID_; node->keycount = 0; if (strcmp(uniqueAttr, "*") == 0) node->uniqueAttr = NULL; else node->uniqueAttr = pstrdup(uniqueAttr); return node;}#ifdef NOT_USEDList *generate_fjoin(List *tlist){ List tlistP; List newTlist = NIL; List fjoinList = NIL; int nIters = 0; /* * Break the target list into elements with Iter nodes, and those * without them. */ foreach(tlistP, tlist) { List tlistElem; tlistElem = lfirst(tlistP); if (IsA(lsecond(tlistElem), Iter)) { nIters++; fjoinList = lappend(fjoinList, tlistElem); } else newTlist = lappend(newTlist, tlistElem); } /* * if we have an Iter node then we need to flatten. */ if (nIters > 0) { List *inner; List *tempList; Fjoin *fjoinNode; DatumPtr results = (DatumPtr) palloc(nIters * sizeof(Datum)); BoolPtr alwaysDone = (BoolPtr) palloc(nIters * sizeof(bool)); inner = lfirst(fjoinList); fjoinList = lnext(fjoinList); fjoinNode = (Fjoin) MakeFjoin(false, nIters, inner, results, alwaysDone); tempList = lcons(fjoinNode, fjoinList); newTlist = lappend(newTlist, tempList); } return newTlist; return tlist; /* do nothing for now - ay 10/94 */}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -