📄 executils.c
字号:
* the following scan type support functions are for * those nodes which are stubborn and return tuples in * their Scan tuple slot instead of their Result tuple * slot.. luck fur us, these nodes do not do projections * so we don't have to worry about getting the ProjectionInfo * right for them... -cim 6/3/91 * ---------------------------------------------------------------- *//* ---------------- * ExecGetScanType * ---------------- */TupleDescExecGetScanType(CommonScanState *csstate){ TupleTableSlot *slot = csstate->css_ScanTupleSlot; return slot->ttc_tupleDescriptor;}/* ---------------- * ExecFreeScanType * ---------------- */#ifdef NOT_USEDvoidExecFreeScanType(CommonScanState *csstate){ TupleTableSlot *slot; TupleDesc tupType; slot = csstate->css_ScanTupleSlot; tupType = slot->ttc_tupleDescriptor; ExecFreeTypeInfo(tupType);}#endif/* ---------------- * ExecAssignScanType * ---------------- */voidExecAssignScanType(CommonScanState *csstate, TupleDesc tupDesc){ TupleTableSlot *slot; slot = (TupleTableSlot *) csstate->css_ScanTupleSlot; slot->ttc_tupleDescriptor = tupDesc;}/* ---------------- * ExecAssignScanTypeFromOuterPlan * ---------------- */voidExecAssignScanTypeFromOuterPlan(Plan *node, CommonScanState *csstate){ Plan *outerPlan; TupleDesc tupDesc; outerPlan = outerPlan(node); tupDesc = ExecGetTupType(outerPlan); ExecAssignScanType(csstate, tupDesc);}/* ---------------------------------------------------------------- * ExecTypeFromTL support routines. * * these routines are used mainly from ExecTypeFromTL. * -cim 6/12/90 * * old comments * Routines dealing with the structure 'attribute' which conatains * the type information about attributes in a tuple: * * ExecMakeTypeInfo(noType) * returns pointer to array of 'noType' structure 'attribute'. * ExecSetTypeInfo(index, typeInfo, attNum, attLen) * sets the element indexed by 'index' in typeInfo with * the values: attNum, attLen. * ExecFreeTypeInfo(typeInfo) * frees the structure 'typeInfo'. * ---------------------------------------------------------------- *//* ---------------- * ExecSetTypeInfo * * This initializes fields of a single attribute in a * tuple descriptor from the specified parameters. * * XXX this duplicates much of the functionality of TupleDescInitEntry. * the routines should be moved to the same place and be rewritten * to share common code. * ---------------- */#ifdef NOT_USEDvoidExecSetTypeInfo(int index, TupleDesc typeInfo, Oid typeID, int attNum, int attLen, char *attName, bool attbyVal, char attalign){ Form_pg_attribute att; /* ---------------- * get attribute pointer and preform a sanity check.. * ---------------- */ att = typeInfo[index]; if (att == NULL) elog(ERROR, "ExecSetTypeInfo: trying to assign through NULL"); /* ---------------- * assign values to the tuple descriptor, being careful not * to copy a null attName.. * * XXX it is unknown exactly what information is needed to * initialize the attribute struct correctly so for now * we use 0. this should be fixed -- otherwise we run the * risk of using garbage data. -cim 5/5/91 * ---------------- */ att->attrelid = 0; /* dummy value */ if (attName != (char *) NULL) StrNCpy(att->attname.data, attName, NAMEDATALEN); else MemSet(att->attname.data, 0, NAMEDATALEN); att->atttypid = typeID; att->attdefrel = 0; /* dummy value */ att->attdisbursion = 0; /* dummy value */ att->atttyparg = 0; /* dummy value */ att->attlen = attLen; att->attnum = attNum; att->attbound = 0; /* dummy value */ att->attbyval = attbyVal; att->attcanindex = 0; /* dummy value */ att->attproc = 0; /* dummy value */ att->attnelems = 0; /* dummy value */ att->attcacheoff = -1; att->atttypmod = -1; att->attisset = false; att->attalign = attalign;}/* ---------------- * ExecFreeTypeInfo frees the array of attrbutes * created by ExecMakeTypeInfo and returned by ExecTypeFromTL... * ---------------- */voidExecFreeTypeInfo(TupleDesc typeInfo){ /* ---------------- * do nothing if asked to free a null pointer * ---------------- */ if (typeInfo == NULL) return; /* ---------------- * the entire array of typeinfo pointers created by * ExecMakeTypeInfo was allocated with a single palloc() * so we can deallocate the whole array with a single pfree(). * (we should not try and free all the elements in the array) * -cim 6/12/90 * ---------------- */ pfree(typeInfo);}/* ---------------------------------------------------------------- * QueryDescGetTypeInfo * *| I don't know how this is used, all I know is that it *| appeared one day in main.c so I moved it here. -cim 11/1/89 * ---------------------------------------------------------------- */TupleDescQueryDescGetTypeInfo(QueryDesc *queryDesc){ Plan *plan; TupleDesc tupleType; List *targetList; AttrInfo *attinfo = (AttrInfo *) palloc(sizeof(AttrInfo)); plan = queryDesc->plantree; tupleType = (TupleDesc) ExecGetTupType(plan);/* targetList = plan->targetlist; attinfo->numAttr = ExecTargetListLength(targetList); attinfo->attrs = tupleType;*/ attinfo->numAttr = tupleType->natts; attinfo->attrs = tupleType->attrs; return attinfo;}#endif/* ---------------------------------------------------------------- * ExecInsertIndexTuples support * ---------------------------------------------------------------- *//* ---------------------------------------------------------------- * ExecGetIndexKeyInfo * * Extracts the index key attribute numbers from * an index tuple form (i.e. a tuple from the pg_index relation) * into an array of attribute numbers. The array and the * size of the array are returned to the caller via return * parameters. * ---------------------------------------------------------------- */static voidExecGetIndexKeyInfo(Form_pg_index indexTuple, int *numAttsOutP, AttrNumber **attsOutP, FuncIndexInfoPtr fInfoP){ int i; int numKeys; AttrNumber *attKeys; /* ---------------- * check parameters * ---------------- */ if (numAttsOutP == NULL && attsOutP == NULL) { elog(DEBUG, "ExecGetIndexKeyInfo: %s", "invalid parameters: numAttsOutP and attsOutP must be non-NULL"); } /* ---------------- * set the procid for a possible functional index. * ---------------- */ FIsetProcOid(fInfoP, indexTuple->indproc); /* ---------------- * count the number of keys.. * ---------------- */ numKeys = 0; for (i = 0; i < INDEX_MAX_KEYS && indexTuple->indkey[i] != InvalidAttrNumber; i++) numKeys++; /* ---------------- * place number keys in callers return area * or the number of arguments for a functional index. * * If we have a functional index then the number of * attributes defined in the index must 1 (the function's * single return value). * ---------------- */ if (FIgetProcOid(fInfoP) != InvalidOid) { FIsetnArgs(fInfoP, numKeys); (*numAttsOutP) = 1; } else (*numAttsOutP) = numKeys; if (numKeys < 1) { elog(DEBUG, "ExecGetIndexKeyInfo: %s", "all index key attribute numbers are zero!"); (*attsOutP) = NULL; return; } /* ---------------- * allocate and fill in array of key attribute numbers * ---------------- */ CXT1_printf("ExecGetIndexKeyInfo: context is %d\n", CurrentMemoryContext); attKeys = (AttrNumber *) palloc(numKeys * sizeof(AttrNumber)); for (i = 0; i < numKeys; i++) attKeys[i] = indexTuple->indkey[i]; /* ---------------- * return array to caller. * ---------------- */ (*attsOutP) = attKeys;}/* ---------------------------------------------------------------- * ExecOpenIndices * * Here we scan the pg_index relation to find indices * associated with a given heap relation oid. Since we * don't know in advance how many indices we have, we * form lists containing the information we need from * pg_index and then process these lists. * * Note: much of this code duplicates effort done by * the IndexCatalogInformation function in plancat.c * because IndexCatalogInformation is poorly written. * * It would be much better if the functionality provided * by this function and IndexCatalogInformation was * in the form of a small set of orthogonal routines.. * If you are trying to understand this, I suggest you * look at the code to IndexCatalogInformation and * FormIndexTuple.. -cim 9/27/89 * ---------------------------------------------------------------- */voidExecOpenIndices(Oid resultRelationOid, RelationInfo *resultRelationInfo){ Relation indexRd; HeapScanDesc indexSd; ScanKeyData key; HeapTuple tuple; Form_pg_index indexStruct; Oid indexOid; List *oidList; List *nkeyList; List *keyList; List *fiList; char *predString; List *predList; List *indexoid; List *numkeys; List *indexkeys; List *indexfuncs; List *indexpreds; int len; RelationPtr relationDescs; IndexInfo **indexInfoArray; FuncIndexInfoPtr fInfoP; int numKeyAtts; AttrNumber *indexKeyAtts; PredInfo *predicate; int i; /* ---------------- * open pg_index * ---------------- */ indexRd = heap_openr(IndexRelationName); /* ---------------- * form a scan key * ---------------- */ ScanKeyEntryInitialize(&key, 0, Anum_pg_index_indrelid, F_OIDEQ, ObjectIdGetDatum(resultRelationOid)); /* ---------------- * scan the index relation, looking for indices for our * result relation.. * ---------------- */ indexSd = heap_beginscan(indexRd, /* scan desc */ false, /* scan backward flag */ SnapshotNow, /* NOW snapshot */ 1, /* number scan keys */ &key); /* scan keys */ oidList = NIL; nkeyList = NIL; keyList = NIL; fiList = NIL; predList = NIL; while (HeapTupleIsValid(tuple = heap_getnext(indexSd, 0))) { /* ---------------- * For each index relation we find, extract the information * we need and store it in a list.. * * first get the oid of the index relation from the tuple * ---------------- */ indexStruct = (Form_pg_index) GETSTRUCT(tuple); indexOid = indexStruct->indexrelid; /* ---------------- * allocate space for functional index information. * ---------------- */ fInfoP = (FuncIndexInfoPtr) palloc(sizeof(*fInfoP)); /* ---------------- * next get the index key information from the tuple * ---------------- */ ExecGetIndexKeyInfo(indexStruct, &numKeyAtts, &indexKeyAtts, fInfoP); /* ---------------- * next get the index predicate from the tuple
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -