PostgreSQL Source Code: src/include/utils/array.h File Reference (original) (raw)

Go to the source code of this file.

Data Structures
struct ArrayType
struct ExpandedArrayHeader
union AnyArrayType
struct ArrayBuildState
struct ArrayBuildStateArr
struct ArrayBuildStateAny
struct ArrayMetaState
struct ArrayMapState
Macros
#define MAXDIM 6
#define MaxArraySize ((Size) (MaxAllocSize / sizeof(Datum)))
#define EA_MAGIC 689375833 /* ID for debugging crosschecks */
#define DatumGetArrayTypeP(X) ((ArrayType *) PG_DETOAST_DATUM(X))
#define DatumGetArrayTypePCopy(X) ((ArrayType *) PG_DETOAST_DATUM_COPY(X))
#define PG_GETARG_ARRAYTYPE_P(n) DatumGetArrayTypeP(PG_GETARG_DATUM(n))
#define PG_GETARG_ARRAYTYPE_P_COPY(n) DatumGetArrayTypePCopy(PG_GETARG_DATUM(n))
#define PG_RETURN_ARRAYTYPE_P(x) PG_RETURN_POINTER(x)
#define PG_GETARG_EXPANDED_ARRAY(n) DatumGetExpandedArray(PG_GETARG_DATUM(n))
#define PG_GETARG_EXPANDED_ARRAYX(n, metacache) DatumGetExpandedArrayX(PG_GETARG_DATUM(n), metacache)
#define PG_RETURN_EXPANDED_ARRAY(x) PG_RETURN_DATUM(EOHPGetRWDatum(&(x)->hdr))
#define PG_GETARG_ANY_ARRAY_P(n) DatumGetAnyArrayP(PG_GETARG_DATUM(n))
#define ARR_SIZE(a) VARSIZE(a)
#define ARR_NDIM(a) ((a)->ndim)
#define ARR_HASNULL(a) ((a)->dataoffset != 0)
#define ARR_ELEMTYPE(a) ((a)->elemtype)
#define ARR_DIMS(a) ((int *) (((char *) (a)) + sizeof(ArrayType)))
#define ARR_LBOUND(a)
#define ARR_NULLBITMAP(a)
#define ARR_OVERHEAD_NONULLS(ndims) MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (ndims))
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
#define ARR_DATA_OFFSET(a) (ARR_HASNULL(a) ? (a)->dataoffset : ARR_OVERHEAD_NONULLS(ARR_NDIM(a)))
#define ARR_DATA_PTR(a) (((char *) (a)) + ARR_DATA_OFFSET(a))
#define AARR_NDIM(a)
#define AARR_HASNULL(a)
#define AARR_ELEMTYPE(a)
#define AARR_DIMS(a)
#define AARR_LBOUND(a)
Typedefs
typedef struct ArrayType ArrayType
typedef struct ExpandedArrayHeader ExpandedArrayHeader
typedef union AnyArrayType AnyArrayType
typedef struct ArrayBuildState ArrayBuildState
typedef struct ArrayBuildStateArr ArrayBuildStateArr
typedef struct ArrayBuildStateAny ArrayBuildStateAny
typedef struct ArrayMetaState ArrayMetaState
typedef struct ArrayMapState ArrayMapState
typedef struct ArrayIteratorData * ArrayIterator
Functions
void CopyArrayEls (ArrayType *array, Datum *values, bool *nulls, int nitems, int typlen, bool typbyval, char typalign, bool freedata)
Datum array_get_element (Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Datum array_set_element (Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Datum array_get_slice (Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
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)
Datum array_ref (ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
ArrayType * array_set (ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Datum array_map (Datum arrayd, struct ExprState *exprstate, struct ExprContext *econtext, Oid retType, ArrayMapState *amstate)
void array_bitmap_copy (bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
ArrayType * construct_array (Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
ArrayType * construct_array_builtin (Datum *elems, int nelems, Oid elmtype)
ArrayType * construct_md_array (Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
ArrayType * construct_empty_array (Oid elmtype)
ExpandedArrayHeader * construct_empty_expanded_array (Oid element_type, MemoryContext parentcontext, ArrayMetaState *metacache)
void deconstruct_array (ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
void deconstruct_array_builtin (ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
bool array_contains_nulls (ArrayType *array)
ArrayBuildState * initArrayResult (Oid element_type, MemoryContext rcontext, bool subcontext)
ArrayBuildState * initArrayResultWithSize (Oid element_type, MemoryContext rcontext, bool subcontext, int initsize)
ArrayBuildState * accumArrayResult (ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Datum makeArrayResult (ArrayBuildState *astate, MemoryContext rcontext)
Datum makeMdArrayResult (ArrayBuildState *astate, int ndims, int *dims, int *lbs, MemoryContext rcontext, bool release)
ArrayBuildStateArr * initArrayResultArr (Oid array_type, Oid element_type, MemoryContext rcontext, bool subcontext)
ArrayBuildStateArr * accumArrayResultArr (ArrayBuildStateArr *astate, Datum dvalue, bool disnull, Oid array_type, MemoryContext rcontext)
Datum makeArrayResultArr (ArrayBuildStateArr *astate, MemoryContext rcontext, bool release)
ArrayBuildStateAny * initArrayResultAny (Oid input_type, MemoryContext rcontext, bool subcontext)
ArrayBuildStateAny * accumArrayResultAny (ArrayBuildStateAny *astate, Datum dvalue, bool disnull, Oid input_type, MemoryContext rcontext)
Datum makeArrayResultAny (ArrayBuildStateAny *astate, MemoryContext rcontext, bool release)
ArrayIterator array_create_iterator (ArrayType *arr, int slice_ndim, ArrayMetaState *mstate)
bool array_iterate (ArrayIterator iterator, Datum *value, bool *isnull)
void array_free_iterator (ArrayIterator iterator)
int ArrayGetOffset (int n, const int *dim, const int *lb, const int *indx)
int ArrayGetNItems (int ndim, const int *dims)
int ArrayGetNItemsSafe (int ndim, const int *dims, struct Node *escontext)
void ArrayCheckBounds (int ndim, const int *dims, const int *lb)
bool ArrayCheckBoundsSafe (int ndim, const int *dims, const int *lb, struct Node *escontext)
void mda_get_range (int n, int *span, const int *st, const int *endp)
void mda_get_prod (int n, const int *range, int *prod)
void mda_get_offset_values (int n, int *dist, const int *prod, const int *span)
int mda_next_tuple (int n, int *curr, const int *span)
int32 * ArrayGetIntegerTypmods (ArrayType *arr, int *n)
Datum expand_array (Datum arraydatum, MemoryContext parentcontext, ArrayMetaState *metacache)
ExpandedArrayHeader * DatumGetExpandedArray (Datum d)
ExpandedArrayHeader * DatumGetExpandedArrayX (Datum d, ArrayMetaState *metacache)
AnyArrayType * DatumGetAnyArrayP (Datum d)
void deconstruct_expanded_array (ExpandedArrayHeader *eah)

AARR_DIMS

Value:

#define VARATT_IS_EXPANDED_HEADER(PTR)

Definition at line 338 of file array.h.

AARR_ELEMTYPE

| #define AARR_ELEMTYPE | ( | | a | ) | | ---------------------- | - | | ---------------------------------------------------- | - |

AARR_HASNULL

| #define AARR_HASNULL | ( | | a | ) | | --------------------- | - | | ---------------------------------------------------- | - |

Value:

((a)->xpn.dvalues != NULL ? (a)->xpn.dnulls != NULL : ARR_HASNULL((a)->xpn.fvalue)) : \

Definition at line 331 of file array.h.

AARR_LBOUND

AARR_NDIM

ARR_DATA_OFFSET

ARR_DATA_PTR

ARR_DIMS

| #define ARR_DIMS | ( | | a | ) | ((int *) (((char *) (a)) + sizeof(ArrayType))) | | ----------------- | - | | ---------------------------------------------------- | - | --------------------------------------------------------------------------------------------------------------------------- |

ARR_ELEMTYPE

| #define ARR_ELEMTYPE | ( | | a | ) | ((a)->elemtype) | | --------------------- | - | | ---------------------------------------------------- | - | ------------------------------------------------------------------ |

ARR_HASNULL

| #define ARR_HASNULL | ( | | a | ) | ((a)->dataoffset != 0) | | -------------------- | - | | ---------------------------------------------------- | - | ------------------------------------------------------------------------- |

ARR_LBOUND

Value:

((int *) (((char *) (a)) + sizeof(ArrayType) + \

struct ArrayType ArrayType

Definition at line 296 of file array.h.

ARR_NDIM

| #define ARR_NDIM | ( | | a | ) | ((a)->ndim) | | ----------------- | - | | ---------------------------------------------------- | - | -------------------------------------------------------------- |

ARR_NULLBITMAP

| #define ARR_NULLBITMAP | ( | | a | ) | | ----------------------- | - | | ---------------------------------------------------- | - |

ARR_OVERHEAD_NONULLS

| #define ARR_OVERHEAD_NONULLS | ( | | ndims | ) | MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (ndims)) | | ------------------------------ | - | | ----- | - | ---------------------------------------------------------------------------------------------------------------------------------- |

ARR_OVERHEAD_WITHNULLS

| #define ARR_OVERHEAD_WITHNULLS | ( | | ndims, | | --------------------------------------------------------------- | - | | ------ | | | nitems | | | | | ) | | | |

ARR_SIZE

DatumGetArrayTypeP

DatumGetArrayTypePCopy

EA_MAGIC

#define EA_MAGIC 689375833 /* ID for debugging crosschecks */

MaxArraySize

MAXDIM

PG_GETARG_ANY_ARRAY_P

PG_GETARG_ARRAYTYPE_P

PG_GETARG_ARRAYTYPE_P_COPY

PG_GETARG_EXPANDED_ARRAY

PG_GETARG_EXPANDED_ARRAYX

PG_RETURN_ARRAYTYPE_P

PG_RETURN_EXPANDED_ARRAY

AnyArrayType

ArrayBuildState

ArrayBuildStateAny

ArrayBuildStateArr

ArrayIterator

ArrayMapState

ArrayMetaState

ArrayType

ExpandedArrayHeader

accumArrayResult()

Definition at line 5350 of file arrayfuncs.c.

5354{

5356

5357 if (astate == NULL)

5358 {

5359

5361 }

5362 else

5363 {

5365 }

5366

5368

5369

5371 {

5372 astate->alen *= 2;

5373

5376 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

5377 errmsg("array size exceeds the maximum allowed (%d)",

5381 astate->dnulls = (bool *)

5383 }

5384

5385

5386

5387

5388

5389

5390

5391

5392

5393 if (!disnull && !astate->typbyval)

5394 {

5395 if (astate->typlen == -1)

5397 else

5399 }

5400

5404

5406

5407 return astate;

5408}

ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)

Datum datumCopy(Datum value, bool typByVal, int typLen)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

#define PG_DETOAST_DATUM_COPY(datum)

Assert(PointerIsAligned(start, uint64))

void * repalloc(void *pointer, Size size)

#define AllocSizeIsValid(size)

static MemoryContext MemoryContextSwitchTo(MemoryContext context)

static Datum PointerGetDatum(const void *X)

References ArrayBuildState::alen, AllocSizeIsValid, Assert(), datumCopy(), ArrayBuildState::dnulls, ArrayBuildState::dvalues, ArrayBuildState::element_type, ereport, errcode(), errmsg(), ERROR, initArrayResult(), MaxAllocSize, ArrayBuildState::mcontext, MemoryContextSwitchTo(), ArrayBuildState::nelems, PG_DETOAST_DATUM_COPY, PointerGetDatum(), repalloc(), ArrayBuildState::typbyval, and ArrayBuildState::typlen.

Referenced by accumArrayResultAny(), array_agg_transfn(), array_positions(), array_to_datum_internal(), brin_minmax_multi_summary_out(), daitch_mokotoff_coding(), dblink_get_connections(), find_or_create_child_node(), multirange_agg_transfn(), optionListToArray(), parse_ident(), pg_get_statisticsobjdef_expressions(), pg_stats_ext_mcvlist_items(), PLySequence_ToArray_recurse(), populate_array_element(), range_agg_transfn(), regexp_split_to_array(), serialize_expr_stats(), split_text_accum_result(), transformRelOptions(), and tuple_data_split_internal().

accumArrayResultAny()

Definition at line 5829 of file arrayfuncs.c.

5833{

5834 if (astate == NULL)

5836

5839 dvalue, disnull,

5840 input_type, rcontext);

5841 else

5843 dvalue, disnull,

5844 input_type, rcontext);

5845

5846 return astate;

5847}

ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)

ArrayBuildStateAny * initArrayResultAny(Oid input_type, MemoryContext rcontext, bool subcontext)

ArrayBuildStateArr * accumArrayResultArr(ArrayBuildStateArr *astate, Datum dvalue, bool disnull, Oid array_type, MemoryContext rcontext)

ArrayBuildStateArr * arraystate

ArrayBuildState * scalarstate

References accumArrayResult(), accumArrayResultArr(), ArrayBuildStateAny::arraystate, initArrayResultAny(), and ArrayBuildStateAny::scalarstate.

Referenced by array_sort_internal(), ExecScanSubPlan(), and ExecSetParamPlan().

accumArrayResultArr()

Definition at line 5550 of file arrayfuncs.c.

5554{

5557 int *dims,

5558 *lbs,

5559 ndims,

5561 ndatabytes;

5563 int i;

5564

5565

5566

5567

5568

5569

5570 if (disnull)

5572 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),

5573 errmsg("cannot accumulate null arrays")));

5574

5575

5577

5578 if (astate == NULL)

5580 else

5582

5584

5585

5592

5593 if (astate->ndims == 0)

5594 {

5595

5596

5597

5598 if (ndims == 0)

5600 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

5601 errmsg("cannot accumulate empty arrays")));

5602 if (ndims + 1 > MAXDIM)

5604 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

5605 errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",

5606 ndims + 1, MAXDIM)));

5607

5608

5609

5610

5611

5612 astate->ndims = ndims + 1;

5613 astate->dims[0] = 0;

5614 memcpy(&astate->dims[1], dims, ndims * sizeof(int));

5615 astate->lbs[0] = 1;

5616 memcpy(&astate->lbs[1], lbs, ndims * sizeof(int));

5617

5618

5621 }

5622 else

5623 {

5624

5625 if (astate->ndims != ndims + 1)

5627 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

5628 errmsg("cannot accumulate arrays of different dimensionality")));

5629 for (i = 0; i < ndims; i++)

5630 {

5631 if (astate->dims[i + 1] != dims[i] || astate->lbs[i + 1] != lbs[i])

5633 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

5634 errmsg("cannot accumulate arrays of different dimensionality")));

5635 }

5636

5637

5638 if (astate->nbytes + ndatabytes > astate->abytes)

5639 {

5641 astate->nbytes + ndatabytes);

5643 }

5644 }

5645

5646

5647

5648

5649

5650

5651

5652 memcpy(astate->data + astate->nbytes, data, ndatabytes);

5653 astate->nbytes += ndatabytes;

5654

5655

5657 {

5659

5661 {

5662

5663

5664

5665

5669 NULL, 0,

5671 }

5672 else if (newnitems > astate->aitems)

5673 {

5677 }

5681 }

5682

5684 astate->dims[0] += 1;

5685

5687

5688

5691

5692 return astate;

5693}

#define ARR_NULLBITMAP(a)

#define DatumGetArrayTypeP(X)

#define ARR_DATA_OFFSET(a)

ArrayBuildStateArr * initArrayResultArr(Oid array_type, Oid element_type, MemoryContext rcontext, bool subcontext)

void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)

int ArrayGetNItems(int ndim, const int *dims)

void pfree(void *pointer)

static uint32 pg_nextpower2_32(uint32 num)

static Pointer DatumGetPointer(Datum X)

References ArrayBuildStateArr::abytes, ArrayBuildStateArr::aitems, arg, ARR_DATA_OFFSET, ARR_DATA_PTR, ARR_DIMS, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, ARR_NULLBITMAP, ARR_SIZE, array_bitmap_copy(), ArrayBuildStateArr::array_type, ArrayGetNItems(), Assert(), ArrayBuildStateArr::data, data, DatumGetArrayTypeP, DatumGetPointer(), ArrayBuildStateArr::dims, ereport, errcode(), errmsg(), ERROR, i, initArrayResultArr(), InvalidOid, ArrayBuildStateArr::lbs, Max, MAXDIM, ArrayBuildStateArr::mcontext, MemoryContextSwitchTo(), ArrayBuildStateArr::nbytes, ArrayBuildStateArr::ndims, ArrayBuildStateArr::nitems, nitems, ArrayBuildStateArr::nullbitmap, palloc(), pfree(), pg_nextpower2_32(), and repalloc().

Referenced by accumArrayResultAny(), and array_agg_array_transfn().

array_bitmap_copy()

void array_bitmap_copy ( bits8 * destbitmap,
int destoffset,
const bits8 * srcbitmap,
int srcoffset,
int nitems
)

Definition at line 4966 of file arrayfuncs.c.

4969{

4970 int destbitmask,

4971 destbitval,

4972 srcbitmask,

4973 srcbitval;

4974

4977 return;

4978 destbitmap += destoffset / 8;

4979 destbitmask = 1 << (destoffset % 8);

4980 destbitval = *destbitmap;

4981 if (srcbitmap)

4982 {

4983 srcbitmap += srcoffset / 8;

4984 srcbitmask = 1 << (srcoffset % 8);

4985 srcbitval = *srcbitmap;

4986 while (nitems-- > 0)

4987 {

4988 if (srcbitval & srcbitmask)

4989 destbitval |= destbitmask;

4990 else

4991 destbitval &= ~destbitmask;

4992 destbitmask <<= 1;

4993 if (destbitmask == 0x100)

4994 {

4995 *destbitmap++ = destbitval;

4996 destbitmask = 1;

4998 destbitval = *destbitmap;

4999 }

5000 srcbitmask <<= 1;

5001 if (srcbitmask == 0x100)

5002 {

5003 srcbitmap++;

5004 srcbitmask = 1;

5006 srcbitval = *srcbitmap;

5007 }

5008 }

5009 if (destbitmask != 1)

5010 *destbitmap = destbitval;

5011 }

5012 else

5013 {

5014 while (nitems-- > 0)

5015 {

5016 destbitval |= destbitmask;

5017 destbitmask <<= 1;

5018 if (destbitmask == 0x100)

5019 {

5020 *destbitmap++ = destbitval;

5021 destbitmask = 1;

5023 destbitval = *destbitmap;

5024 }

5025 }

5026 if (destbitmask != 1)

5027 *destbitmap = destbitval;

5028 }

5029}

References Assert(), and nitems.

Referenced by accumArrayResultArr(), array_agg_array_combine(), array_cat(), array_extract_slice(), array_insert_slice(), array_set_element(), array_set_slice(), ExecEvalArrayExpr(), and makeArrayResultArr().

array_contains_nulls()

bool array_contains_nulls ( ArrayType * array )

Definition at line 3767 of file arrayfuncs.c.

3768{

3769 int nelems;

3771 int bitmask;

3772

3773

3775 return false;

3776

3778

3780

3781

3782 while (nelems >= 8)

3783 {

3784 if (*bitmap != 0xFF)

3785 return true;

3786 bitmap++;

3787 nelems -= 8;

3788 }

3789

3790

3791 bitmask = 1;

3792 while (nelems > 0)

3793 {

3794 if ((*bitmap & bitmask) == 0)

3795 return true;

3796 bitmask <<= 1;

3797 nelems--;

3798 }

3799

3800 return false;

3801}

References ARR_DIMS, ARR_HASNULL, ARR_NDIM, ARR_NULLBITMAP, and ArrayGetNItems().

Referenced by _arrq_cons(), _lca(), _lt_q_regex(), _ltree_compress(), array_fill_internal(), array_iterator(), array_position_common(), array_positions(), ArrayGetIntegerTypmods(), arrq_cons(), cube_a_f8(), cube_a_f8_f8(), cube_subset(), get_jsonb_path_all(), get_path_all(), getWeights(), lt_q_regex(), pg_isolation_test_session_is_blocked(), pg_logical_slot_get_changes_guts(), sanity_check_array(), sanity_check_tid_array(), stats_check_arg_array(), text_to_stavalues(), width_bucket_array(), and worker_spi_launch().

array_create_iterator()

Definition at line 4597 of file arrayfuncs.c.

4598{

4600

4601

4602

4603

4605 if (slice_ndim < 0 || slice_ndim > ARR_NDIM(arr))

4606 elog(ERROR, "invalid arguments to array_create_iterator");

4607

4608

4609

4610

4611 iterator->arr = arr;

4614

4615 if (mstate != NULL)

4616 {

4618

4622 }

4623 else

4628

4629

4630

4631

4633

4634 if (slice_ndim > 0)

4635 {

4636

4637

4638

4639

4640

4643

4644

4645

4646

4649

4650

4651

4652

4657 }

4658

4659

4660

4661

4662

4665

4666 return iterator;

4667}

#define PointerIsValid(pointer)

void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)

void * palloc0(Size size)

References ArrayIteratorData::arr, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_LBOUND, ARR_NDIM, ARR_NULLBITMAP, ArrayGetNItems(), Assert(), ArrayIteratorData::current_item, ArrayIteratorData::data_ptr, ArrayMetaState::element_type, elog, ERROR, get_typlenbyvalalign(), ArrayIteratorData::nitems, ArrayIteratorData::nullbitmap, palloc(), palloc0(), PointerIsValid, ArrayIteratorData::slice_dims, ArrayIteratorData::slice_lbound, ArrayIteratorData::slice_len, ArrayIteratorData::slice_ndim, ArrayIteratorData::slice_nulls, ArrayIteratorData::slice_values, ArrayIteratorData::typalign, ArrayMetaState::typalign, ArrayIteratorData::typbyval, ArrayMetaState::typbyval, ArrayIteratorData::typlen, and ArrayMetaState::typlen.

Referenced by array_position_common(), array_positions(), array_sort_internal(), and exec_stmt_foreach_a().

array_free_iterator()

array_get_element()

Datum array_get_element ( Datum arraydatum,
int nSubscripts,
int * indx,
int arraytyplen,
int elmlen,
bool elmbyval,
char elmalign,
bool * isNull
)

Definition at line 1820 of file arrayfuncs.c.

1828{

1829 int i,

1830 ndim,

1831 *dim,

1832 *lb,

1833 offset,

1834 fixedDim[1],

1835 fixedLb[1];

1836 char *arraydataptr,

1837 *retptr;

1838 bits8 *arraynullsptr;

1839

1840 if (arraytyplen > 0)

1841 {

1842

1843

1844

1845 ndim = 1;

1846 fixedDim[0] = arraytyplen / elmlen;

1847 fixedLb[0] = 0;

1848 dim = fixedDim;

1849 lb = fixedLb;

1851 arraynullsptr = NULL;

1852 }

1854 {

1855

1857 nSubscripts,

1858 indx,

1859 arraytyplen,

1860 elmlen,

1861 elmbyval,

1862 elmalign,

1863 isNull);

1864 }

1865 else

1866 {

1867

1869

1875 }

1876

1877

1878

1879

1880 if (ndim != nSubscripts || ndim <= 0 || ndim > MAXDIM)

1881 {

1882 *isNull = true;

1883 return (Datum) 0;

1884 }

1885 for (i = 0; i < ndim; i++)

1886 {

1887 if (indx[i] < lb[i] || indx[i] >= (dim[i] + lb[i]))

1888 {

1889 *isNull = true;

1890 return (Datum) 0;

1891 }

1892 }

1893

1894

1895

1896

1897 offset = ArrayGetOffset(nSubscripts, dim, lb, indx);

1898

1899

1900

1901

1903 {

1904 *isNull = true;

1905 return (Datum) 0;

1906 }

1907

1908

1909

1910

1911 *isNull = false;

1912 retptr = array_seek(arraydataptr, 0, arraynullsptr, offset,

1913 elmlen, elmbyval, elmalign);

1914 return ArrayCast(retptr, elmbyval, elmlen);

1915}

static bool array_get_isnull(const bits8 *nullbitmap, int offset)

static Datum array_get_element_expanded(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)

static Datum ArrayCast(char *value, bool byval, int len)

static char * array_seek(char *ptr, int offset, bits8 *nullbitmap, int nitems, int typlen, bool typbyval, char typalign)

int ArrayGetOffset(int n, const int *dim, const int *lb, const int *indx)

#define VARATT_IS_EXTERNAL_EXPANDED(PTR)

References ARR_DATA_PTR, ARR_DIMS, ARR_LBOUND, ARR_NDIM, ARR_NULLBITMAP, array_get_element_expanded(), array_get_isnull(), array_seek(), ArrayCast(), ArrayGetOffset(), DatumGetArrayTypeP, DatumGetPointer(), i, MAXDIM, and VARATT_IS_EXTERNAL_EXPANDED.

Referenced by array_ref(), array_subscript_fetch(), array_subscript_fetch_old(), ATExecAlterColumnType(), and RelationBuildTupleDesc().

array_get_slice()

Datum array_get_slice ( Datum arraydatum,
int nSubscripts,
int * upperIndx,
int * lowerIndx,
bool * upperProvided,
bool * lowerProvided,
int arraytyplen,
int elmlen,
bool elmbyval,
char elmalign
)

Definition at line 2030 of file arrayfuncs.c.

2040{

2043 int i,

2044 ndim,

2045 *dim,

2046 *lb,

2047 *newlb;

2048 int fixedDim[1],

2049 fixedLb[1];

2050 Oid elemtype;

2051 char *arraydataptr;

2052 bits8 *arraynullsptr;

2053 int32 dataoffset;

2054 int bytes,

2056

2057 if (arraytyplen > 0)

2058 {

2059

2060

2061

2062

2063

2064

2066 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

2067 errmsg("slices of fixed-length arrays not implemented")));

2068

2069

2070

2071

2072

2073

2074 ndim = 1;

2075 fixedDim[0] = arraytyplen / elmlen;

2076 fixedLb[0] = 0;

2077 dim = fixedDim;

2078 lb = fixedLb;

2081 arraynullsptr = NULL;

2082 }

2083 else

2084 {

2085

2087

2094 }

2095

2096

2097

2098

2099

2100

2101 if (ndim < nSubscripts || ndim <= 0 || ndim > MAXDIM)

2103

2104 for (i = 0; i < nSubscripts; i++)

2105 {

2106 if (!lowerProvided[i] || lowerIndx[i] < lb[i])

2107 lowerIndx[i] = lb[i];

2108 if (!upperProvided[i] || upperIndx[i] >= (dim[i] + lb[i]))

2109 upperIndx[i] = dim[i] + lb[i] - 1;

2110 if (lowerIndx[i] > upperIndx[i])

2112 }

2113

2114 for (; i < ndim; i++)

2115 {

2116 lowerIndx[i] = lb[i];

2117 upperIndx[i] = dim[i] + lb[i] - 1;

2118 if (lowerIndx[i] > upperIndx[i])

2120 }

2121

2122 mda_get_range(ndim, span, lowerIndx, upperIndx);

2123

2125 ndim, dim, lb,

2126 lowerIndx, upperIndx,

2127 elmlen, elmbyval, elmalign);

2128

2129

2130

2131

2132

2133 if (arraynullsptr)

2134 {

2136 bytes += dataoffset;

2137 }

2138 else

2139 {

2140 dataoffset = 0;

2142 }

2143

2146 newarray->ndim = ndim;

2148 newarray->elemtype = elemtype;

2149 memcpy(ARR_DIMS(newarray), span, ndim * sizeof(int));

2150

2151

2152

2153

2154

2156 for (i = 0; i < ndim; i++)

2157 newlb[i] = 1;

2158

2160 ndim, dim, lb,

2161 arraydataptr, arraynullsptr,

2162 lowerIndx, upperIndx,

2163 elmlen, elmbyval, elmalign);

2164

2166}

#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)

#define ARR_OVERHEAD_NONULLS(ndims)

ArrayType * construct_empty_array(Oid elmtype)

static int array_slice_size(char *arraydataptr, bits8 *arraynullsptr, int ndim, int *dim, int *lb, int *st, int *endp, int typlen, bool typbyval, char typalign)

static void array_extract_slice(ArrayType *newarray, int ndim, int *dim, int *lb, char *arraydataptr, bits8 *arraynullsptr, int *st, int *endp, int typlen, bool typbyval, char typalign)

void mda_get_range(int n, int *span, const int *st, const int *endp)

#define SET_VARSIZE(PTR, len)

References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_LBOUND, ARR_NDIM, ARR_NULLBITMAP, ARR_OVERHEAD_NONULLS, ARR_OVERHEAD_WITHNULLS, array_extract_slice(), array_slice_size(), ArrayGetNItems(), construct_empty_array(), ArrayType::dataoffset, DatumGetArrayTypeP, DatumGetPointer(), ArrayType::elemtype, ereport, errcode(), errmsg(), ERROR, i, InvalidOid, MAXDIM, mda_get_range(), ArrayType::ndim, palloc0(), PointerGetDatum(), and SET_VARSIZE.

Referenced by array_subscript_fetch_old_slice(), array_subscript_fetch_slice(), and trim_array().

array_iterate()

Definition at line 4676 of file arrayfuncs.c.

4677{

4678

4680 return false;

4681

4683 {

4684

4685

4686

4688 {

4689 *isnull = true;

4691 }

4692 else

4693 {

4694

4695 char *p = iterator->data_ptr;

4696

4697 *isnull = false;

4699

4700

4704 }

4705 }

4706 else

4707 {

4708

4709

4710

4714 char *p = iterator->data_ptr;

4715 int i;

4716

4718 {

4721 {

4722 nulls[i] = true;

4724 }

4725 else

4726 {

4727 nulls[i] = false;

4729

4730

4733 }

4734 }

4735

4737

4739 nulls,

4747

4748 *isnull = false;

4750 }

4751

4752 return true;

4753}

ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)

static Datum values[MAXATTR]

#define att_align_nominal(cur_offset, attalign)

#define att_addlength_pointer(cur_offset, attlen, attptr)

static Datum fetch_att(const void *T, bool attbyval, int attlen)

References ArrayIteratorData::arr, ARR_ELEMTYPE, array_get_isnull(), att_addlength_pointer, att_align_nominal, construct_md_array(), ArrayIteratorData::current_item, ArrayIteratorData::data_ptr, fetch_att(), i, ArrayIteratorData::nitems, ArrayIteratorData::nullbitmap, PointerGetDatum(), ArrayIteratorData::slice_dims, ArrayIteratorData::slice_lbound, ArrayIteratorData::slice_len, ArrayIteratorData::slice_ndim, ArrayIteratorData::slice_nulls, ArrayIteratorData::slice_values, ArrayIteratorData::typalign, ArrayIteratorData::typbyval, ArrayIteratorData::typlen, value, and values.

Referenced by array_position_common(), array_positions(), array_sort_internal(), and exec_stmt_foreach_a().

array_map()

Definition at line 3201 of file arrayfuncs.c.

3204{

3208 bool *nulls;

3209 int *dim;

3210 int ndim;

3212 int i;

3213 int32 nbytes = 0;

3214 int32 dataoffset;

3215 bool hasnulls;

3216 Oid inpType;

3217 int inp_typlen;

3218 bool inp_typbyval;

3219 char inp_typalign;

3220 int typlen;

3221 bool typbyval;

3228

3233

3234

3236 {

3237

3239 }

3240

3241

3242

3243

3244

3245

3246 inp_extra = &amstate->inp_extra;

3247 ret_extra = &amstate->ret_extra;

3248

3250 {

3256 }

3257 inp_typlen = inp_extra->typlen;

3258 inp_typbyval = inp_extra->typbyval;

3259 inp_typalign = inp_extra->typalign;

3260

3262 {

3268 }

3269 typlen = ret_extra->typlen;

3270 typbyval = ret_extra->typbyval;

3272

3273

3275 nulls = (bool *) palloc(nitems * sizeof(bool));

3276

3277

3279 hasnulls = false;

3280

3282 {

3283

3284 *transform_source =

3286 inp_typlen, inp_typbyval, inp_typalign);

3287

3288

3290

3291 if (nulls[i])

3292 hasnulls = true;

3293 else

3294 {

3295

3296 if (typlen == -1)

3298

3301

3304 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

3305 errmsg("array size exceeds the maximum allowed (%d)",

3307 }

3308 }

3309

3310

3311 if (hasnulls)

3312 {

3314 nbytes += dataoffset;

3315 }

3316 else

3317 {

3318 dataoffset = 0;

3320 }

3323 result->ndim = ndim;

3328

3332 false);

3333

3334

3335

3336

3339

3341}

AnyArrayType * DatumGetAnyArrayP(Datum d)

static Datum array_iter_next(array_iter *it, bool *isnull, int i, int elmlen, bool elmbyval, char elmalign)

static void array_iter_setup(array_iter *it, AnyArrayType *a)

void CopyArrayEls(ArrayType *array, Datum *values, bool *nulls, int nitems, int typlen, bool typbyval, char typalign, bool freedata)

static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)

#define PG_DETOAST_DATUM(datum)

bool * innermost_casenull

Datum * innermost_caseval

#define att_addlength_datum(cur_offset, attlen, attdatum)

References AARR_DIMS, AARR_ELEMTYPE, AARR_LBOUND, AARR_NDIM, AllocSizeIsValid, ARR_DIMS, ARR_LBOUND, ARR_OVERHEAD_NONULLS, ARR_OVERHEAD_WITHNULLS, array_iter_next(), array_iter_setup(), ArrayGetNItems(), att_addlength_datum, att_align_nominal, construct_empty_array(), CopyArrayEls(), ArrayType::dataoffset, DatumGetAnyArrayP(), ArrayMetaState::element_type, ArrayType::elemtype, ereport, errcode(), errmsg(), ERROR, ExecEvalExpr(), get_typlenbyvalalign(), i, ExprState::innermost_casenull, ExprState::innermost_caseval, ArrayMapState::inp_extra, MaxAllocSize, ArrayType::ndim, nitems, palloc(), palloc0(), pfree(), PG_DETOAST_DATUM, PointerGetDatum(), ArrayMapState::ret_extra, SET_VARSIZE, typalign, ArrayMetaState::typalign, ArrayMetaState::typbyval, ArrayMetaState::typlen, and values.

Referenced by ExecEvalArrayCoerce().

array_ref()

Datum array_ref ( ArrayType * array,
int nSubscripts,
int * indx,
int arraytyplen,
int elmlen,
bool elmbyval,
char elmalign,
bool * isNull
)

Definition at line 3146 of file arrayfuncs.c.

3149{

3151 arraytyplen, elmlen, elmbyval, elmalign,

3152 isNull);

3153}

Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)

References array_get_element(), and PointerGetDatum().

Referenced by GUCArrayAdd(), GUCArrayDelete(), GUCArrayReset(), pg_get_functiondef(), and TransformGUCArray().

array_set()

ArrayType * array_set ( ArrayType * array,
int nSubscripts,
int * indx,
Datum dataValue,
bool isNull,
int arraytyplen,
int elmlen,
bool elmbyval,
char elmalign
)

Definition at line 3163 of file arrayfuncs.c.

3166{

3168 nSubscripts, indx,

3169 dataValue, isNull,

3170 arraytyplen,

3171 elmlen, elmbyval, elmalign));

3172}

Datum array_set_element(Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)

References array_set_element(), DatumGetArrayTypeP, and PointerGetDatum().

Referenced by GUCArrayAdd(), GUCArrayDelete(), GUCArrayReset(), and pg_extension_config_dump().

array_set_element()

Datum array_set_element ( Datum arraydatum,
int nSubscripts,
int * indx,
Datum dataValue,
bool isNull,
int arraytyplen,
int elmlen,
bool elmbyval,
char elmalign
)

Definition at line 2201 of file arrayfuncs.c.

2210{

2213 int i,

2214 ndim,

2217 offset;

2218 char *elt_ptr;

2219 bool newhasnulls;

2220 bits8 *oldnullbitmap;

2221 int oldnitems,

2222 newnitems,

2223 olddatasize,

2224 newsize,

2225 olditemlen,

2226 newitemlen,

2227 overheadlen,

2228 oldoverheadlen,

2229 addedbefore,

2230 addedafter,

2231 lenbefore,

2232 lenafter;

2233

2234 if (arraytyplen > 0)

2235 {

2236

2237

2238

2239

2240 char *resultarray;

2241

2242 if (nSubscripts != 1)

2244 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2245 errmsg("wrong number of array subscripts")));

2246

2247 if (indx[0] < 0 || indx[0] >= arraytyplen / elmlen)

2249 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2250 errmsg("array subscript out of range")));

2251

2252 if (isNull)

2254 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),

2255 errmsg("cannot assign null value to an element of a fixed-length array")));

2256

2257 resultarray = (char *) palloc(arraytyplen);

2258 memcpy(resultarray, DatumGetPointer(arraydatum), arraytyplen);

2259 elt_ptr = (char *) resultarray + indx[0] * elmlen;

2260 ArrayCastAndSet(dataValue, elmlen, elmbyval, elmalign, elt_ptr);

2262 }

2263

2264 if (nSubscripts <= 0 || nSubscripts > MAXDIM)

2266 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2267 errmsg("wrong number of array subscripts")));

2268

2269

2270 if (elmlen == -1 && !isNull)

2272

2274 {

2275

2277 nSubscripts,

2278 indx,

2279 dataValue,

2280 isNull,

2281 arraytyplen,

2282 elmlen,

2283 elmbyval,

2284 elmalign);

2285 }

2286

2287

2289

2291

2292

2293

2294

2295

2296

2297 if (ndim == 0)

2298 {

2300

2301 for (i = 0; i < nSubscripts; i++)

2302 {

2303 dim[i] = 1;

2304 lb[i] = indx[i];

2305 }

2306

2308 nSubscripts, dim, lb,

2309 elmtype,

2310 elmlen, elmbyval, elmalign));

2311 }

2312

2313 if (ndim != nSubscripts)

2315 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2316 errmsg("wrong number of array subscripts")));

2317

2318

2319 memcpy(dim, ARR_DIMS(array), ndim * sizeof(int));

2320 memcpy(lb, ARR_LBOUND(array), ndim * sizeof(int));

2321

2322 newhasnulls = (ARR_HASNULL(array) || isNull);

2323 addedbefore = addedafter = 0;

2324

2325

2326

2327

2328

2329

2330

2331 if (ndim == 1)

2332 {

2333 if (indx[0] < lb[0])

2334 {

2335

2336

2340 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

2341 errmsg("array size exceeds the maximum allowed (%d)",

2343 lb[0] = indx[0];

2344 if (addedbefore > 1)

2345 newhasnulls = true;

2346 }

2347 if (indx[0] >= (dim[0] + lb[0]))

2348 {

2349

2350

2355 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

2356 errmsg("array size exceeds the maximum allowed (%d)",

2358 if (addedafter > 1)

2359 newhasnulls = true;

2360 }

2361 }

2362 else

2363 {

2364

2365

2366

2367

2368 for (i = 0; i < ndim; i++)

2369 {

2370 if (indx[i] < lb[i] ||

2371 indx[i] >= (dim[i] + lb[i]))

2373 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2374 errmsg("array subscript out of range")));

2375 }

2376 }

2377

2378

2381

2382

2383

2384

2385 if (newhasnulls)

2387 else

2392 olddatasize = ARR_SIZE(array) - oldoverheadlen;

2393 if (addedbefore)

2394 {

2395 offset = 0;

2396 lenbefore = 0;

2397 olditemlen = 0;

2398 lenafter = olddatasize;

2399 }

2400 else if (addedafter)

2401 {

2402 offset = oldnitems;

2403 lenbefore = olddatasize;

2404 olditemlen = 0;

2405 lenafter = 0;

2406 }

2407 else

2408 {

2409 offset = ArrayGetOffset(nSubscripts, dim, lb, indx);

2411 elmlen, elmbyval, elmalign);

2412 lenbefore = (int) (elt_ptr - ARR_DATA_PTR(array));

2414 olditemlen = 0;

2415 else

2416 {

2419 }

2420 lenafter = (int) (olddatasize - lenbefore - olditemlen);

2421 }

2422

2423 if (isNull)

2424 newitemlen = 0;

2425 else

2426 {

2429 }

2430

2431 newsize = overheadlen + lenbefore + newitemlen + lenafter;

2432

2433

2434

2435

2438 newarray->ndim = ndim;

2439 newarray->dataoffset = newhasnulls ? overheadlen : 0;

2441 memcpy(ARR_DIMS(newarray), dim, ndim * sizeof(int));

2442 memcpy(ARR_LBOUND(newarray), lb, ndim * sizeof(int));

2443

2444

2445

2446

2447 memcpy((char *) newarray + overheadlen,

2448 (char *) array + oldoverheadlen,

2449 lenbefore);

2450 if (!isNull)

2452 (char *) newarray + overheadlen + lenbefore);

2453 memcpy((char *) newarray + overheadlen + lenbefore + newitemlen,

2454 (char *) array + oldoverheadlen + lenbefore + olditemlen,

2455 lenafter);

2456

2457

2458

2459

2460

2461

2462

2463 if (newhasnulls)

2464 {

2466

2467

2468

2469 if (addedafter)

2471 else

2473

2474 if (addedbefore)

2476 oldnullbitmap, 0,

2477 oldnitems);

2478 else

2479 {

2481 oldnullbitmap, 0,

2482 offset);

2483 if (addedafter == 0)

2485 oldnullbitmap, offset + 1,

2486 oldnitems - offset - 1);

2487 }

2488 }

2489

2491}

static Datum array_set_element_expanded(Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)

static void array_set_isnull(bits8 *nullbitmap, int offset, bool isNull)

static int ArrayCastAndSet(Datum src, int typlen, bool typbyval, char typalign, char *dest)

void ArrayCheckBounds(int ndim, const int *dims, const int *lb)

static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)

static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)

References ARR_DATA_OFFSET, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, ARR_NULLBITMAP, ARR_OVERHEAD_NONULLS, ARR_OVERHEAD_WITHNULLS, ARR_SIZE, array_bitmap_copy(), array_get_isnull(), array_seek(), array_set_element_expanded(), array_set_isnull(), ArrayCastAndSet(), ArrayCheckBounds(), ArrayGetNItems(), ArrayGetOffset(), att_addlength_datum, att_addlength_pointer, att_align_nominal, construct_md_array(), ArrayType::dataoffset, DatumGetArrayTypeP, DatumGetPointer(), ArrayType::elemtype, ereport, errcode(), errmsg(), ERROR, i, MaxArraySize, MAXDIM, ArrayType::ndim, palloc(), palloc0(), pg_add_s32_overflow(), PG_DETOAST_DATUM, pg_sub_s32_overflow(), PointerGetDatum(), SET_VARSIZE, and VARATT_IS_EXTERNAL_EXPANDED.

Referenced by array_append(), array_prepend(), array_set(), and array_subscript_assign().

array_set_slice()

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
)

Definition at line 2806 of file arrayfuncs.c.

2818{

2822 int i,

2823 ndim,

2827 bool newhasnulls;

2829 nsrcitems,

2830 olddatasize,

2831 newsize,

2832 olditemsize,

2833 newitemsize,

2834 overheadlen,

2835 oldoverheadlen,

2836 addedbefore,

2837 addedafter,

2838 lenbefore,

2839 lenafter,

2840 itemsbefore,

2841 itemsafter,

2842 nolditems;

2843

2844

2845 if (isNull)

2846 return arraydatum;

2847

2848 if (arraytyplen > 0)

2849 {

2850

2851

2852

2854 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

2855 errmsg("updates on slices of fixed-length arrays not implemented")));

2856 }

2857

2858

2861

2862

2863

2865

2866

2867

2868

2869

2870

2871 if (ndim == 0)

2872 {

2874 bool *dnulls;

2875 int nelems;

2877

2878 deconstruct_array(srcArray, elmtype, elmlen, elmbyval, elmalign,

2879 &dvalues, &dnulls, &nelems);

2880

2881 for (i = 0; i < nSubscripts; i++)

2882 {

2883 if (!upperProvided[i] || !lowerProvided[i])

2885 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2886 errmsg("array slice subscript must provide both boundaries"),

2887 errdetail("When assigning to a slice of an empty array value,"

2888 " slice boundaries must be fully specified.")));

2889

2890

2894 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

2895 errmsg("array size exceeds the maximum allowed (%d)",

2897

2898 lb[i] = lowerIndx[i];

2899 }

2900

2901

2904 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2905 errmsg("source array too small")));

2906

2908 dim, lb, elmtype,

2909 elmlen, elmbyval, elmalign));

2910 }

2911

2912 if (ndim < nSubscripts || ndim <= 0 || ndim > MAXDIM)

2914 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2915 errmsg("wrong number of array subscripts")));

2916

2917

2918 memcpy(dim, ARR_DIMS(array), ndim * sizeof(int));

2919 memcpy(lb, ARR_LBOUND(array), ndim * sizeof(int));

2920

2922 addedbefore = addedafter = 0;

2923

2924

2925

2926

2927

2928

2929

2930 if (ndim == 1)

2931 {

2932 Assert(nSubscripts == 1);

2933 if (!lowerProvided[0])

2934 lowerIndx[0] = lb[0];

2935 if (!upperProvided[0])

2936 upperIndx[0] = dim[0] + lb[0] - 1;

2937 if (lowerIndx[0] > upperIndx[0])

2939 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2940 errmsg("upper bound cannot be less than lower bound")));

2941 if (lowerIndx[0] < lb[0])

2942 {

2943

2944

2948 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

2949 errmsg("array size exceeds the maximum allowed (%d)",

2951 lb[0] = lowerIndx[0];

2952 if (addedbefore > 1)

2953 newhasnulls = true;

2954 }

2955 if (upperIndx[0] >= (dim[0] + lb[0]))

2956 {

2957

2958

2963 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

2964 errmsg("array size exceeds the maximum allowed (%d)",

2966 if (addedafter > 1)

2967 newhasnulls = true;

2968 }

2969 }

2970 else

2971 {

2972

2973

2974

2975

2976 for (i = 0; i < nSubscripts; i++)

2977 {

2978 if (!lowerProvided[i])

2979 lowerIndx[i] = lb[i];

2980 if (!upperProvided[i])

2981 upperIndx[i] = dim[i] + lb[i] - 1;

2982 if (lowerIndx[i] > upperIndx[i])

2984 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2985 errmsg("upper bound cannot be less than lower bound")));

2986 if (lowerIndx[i] < lb[i] ||

2987 upperIndx[i] >= (dim[i] + lb[i]))

2989 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

2990 errmsg("array subscript out of range")));

2991 }

2992

2993 for (; i < ndim; i++)

2994 {

2995 lowerIndx[i] = lb[i];

2996 upperIndx[i] = dim[i] + lb[i] - 1;

2997 if (lowerIndx[i] > upperIndx[i])

2999 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

3000 errmsg("upper bound cannot be less than lower bound")));

3001 }

3002 }

3003

3004

3007

3008

3009

3010

3011

3012 mda_get_range(ndim, span, lowerIndx, upperIndx);

3016 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

3017 errmsg("source array too small")));

3018

3019

3020

3021

3022

3023 if (newhasnulls)

3025 else

3029 elmlen, elmbyval, elmalign);

3031 olddatasize = ARR_SIZE(array) - oldoverheadlen;

3032 if (ndim > 1)

3033 {

3034

3035

3036

3037

3040 ndim, dim, lb,

3041 lowerIndx, upperIndx,

3042 elmlen, elmbyval, elmalign);

3043 lenbefore = lenafter = 0;

3044 itemsbefore = itemsafter = nolditems = 0;

3045 }

3046 else

3047 {

3048

3049

3050

3051

3053 int oldub = oldlb + ARR_DIMS(array)[0] - 1;

3054 int slicelb = Max(oldlb, lowerIndx[0]);

3055 int sliceub = Min(oldub, upperIndx[0]);

3058

3059

3060 itemsbefore = Min(slicelb, oldub + 1) - oldlb;

3062 itemsbefore,

3063 elmlen, elmbyval, elmalign);

3064

3065 if (slicelb > sliceub)

3066 {

3067 nolditems = 0;

3068 olditemsize = 0;

3069 }

3070 else

3071 {

3072 nolditems = sliceub - slicelb + 1;

3074 itemsbefore, oldarraybitmap,

3075 nolditems,

3076 elmlen, elmbyval, elmalign);

3077 }

3078

3079 itemsafter = oldub + 1 - Max(sliceub + 1, oldlb);

3080 lenafter = olddatasize - lenbefore - olditemsize;

3081 }

3082

3083 newsize = overheadlen + olddatasize - olditemsize + newitemsize;

3084

3087 newarray->ndim = ndim;

3088 newarray->dataoffset = newhasnulls ? overheadlen : 0;

3090 memcpy(ARR_DIMS(newarray), dim, ndim * sizeof(int));

3091 memcpy(ARR_LBOUND(newarray), lb, ndim * sizeof(int));

3092

3093 if (ndim > 1)

3094 {

3095

3096

3097

3098

3100 ndim, dim, lb,

3101 lowerIndx, upperIndx,

3102 elmlen, elmbyval, elmalign);

3103 }

3104 else

3105 {

3106

3107 memcpy((char *) newarray + overheadlen,

3108 (char *) array + oldoverheadlen,

3109 lenbefore);

3110 memcpy((char *) newarray + overheadlen + lenbefore,

3112 newitemsize);

3113 memcpy((char *) newarray + overheadlen + lenbefore + newitemsize,

3114 (char *) array + oldoverheadlen + lenbefore + olditemsize,

3115 lenafter);

3116

3117 if (newhasnulls)

3118 {

3121

3122

3124 oldnullbitmap, 0,

3125 itemsbefore);

3128 nsrcitems);

3129 array_bitmap_copy(newnullbitmap, addedbefore + itemsbefore + nolditems,

3130 oldnullbitmap, itemsbefore + nolditems,

3131 itemsafter);

3132 }

3133 }

3134

3136}

void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)

static void array_insert_slice(ArrayType *destArray, ArrayType *origArray, ArrayType *srcArray, int ndim, int *dim, int *lb, int *st, int *endp, int typlen, bool typbyval, char typalign)

static int array_nelems_size(char *ptr, int offset, bits8 *nullbitmap, int nitems, int typlen, bool typbyval, char typalign)

int errdetail(const char *fmt,...)

References ARR_DATA_OFFSET, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, ARR_NULLBITMAP, ARR_OVERHEAD_NONULLS, ARR_OVERHEAD_WITHNULLS, ARR_SIZE, array_bitmap_copy(), array_insert_slice(), array_nelems_size(), array_slice_size(), ArrayCheckBounds(), ArrayGetNItems(), Assert(), construct_md_array(), ArrayType::dataoffset, DatumGetArrayTypeP, deconstruct_array(), ArrayType::elemtype, ereport, errcode(), errdetail(), errmsg(), ERROR, i, Max, MaxArraySize, MAXDIM, mda_get_range(), Min, ArrayType::ndim, nitems, palloc0(), pg_add_s32_overflow(), pg_sub_s32_overflow(), PointerGetDatum(), and SET_VARSIZE.

Referenced by array_subscript_assign_slice().

ArrayCheckBounds()

void ArrayCheckBounds ( int ndim,
const int * dims,
const int * lb
)

Definition at line 117 of file arrayutils.c.

118{

120}

bool ArrayCheckBoundsSafe(int ndim, const int *dims, const int *lb, struct Node *escontext)

References ArrayCheckBoundsSafe().

Referenced by array_cat(), array_fill_internal(), array_recv(), array_set_element(), array_set_element_expanded(), array_set_slice(), construct_md_array(), ExecEvalArrayExpr(), and makeArrayResultArr().

ArrayCheckBoundsSafe()

bool ArrayCheckBoundsSafe ( int ndim,
const int * dims,
const int * lb,
struct Node * escontext
)

Definition at line 127 of file arrayutils.c.

129{

130 int i;

131

132 for (i = 0; i < ndim; i++)

133 {

134

136

138 ereturn(escontext, false,

139 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

140 errmsg("array lower bound is too large: %d",

141 lb[i])));

142 }

143

144 return true;

145}

#define PG_USED_FOR_ASSERTS_ONLY

#define ereturn(context, dummy_value,...)

References ereturn, errcode(), errmsg(), i, pg_add_s32_overflow(), and PG_USED_FOR_ASSERTS_ONLY.

Referenced by ArrayCheckBounds().

ArrayGetIntegerTypmods()

Definition at line 233 of file arrayutils.c.

234{

236 Datum *elem_values;

237 int i;

238

241 (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),

242 errmsg("typmod array must be type cstring[]")));

243

246 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

247 errmsg("typmod array must be one-dimensional")));

248

251 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),

252 errmsg("typmod array must not contain nulls")));

253

255

257

258 for (i = 0; i < *n; i++)

260

261 pfree(elem_values);

262

263 return result;

264}

bool array_contains_nulls(ArrayType *array)

void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)

int32 pg_strtoint32(const char *s)

static char * DatumGetCString(Datum X)

References ARR_ELEMTYPE, ARR_NDIM, array_contains_nulls(), DatumGetCString(), deconstruct_array_builtin(), ereport, errcode(), errmsg(), ERROR, i, palloc(), pfree(), and pg_strtoint32().

Referenced by anybit_typmodin(), anychar_typmodin(), anytime_typmodin(), anytimestamp_typmodin(), intervaltypmodin(), and numerictypmodin().

ArrayGetNItems()

int ArrayGetNItems ( int ndim,
const int * dims
)

Definition at line 57 of file arrayutils.c.

58{

60}

int ArrayGetNItemsSafe(int ndim, const int *dims, struct Node *escontext)

References ArrayGetNItemsSafe().

Referenced by _arrq_cons(), _lca(), _lt_q_regex(), _ltree_compress(), accumArrayResultArr(), array_cardinality(), array_cat(), array_cmp(), array_contain_compare(), array_contains_nulls(), array_create_iterator(), array_eq(), array_fill_internal(), array_get_slice(), array_insert_slice(), array_iterator(), array_map(), array_out(), array_recv(), array_replace_internal(), array_send(), array_set_element(), array_set_element_expanded(), array_set_slice(), array_slice_size(), array_to_json_internal(), array_to_jsonb_internal(), array_to_text_internal(), array_unnest(), arrq_cons(), clause_is_strict_for(), construct_md_array(), convert_saop_to_hashed_saop_walker(), count_nulls(), deconstruct_array(), do_set_block_offsets(), EA_get_flat_size(), estimate_array_length(), ExecEvalArrayExpr(), ExecEvalHashedScalarArrayOp(), ExecEvalScalarArrayOp(), get_text_array_contents(), getWeights(), hash_array(), hash_array_extended(), is_strict_saop(), lt_q_regex(), makeArrayResultArr(), pg_isolation_test_session_is_blocked(), predicate_classify(), sanity_check_tid_array(), width_bucket_array_fixed(), width_bucket_array_float8(), and width_bucket_array_variable().

ArrayGetNItemsSafe()

int ArrayGetNItemsSafe ( int ndim,
const int * dims,
struct Node * escontext
)

Definition at line 67 of file arrayutils.c.

68{

70 int i;

71

72 if (ndim <= 0)

73 return 0;

74 ret = 1;

75 for (i = 0; i < ndim; i++)

76 {

78

79

80 if (dims[i] < 0)

82 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

83 errmsg("array size exceeds the maximum allowed (%d)",

85

87

88 ret = (int32) prod;

89 if ((int64) ret != prod)

91 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

92 errmsg("array size exceeds the maximum allowed (%d)",

94 }

98 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

99 errmsg("array size exceeds the maximum allowed (%d)",

101 return (int) ret;

102}

References Assert(), ereturn, errcode(), errmsg(), i, and MaxArraySize.

Referenced by ArrayGetNItems().

ArrayGetOffset()

int ArrayGetOffset ( int n,
const int * dim,
const int * lb,
const int * indx
)

construct_array()

ArrayType * construct_array ( Datum * elems,
int nelems,
Oid elmtype,
int elmlen,
bool elmbyval,
char elmalign
)

construct_array_builtin()

Definition at line 3381 of file arrayfuncs.c.

3382{

3383 int elmlen;

3384 bool elmbyval;

3385 char elmalign;

3386

3387 switch (elmtype)

3388 {

3389 case CHAROID:

3390 elmlen = 1;

3391 elmbyval = true;

3392 elmalign = TYPALIGN_CHAR;

3393 break;

3394

3395 case CSTRINGOID:

3396 elmlen = -2;

3397 elmbyval = false;

3398 elmalign = TYPALIGN_CHAR;

3399 break;

3400

3401 case FLOAT4OID:

3402 elmlen = sizeof(float4);

3403 elmbyval = true;

3404 elmalign = TYPALIGN_INT;

3405 break;

3406

3407 case FLOAT8OID:

3408 elmlen = sizeof(float8);

3410 elmalign = TYPALIGN_DOUBLE;

3411 break;

3412

3413 case INT2OID:

3414 elmlen = sizeof(int16);

3415 elmbyval = true;

3416 elmalign = TYPALIGN_SHORT;

3417 break;

3418

3419 case INT4OID:

3420 elmlen = sizeof(int32);

3421 elmbyval = true;

3422 elmalign = TYPALIGN_INT;

3423 break;

3424

3425 case INT8OID:

3426 elmlen = sizeof(int64);

3428 elmalign = TYPALIGN_DOUBLE;

3429 break;

3430

3431 case NAMEOID:

3433 elmbyval = false;

3434 elmalign = TYPALIGN_CHAR;

3435 break;

3436

3437 case OIDOID:

3438 case REGTYPEOID:

3439 elmlen = sizeof(Oid);

3440 elmbyval = true;

3441 elmalign = TYPALIGN_INT;

3442 break;

3443

3444 case TEXTOID:

3445 elmlen = -1;

3446 elmbyval = false;

3447 elmalign = TYPALIGN_INT;

3448 break;

3449

3450 case TIDOID:

3452 elmbyval = false;

3453 elmalign = TYPALIGN_SHORT;

3454 break;

3455

3456 case XIDOID:

3458 elmbyval = true;

3459 elmalign = TYPALIGN_INT;

3460 break;

3461

3462 default:

3463 elog(ERROR, "type %u not supported by construct_array_builtin()", elmtype);

3464

3465 elmlen = 0;

3466 elmbyval = false;

3467 elmalign = 0;

3468 }

3469

3470 return construct_array(elems, nelems, elmtype, elmlen, elmbyval, elmalign);

3471}

ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)

struct ItemPointerData ItemPointerData

References construct_array(), elog, ERROR, FLOAT8PASSBYVAL, and NAMEDATALEN.

Referenced by AlterPolicy(), attribute_statistics_update(), bt_page_print_tuples(), build_regtype_array(), convert_requires_to_datum(), CreateConstraintEntry(), CreateFunction(), CreatePolicy(), CreateStatistics(), current_schemas(), executeItemOptUnwrapTarget(), extension_config_remove(), filter_list_to_array(), float4_accum(), float8_accum(), float8_combine(), float8_regr_accum(), float8_regr_combine(), get_environ(), get_hba_options(), GetWALBlockInfo(), gin_leafpage_items(), gin_page_opaque_info(), gist_page_opaque_info(), GUCArrayAdd(), GUCArrayDelete(), GUCArrayReset(), hash_metapage_info(), heap_tuple_infomask_flags(), hstore_akeys(), int_list_to_array(), interpret_function_parameter_list(), makeMultirangeConstructors(), pg_blocking_pids(), pg_extension_config_dump(), pg_get_logical_snapshot_info(), pg_get_process_memory_contexts(), pg_safe_snapshot_blocking_pids(), pg_settings_get_flags(), publicationListToArray(), RemoveRoleFromObjectPolicy(), serialize_expr_stats(), show_trgm(), test_rls_hooks_permissive(), test_rls_hooks_restrictive(), ts_lexize(), tsvector_to_array(), tsvector_unnest(), typenameTypeMod(), and update_attstats().

construct_empty_array()

Definition at line 3580 of file arrayfuncs.c.

3581{

3583

3586 result->ndim = 0;

3589 return result;

3590}

References ArrayType::dataoffset, ArrayType::elemtype, ArrayType::ndim, palloc0(), and SET_VARSIZE.

Referenced by array_fill_internal(), array_get_slice(), array_in(), array_map(), array_recv(), array_replace_internal(), array_shuffle_n(), array_subscript_assign(), array_subscript_assign_slice(), construct_empty_expanded_array(), construct_md_array(), ExecEvalArrayExpr(), heap_tuple_infomask_flags(), hstore_akeys(), hstore_avals(), hstore_slice_to_array(), hstore_to_array_internal(), makeArrayResultArr(), new_intArrayType(), percentile_cont_multi_final_common(), percentile_disc_multi_final(), pg_event_trigger_dropped_objects(), pg_identify_object_as_address(), plperl_array_to_datum(), PLySequence_ToArray(), resize_intArrayType(), text_to_array(), and transformGenericOptions().

construct_empty_expanded_array()

construct_md_array()

ArrayType * construct_md_array ( Datum * elems,
bool * nulls,
int ndims,
int * dims,
int * lbs,
Oid elmtype,
int elmlen,
bool elmbyval,
char elmalign
)

Definition at line 3494 of file arrayfuncs.c.

3500{

3502 bool hasnulls;

3504 int32 dataoffset;

3505 int i;

3506 int nelems;

3507

3508 if (ndims < 0)

3510 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

3511 errmsg("invalid number of dimensions: %d", ndims)));

3514 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

3515 errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",

3517

3518

3521

3522

3523 if (nelems <= 0)

3525

3526

3527 nbytes = 0;

3528 hasnulls = false;

3529 for (i = 0; i < nelems; i++)

3530 {

3531 if (nulls && nulls[i])

3532 {

3533 hasnulls = true;

3534 continue;

3535 }

3536

3537 if (elmlen == -1)

3541

3544 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

3545 errmsg("array size exceeds the maximum allowed (%d)",

3547 }

3548

3549

3550 if (hasnulls)

3551 {

3553 nbytes += dataoffset;

3554 }

3555 else

3556 {

3557 dataoffset = 0;

3559 }

3562 result->ndim = ndims;

3565 memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));

3566 memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));

3567

3569 elems, nulls, nelems,

3570 elmlen, elmbyval, elmalign,

3571 false);

3572

3573 return result;

3574}

References AllocSizeIsValid, ARR_DIMS, ARR_LBOUND, ARR_OVERHEAD_NONULLS, ARR_OVERHEAD_WITHNULLS, ArrayCheckBounds(), ArrayGetNItems(), att_addlength_datum, att_align_nominal, construct_empty_array(), CopyArrayEls(), ArrayType::dataoffset, ArrayType::elemtype, ereport, errcode(), errmsg(), ERROR, i, MaxAllocSize, MAXDIM, ArrayType::ndim, palloc0(), PG_DETOAST_DATUM, PointerGetDatum(), and SET_VARSIZE.

Referenced by array_iterate(), array_reverse_n(), array_set_element(), array_set_slice(), array_shuffle_n(), build_regexp_match_result(), build_test_info_result(), build_test_match_result(), construct_array(), ExecEvalArrayExpr(), hstore_avals(), hstore_slice_to_array(), hstore_to_array_internal(), make_SAOP_expr(), makeMdArrayResult(), percentile_cont_multi_final_common(), percentile_disc_multi_final(), plpgsql_fulfill_promise(), and strlist_to_textarray().

CopyArrayEls()

void CopyArrayEls ( ArrayType * array,
Datum * values,
bool * nulls,
int nitems,
int typlen,
bool typbyval,
char typalign,
bool freedata
)

Definition at line 961 of file arrayfuncs.c.

969{

972 int bitval = 0;

973 int bitmask = 1;

974 int i;

975

976 if (typbyval)

977 freedata = false;

978

980 {

981 if (nulls && nulls[i])

982 {

983 if (!bitmap)

984 elog(ERROR, "null array element where not supported");

985

986 }

987 else

988 {

989 bitval |= bitmask;

991 if (freedata)

993 }

994 if (bitmap)

995 {

996 bitmask <<= 1;

997 if (bitmask == 0x100)

998 {

999 *bitmap++ = bitval;

1000 bitval = 0;

1001 bitmask = 1;

1002 }

1003 }

1004 }

1005

1006 if (bitmap && bitmask != 1)

1007 *bitmap = bitval;

1008}

References ARR_DATA_PTR, ARR_NULLBITMAP, ArrayCastAndSet(), DatumGetPointer(), elog, ERROR, i, nitems, pfree(), typalign, and values.

Referenced by array_in(), array_map(), array_recv(), array_replace_internal(), construct_md_array(), and EA_flatten_into().

DatumGetAnyArrayP()

DatumGetExpandedArray()

DatumGetExpandedArrayX()

Definition at line 372 of file array_expanded.c.

373{

374

376 {

378

380

381 if (metacache)

382 {

387 }

388 return eah;

389 }

390

391

394}

References Assert(), CurrentMemoryContext, DatumGetEOHP(), DatumGetPointer(), EA_MAGIC, ExpandedArrayHeader::ea_magic, ExpandedArrayHeader::element_type, ArrayMetaState::element_type, expand_array(), ExpandedArrayHeader::typalign, ArrayMetaState::typalign, ExpandedArrayHeader::typbyval, ArrayMetaState::typbyval, ExpandedArrayHeader::typlen, ArrayMetaState::typlen, and VARATT_IS_EXTERNAL_EXPANDED_RW.

deconstruct_array()

void deconstruct_array ( ArrayType * array,
Oid elmtype,
int elmlen,
bool elmbyval,
char elmalign,
Datum ** elemsp,
bool ** nullsp,
int * nelemsp
)

Definition at line 3631 of file arrayfuncs.c.

3635{

3637 bool *nulls;

3638 int nelems;

3639 char *p;

3641 int bitmask;

3642 int i;

3643

3645

3648 if (nullsp)

3649 *nullsp = nulls = (bool *) palloc0(nelems * sizeof(bool));

3650 else

3651 nulls = NULL;

3652 *nelemsp = nelems;

3653

3656 bitmask = 1;

3657

3658 for (i = 0; i < nelems; i++)

3659 {

3660

3661 if (bitmap && (*bitmap & bitmask) == 0)

3662 {

3663 elems[i] = (Datum) 0;

3664 if (nulls)

3665 nulls[i] = true;

3666 else

3668 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),

3669 errmsg("null array element not allowed in this context")));

3670 }

3671 else

3672 {

3673 elems[i] = fetch_att(p, elmbyval, elmlen);

3676 }

3677

3678

3679 if (bitmap)

3680 {

3681 bitmask <<= 1;

3682 if (bitmask == 0x100)

3683 {

3684 bitmap++;

3685 bitmask = 1;

3686 }

3687 }

3688 }

3689}

References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_NDIM, ARR_NULLBITMAP, ArrayGetNItems(), Assert(), att_addlength_pointer, att_align_nominal, ereport, errcode(), errmsg(), ERROR, fetch_att(), i, palloc(), and palloc0().

Referenced by _bt_preprocess_array_keys(), array_contain_compare(), array_reverse_n(), array_set_slice(), array_shuffle_n(), array_to_json_internal(), array_to_jsonb_internal(), arrayconst_startup_fn(), compute_array_stats(), deconstruct_array_builtin(), deconstruct_expanded_array(), ExecIndexEvalArrayKeys(), extract_variadic_args(), get_attstatsslot(), ginarrayextract(), gincost_scalararrayopexpr(), ginqueryarrayextract(), map_sql_value_to_xml_value(), match_clause_to_partition_key(), mcelem_array_selec(), mcv_get_match_bitmap(), multirange_constructor2(), plperl_ref_from_pg_array(), satisfies_hash_partition(), scalararraysel(), and text_format().

deconstruct_array_builtin()

void deconstruct_array_builtin ( ArrayType * array,
Oid elmtype,
Datum ** elemsp,
bool ** nullsp,
int * nelemsp
)

Definition at line 3697 of file arrayfuncs.c.

3700{

3701 int elmlen;

3702 bool elmbyval;

3703 char elmalign;

3704

3705 switch (elmtype)

3706 {

3707 case CHAROID:

3708 elmlen = 1;

3709 elmbyval = true;

3710 elmalign = TYPALIGN_CHAR;

3711 break;

3712

3713 case CSTRINGOID:

3714 elmlen = -2;

3715 elmbyval = false;

3716 elmalign = TYPALIGN_CHAR;

3717 break;

3718

3719 case FLOAT8OID:

3720 elmlen = sizeof(float8);

3722 elmalign = TYPALIGN_DOUBLE;

3723 break;

3724

3725 case INT2OID:

3726 elmlen = sizeof(int16);

3727 elmbyval = true;

3728 elmalign = TYPALIGN_SHORT;

3729 break;

3730

3731 case OIDOID:

3732 elmlen = sizeof(Oid);

3733 elmbyval = true;

3734 elmalign = TYPALIGN_INT;

3735 break;

3736

3737 case TEXTOID:

3738 elmlen = -1;

3739 elmbyval = false;

3740 elmalign = TYPALIGN_INT;

3741 break;

3742

3743 case TIDOID:

3745 elmbyval = false;

3746 elmalign = TYPALIGN_SHORT;

3747 break;

3748

3749 default:

3750 elog(ERROR, "type %u not supported by deconstruct_array_builtin()", elmtype);

3751

3752 elmlen = 0;

3753 elmbyval = false;

3754 elmalign = 0;

3755 }

3756

3757 deconstruct_array(array, elmtype, elmlen, elmbyval, elmalign, elemsp, nullsp, nelemsp);

3758}

References deconstruct_array(), elog, ERROR, and FLOAT8PASSBYVAL.

Referenced by array_to_tsvector(), ArrayGetIntegerTypmods(), binary_upgrade_create_empty_extension(), build_function_result_tupdesc_d(), DecodeTextArrayToBitmapset(), decompile_column_index_array(), extension_config_remove(), generateClonedIndexStmt(), get_func_arg_info(), get_func_input_arg_names(), get_func_result_name(), get_jsonb_path_all(), get_path_all(), get_reloptions(), ghstore_consistent(), gin_extract_hstore_query(), gin_extract_jsonb_query(), hstore_from_array(), hstore_from_arrays(), hstore_slice_to_array(), hstoreArrayToPairs(), json_object(), json_object_two_arg(), jsonb_delete_array(), jsonb_delete_path(), jsonb_exists_all(), jsonb_exists_any(), jsonb_insert(), jsonb_object(), jsonb_object_two_arg(), jsonb_set(), oid_array_to_list(), parse_key_value_arrays(), parseRelOptionsInternal(), percentile_cont_multi_final_common(), percentile_disc_multi_final(), pg_get_constraintdef_worker(), pg_get_object_address(), pg_get_publication_tables(), pg_logical_slot_get_changes_guts(), textarray_to_stringlist(), textarray_to_strvaluelist(), TidListEval(), transformRelOptions(), tsvector_delete_arr(), tsvector_filter(), tsvector_setweight_by_filter(), untransformRelOptions(), and worker_spi_launch().

deconstruct_expanded_array()

Definition at line 424 of file array_expanded.c.

425{

426 if (eah->dvalues == NULL)

427 {

430 bool *dnulls;

431 int nelems;

432

433 dnulls = NULL;

437 &dvalues,

439 &nelems);

440

441

442

443

444

445

446

447

449 eah->dnulls = dnulls;

452 }

453}

MemoryContext eoh_context

References ARR_HASNULL, deconstruct_array(), ExpandedArrayHeader::dnulls, ExpandedArrayHeader::dvalues, ExpandedArrayHeader::dvalueslen, ExpandedArrayHeader::element_type, ExpandedObjectHeader::eoh_context, ExpandedArrayHeader::fvalue, ExpandedArrayHeader::hdr, MemoryContextSwitchTo(), ExpandedArrayHeader::nelems, ExpandedArrayHeader::typalign, ExpandedArrayHeader::typbyval, and ExpandedArrayHeader::typlen.

Referenced by array_contain_compare(), array_get_element_expanded(), array_set_element_expanded(), and statext_expressions_load().

expand_array()

Definition at line 50 of file array_expanded.c.

52{

58

59

60

61

62

63

65 "expanded array",

67

68

71

74

75

77 {

79

81

82

83

84

85

86

87

88

89 if (metacache == NULL)

90 metacache = &fakecache;

95

96

97

98

99

100

101

103 {

105

107 }

108

109

110

111

112

113

114

115

116

117

118

119 }

120

121

122

123

124

125

126

127

128

129

133

135

138

139

142 {

143

147 }

148 else

149 {

150

155

156 if (metacache)

157 {

162 }

163 }

164

165

171

172

176

177

179}

#define DatumGetArrayTypePCopy(X)

static void copy_byval_expanded_array(ExpandedArrayHeader *eah, ExpandedArrayHeader *oldeah)

static const ExpandedObjectMethods EA_methods

void EOH_init_header(ExpandedObjectHeader *eohptr, const ExpandedObjectMethods *methods, MemoryContext obj_context)

static Datum EOHPGetRWDatum(const struct ExpandedObjectHeader *eohptr)

void * MemoryContextAlloc(MemoryContext context, Size size)

#define AllocSetContextCreate

#define ALLOCSET_START_SMALL_SIZES

References ALLOCSET_START_SMALL_SIZES, AllocSetContextCreate, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_LBOUND, ARR_NDIM, ARR_SIZE, Assert(), copy_byval_expanded_array(), DatumGetArrayTypePCopy, DatumGetEOHP(), DatumGetPointer(), ExpandedArrayHeader::dims, ExpandedArrayHeader::dnulls, ExpandedArrayHeader::dvalues, ExpandedArrayHeader::dvalueslen, EA_MAGIC, ExpandedArrayHeader::ea_magic, EA_methods, ExpandedArrayHeader::element_type, ArrayMetaState::element_type, EOH_init_header(), EOHPGetRWDatum(), ExpandedArrayHeader::fendptr, ExpandedArrayHeader::flat_size, ExpandedArrayHeader::fstartptr, ExpandedArrayHeader::fvalue, get_typlenbyvalalign(), ExpandedArrayHeader::hdr, ExpandedArrayHeader::lbound, MemoryContextAlloc(), MemoryContextSwitchTo(), ExpandedArrayHeader::ndims, ExpandedArrayHeader::nelems, ExpandedArrayHeader::typalign, ArrayMetaState::typalign, ExpandedArrayHeader::typbyval, ArrayMetaState::typbyval, ExpandedArrayHeader::typlen, ArrayMetaState::typlen, and VARATT_IS_EXTERNAL_EXPANDED.

Referenced by construct_empty_expanded_array(), DatumGetExpandedArray(), DatumGetExpandedArrayX(), exec_assign_value(), and plpgsql_exec_function().

initArrayResult()

Definition at line 5293 of file arrayfuncs.c.

5294{

5295

5296

5297

5298

5299

5301 subcontext ? 64 : 8);

5302}

ArrayBuildState * initArrayResultWithSize(Oid element_type, MemoryContext rcontext, bool subcontext, int initsize)

References initArrayResultWithSize().

Referenced by accumArrayResult(), array_agg_transfn(), array_positions(), array_to_datum_internal(), daitch_mokotoff(), initArrayResultAny(), multirange_agg_transfn(), PLySequence_ToArray_recurse(), populate_array(), range_agg_transfn(), tuple_data_split_internal(), and xpath().

initArrayResultAny()

Definition at line 5782 of file arrayfuncs.c.

5783{

5785

5786

5787

5788

5789

5790

5791

5793 {

5794

5796

5803 }

5804 else

5805 {

5806

5808

5809 scalarstate = initArrayResult(input_type, rcontext, subcontext);

5815 }

5816

5817 return astate;

5818}

#define OidIsValid(objectId)

Oid get_array_type(Oid typid)

References ArrayBuildStateAny::arraystate, get_array_type(), initArrayResult(), initArrayResultArr(), InvalidOid, ArrayBuildState::mcontext, ArrayBuildStateArr::mcontext, MemoryContextAlloc(), OidIsValid, and ArrayBuildStateAny::scalarstate.

Referenced by accumArrayResultAny(), ExecScanSubPlan(), and ExecSetParamPlan().

initArrayResultArr()

Definition at line 5504 of file arrayfuncs.c.

5506{

5508 MemoryContext arr_context = rcontext;

5509

5510

5512 {

5514

5517 (errcode(ERRCODE_DATATYPE_MISMATCH),

5518 errmsg("data type %s is not an array type",

5520 }

5521

5522

5523 if (subcontext)

5525 "accumArrayResultArr",

5527

5528

5531 astate->mcontext = arr_context;

5533

5534

5537

5538 return astate;

5539}

char * format_type_be(Oid type_oid)

Oid get_element_type(Oid typid)

void * MemoryContextAllocZero(MemoryContext context, Size size)

#define ALLOCSET_DEFAULT_SIZES

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, ArrayBuildStateArr::array_type, ArrayBuildStateArr::element_type, ereport, errcode(), errmsg(), ERROR, format_type_be(), get_element_type(), ArrayBuildStateArr::mcontext, MemoryContextAllocZero(), OidIsValid, and ArrayBuildStateArr::private_cxt.

Referenced by accumArrayResultArr(), array_agg_array_combine(), array_agg_array_deserialize(), array_agg_array_transfn(), and initArrayResultAny().

initArrayResultWithSize()

Definition at line 5310 of file arrayfuncs.c.

5312{

5315

5316

5317 if (subcontext)

5319 "accumArrayResult",

5321

5324 astate->mcontext = arr_context;

5326 astate->alen = initsize;

5329 astate->dnulls = (bool *)

5337

5338 return astate;

5339}

References ArrayBuildState::alen, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, ArrayBuildState::dnulls, ArrayBuildState::dvalues, ArrayBuildState::element_type, get_typlenbyvalalign(), ArrayBuildState::mcontext, MemoryContextAlloc(), ArrayBuildState::nelems, ArrayBuildState::private_cxt, ArrayBuildState::typalign, ArrayBuildState::typbyval, and ArrayBuildState::typlen.

Referenced by array_agg_combine(), array_agg_deserialize(), and initArrayResult().

makeArrayResult()

Definition at line 5420 of file arrayfuncs.c.

5422{

5423 int ndims;

5424 int dims[1];

5425 int lbs[1];

5426

5427

5428 ndims = (astate->nelems > 0) ? 1 : 0;

5429 dims[0] = astate->nelems;

5430 lbs[0] = 1;

5431

5434}

Datum makeMdArrayResult(ArrayBuildState *astate, int ndims, int *dims, int *lbs, MemoryContext rcontext, bool release)

References makeMdArrayResult(), ArrayBuildState::nelems, and ArrayBuildState::private_cxt.

Referenced by array_positions(), brin_minmax_multi_summary_out(), daitch_mokotoff(), dblink_get_connections(), optionListToArray(), parse_ident(), pg_get_statisticsobjdef_expressions(), pg_stats_ext_mcvlist_items(), regexp_split_to_array(), serialize_expr_stats(), text_to_array(), transformRelOptions(), tuple_data_split_internal(), and xpath().

makeArrayResultAny()

Definition at line 5857 of file arrayfuncs.c.

5859{

5861

5863 {

5864

5865 int ndims;

5866 int dims[1];

5867 int lbs[1];

5868

5869

5872 lbs[0] = 1;

5873

5875 rcontext, release);

5876 }

5877 else

5878 {

5880 rcontext, release);

5881 }

5882 return result;

5883}

Datum makeArrayResultArr(ArrayBuildStateArr *astate, MemoryContext rcontext, bool release)

References ArrayBuildStateAny::arraystate, makeArrayResultArr(), makeMdArrayResult(), ArrayBuildState::nelems, and ArrayBuildStateAny::scalarstate.

Referenced by array_sort_internal(), ExecScanSubPlan(), and ExecSetParamPlan().

makeArrayResultArr()

Definition at line 5703 of file arrayfuncs.c.

5706{

5709

5710

5712

5713 if (astate->ndims == 0)

5714 {

5715

5717 }

5718 else

5719 {

5720 int dataoffset,

5721 nbytes;

5722

5723

5726

5727

5728 nbytes = astate->nbytes;

5730 {

5732 nbytes += dataoffset;

5733 }

5734 else

5735 {

5736 dataoffset = 0;

5738 }

5739

5745

5746 memcpy(ARR_DIMS(result), astate->dims, astate->ndims * sizeof(int));

5747 memcpy(ARR_LBOUND(result), astate->lbs, astate->ndims * sizeof(int));

5749

5754 }

5755

5757

5758

5759 if (release)

5760 {

5763 }

5764

5766}

void MemoryContextDelete(MemoryContext context)

References ARR_DATA_PTR, ARR_DIMS, ARR_LBOUND, ARR_NULLBITMAP, ARR_OVERHEAD_NONULLS, ARR_OVERHEAD_WITHNULLS, array_bitmap_copy(), ArrayCheckBounds(), ArrayGetNItems(), Assert(), construct_empty_array(), ArrayBuildStateArr::data, ArrayType::dataoffset, ArrayBuildStateArr::dims, ArrayBuildStateArr::element_type, ArrayType::elemtype, ArrayBuildStateArr::lbs, ArrayBuildStateArr::mcontext, MemoryContextDelete(), MemoryContextSwitchTo(), ArrayBuildStateArr::nbytes, ArrayType::ndim, ArrayBuildStateArr::ndims, ArrayBuildStateArr::nitems, ArrayBuildStateArr::nullbitmap, palloc0(), PointerGetDatum(), ArrayBuildStateArr::private_cxt, and SET_VARSIZE.

Referenced by array_agg_array_finalfn(), and makeArrayResultAny().

makeMdArrayResult()

Definition at line 5452 of file arrayfuncs.c.

5458{

5461

5462

5464

5467 ndims,

5468 dims,

5469 lbs,

5474

5476

5477

5478 if (release)

5479 {

5482 }

5483

5485}

References Assert(), construct_md_array(), ArrayBuildState::dnulls, ArrayBuildState::dvalues, ArrayBuildState::element_type, ArrayBuildState::mcontext, MemoryContextDelete(), MemoryContextSwitchTo(), PointerGetDatum(), ArrayBuildState::private_cxt, ArrayBuildState::typalign, ArrayBuildState::typbyval, and ArrayBuildState::typlen.

Referenced by array_agg_finalfn(), makeArrayResult(), makeArrayResultAny(), plperl_array_to_datum(), PLySequence_ToArray(), and populate_array().

mda_get_offset_values()

void mda_get_offset_values ( int n,
int * dist,
const int * prod,
const int * span
)

mda_get_prod()

void mda_get_prod ( int n,
const int * range,
int * prod
)

mda_get_range()

void mda_get_range ( int n,
int * span,
const int * st,
const int * endp
)

mda_next_tuple()

int mda_next_tuple ( int n,
int * curr,
const int * span
)

Definition at line 208 of file arrayutils.c.

209{

210 int i;

211

212 if (n <= 0)

213 return -1;

214

215 curr[n - 1] = (curr[n - 1] + 1) % span[n - 1];

216 for (i = n - 1; i && curr[i] == 0; i--)

217 curr[i - 1] = (curr[i - 1] + 1) % span[i - 1];

218

219 if (i)

220 return i;

221 if (curr[0])

222 return 0;

223

224 return -1;

225}

References i.

Referenced by array_extract_slice(), array_insert_slice(), and array_slice_size().

Array_nulls