/* *Arraysarevarlenaobjects,somustmeetthevarlenaconventionthat *thefirstint32oftheobjectcontainsthetotalobjectsizeinbytes. *BesuretouseVARSIZE()andSET_VARSIZE()toaccessit,though! * *CAUTION:ifyouchangetheheaderforordinaryarraysyouwillalso *needtochangetheheadersforoidvectorandint2vector!
*/ typedefstruct ArrayType
{
int32 vl_len_; /* varlena header (do not touch directly!) */ int ndim; /* # of dimensions */
int32 dataoffset; /* offset to data, or 0 if no bitmap */
Oid elemtype; /* element type OID */
} ArrayType;
typedefstruct ExpandedArrayHeader
{ /* Standard header for expanded objects */
ExpandedObjectHeader hdr;
/* Magic value identifying an expanded array (for debugging only) */ int ea_magic;
/* Dimensionality info (always valid) */ int ndims; /* # of dimensions */ int *dims; /* array dimensions */ int *lbound; /* index lower bounds for each dimension */
/* Element type info (always valid) */
Oid element_type; /* element type OID */
int16 typlen; /* needed info about element datatype */ bool typbyval; char typalign;
/* *IfwehaveaDatum-arrayrepresentationofthearray,it'skepthere; *elsedvalues/dnullsareNULL.Thedvaluesanddnullsarraysarealways *palloc'dwithintheobjectprivatecontext,butmaychangesizefrom *timetotime.Forpass-by-refelementtypes,dvaluesentriesmight *pointeitherintothefstartptr..fendptrarea,ortoseparately *palloc'dchunks.Elementsshouldalwaysbefullydetoasted,asthey *areinthestandardflatrepresentation. * *Evenwhendvaluesisvalid,dnullscanbeNULLiftherearenonull *elements.
*/
Datum *dvalues; /* array of Datums */ bool *dnulls; /* array of is-null flags for Datums */ int dvalueslen; /* allocated length of above arrays */ int nelems; /* number of valid entries in above arrays */
/* *fvaluepointstotheflatrepresentationifitisvalid,elseitis *NULL.Ifwehaveoreverhadaflatrepresentationthen *fstartptr/fendptrpointtothestartandend+1ofitsdataarea;this *issothatwecantellwhichDatumpointerspointintotheflat *representationratherthanbeingpointerstoseparatelypalloc'ddata.
*/
ArrayType *fvalue; /* must be a fully detoasted array */ char *fstartptr; /* start of its data area */ char *fendptr; /* end+1 of its data area */
} ExpandedArrayHeader;
/* *workingstateforaccumArrayResult()andfriends *notethattheinputmustbescalars(legalarrayelements)
*/ typedefstruct ArrayBuildState
{
MemoryContext mcontext; /* where all the temp stuff is kept */
Datum *dvalues; /* array of accumulated Datums */ bool *dnulls; /* array of is-null flags for Datums */ int alen; /* allocated length of above arrays */ int nelems; /* number of valid entries in above arrays */
Oid element_type; /* data type of the Datums */
int16 typlen; /* needed info about datatype */ bool typbyval; char typalign; bool private_cxt; /* use private memory context */
} ArrayBuildState;
/* *workingstateforaccumArrayResultArr()andfriends *notethattheinputmustbearrays,andthesamearraytypeisreturned
*/ typedefstruct ArrayBuildStateArr
{
MemoryContext mcontext; /* where all the temp stuff is kept */ char *data; /* accumulated data */
bits8 *nullbitmap; /* bitmap of is-null flags, or NULL if none */ int abytes; /* allocated length of "data" */ int nbytes; /* number of bytes used so far */ int aitems; /* allocated length of bitmap (in elements) */ int nitems; /* total number of elements in result */ int ndims; /* current dimensions of result */ int dims[MAXDIM]; int lbs[MAXDIM];
Oid array_type; /* data type of the arrays */
Oid element_type; /* data type of the array elements */ bool private_cxt; /* use private memory context */
} ArrayBuildStateArr;
/* *workingstateforaccumArrayResultAny()andfriends *thesefunctionshandlebothcases
*/ typedefstruct ArrayBuildStateAny
{ /* Exactly one of these is not NULL: */
ArrayBuildState *scalarstate;
ArrayBuildStateArr *arraystate;
} ArrayBuildStateAny;
/* *structuretocachetypemetadataneededforarraymanipulation
*/ typedefstruct ArrayMetaState
{
Oid element_type;
int16 typlen; bool typbyval; char typalign; char typdelim;
Oid typioparam;
Oid typiofunc;
FmgrInfo proc;
} ArrayMetaState;
/* *prototypesforfunctionsdefinedinarrayfuncs.c
*/ externvoid CopyArrayEls(ArrayType *array,
Datum *values, bool *nulls, int nitems, int typlen, bool typbyval, char typalign, bool freedata);
extern Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull); extern Datum array_set_element(Datum arraydatum, int nSubscripts, int *indx,
Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign); extern Datum array_get_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided, int arraytyplen, int elmlen, bool elmbyval, char elmalign); extern Datum array_set_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided,
Datum srcArrayDatum, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign);
extern Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull); extern ArrayType *array_set(ArrayType *array, int nSubscripts, int *indx,
Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign);
extern Datum array_map(Datum arrayd, struct ExprState *exprstate, struct ExprContext *econtext,
Oid retType, ArrayMapState *amstate);
externvoid array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems);
extern ArrayType *construct_array(Datum *elems, int nelems,
Oid elmtype, int elmlen, bool elmbyval, char elmalign); extern ArrayType *construct_array_builtin(Datum *elems, int nelems, Oid elmtype); extern ArrayType *construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs,
Oid elmtype, int elmlen, bool elmbyval, char elmalign); extern ArrayType *construct_empty_array(Oid elmtype); extern ExpandedArrayHeader *construct_empty_expanded_array(Oid element_type,
MemoryContext parentcontext,
ArrayMetaState *metacache); externvoid deconstruct_array(ArrayType *array,
Oid elmtype, int elmlen, bool elmbyval, char elmalign,
Datum **elemsp, bool **nullsp, int *nelemsp); externvoid deconstruct_array_builtin(ArrayType *array,
Oid elmtype,
Datum **elemsp, bool **nullsp, int *nelemsp); externbool array_contains_nulls(ArrayType *array);
extern ArrayBuildState *initArrayResult(Oid element_type,
MemoryContext rcontext, bool subcontext); extern ArrayBuildState *initArrayResultWithSize(Oid element_type,
MemoryContext rcontext, bool subcontext, int initsize); extern ArrayBuildState *accumArrayResult(ArrayBuildState *astate,
Datum dvalue, bool disnull,
Oid element_type,
MemoryContext rcontext); extern Datum makeArrayResult(ArrayBuildState *astate,
MemoryContext rcontext); extern Datum makeMdArrayResult(ArrayBuildState *astate, int ndims, int *dims, int *lbs, MemoryContext rcontext, bool release);
extern ArrayBuildStateArr *initArrayResultArr(Oid array_type, Oid element_type,
MemoryContext rcontext, bool subcontext); extern ArrayBuildStateArr *accumArrayResultArr(ArrayBuildStateArr *astate,
Datum dvalue, bool disnull,
Oid array_type,
MemoryContext rcontext); extern Datum makeArrayResultArr(ArrayBuildStateArr *astate,
MemoryContext rcontext, bool release);
extern ArrayBuildStateAny *initArrayResultAny(Oid input_type,
MemoryContext rcontext, bool subcontext); extern ArrayBuildStateAny *accumArrayResultAny(ArrayBuildStateAny *astate,
Datum dvalue, bool disnull,
Oid input_type,
MemoryContext rcontext); extern Datum makeArrayResultAny(ArrayBuildStateAny *astate,
MemoryContext rcontext, bool release);
extern ArrayIterator array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate); externbool array_iterate(ArrayIterator iterator, Datum *value, bool *isnull); externvoid array_free_iterator(ArrayIterator iterator);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.