34#include "utils/fmgroids.h"
51#define AARR_FREE_IF_COPY(array,n) \
53 if (!VARATT_IS_EXPANDED_HEADER(array)) \
54 PG_FREE_IF_COPY(array, n); \
101 int typlen,
bool typbyval,
char typalign,
110 int typlen,
bool typbyval,
char typalign,
116 int elmlen,
bool elmbyval,
char elmalign,
122 int elmlen,
bool elmbyval,
char elmalign);
127 int typlen,
bool typbyval,
uint8 typalignby,
130 int typlen,
bool typbyval,
char typalign);
135 int typlen,
bool typbyval,
char typalign);
137 int ndim,
int *dim,
int *lb,
139 int typlen,
bool typbyval,
char typalign);
141 int ndim,
int *dim,
int *lb,
144 int typlen,
bool typbyval,
char typalign);
147 int ndim,
int *dim,
int *lb,
149 int typlen,
bool typbyval,
char typalign);
159 bool remove,
Oid collation,
187 Node *escontext = fcinfo->context;
221 if (
my_extra->element_type != element_type)
231 fcinfo->flinfo->fn_mcxt);
232 my_extra->element_type = element_type;
268 errmsg(
"malformed array literal: \"%s\"",
string),
269 errdetail(
"Array value must start with \"{\" or dimension information.")));
277 errmsg(
"malformed array literal: \"%s\"",
string),
278 errdetail(
"Missing \"%s\" after array dimensions.",
288 errmsg(
"malformed array literal: \"%s\"",
string),
289 errdetail(
"Array contents must start with \"{\".")));
294 &
my_extra->proc, typioparam, typmod,
311 errmsg(
"malformed array literal: \"%s\"",
string),
312 errdetail(
"Junk after closing right brace.")));
339 errmsg(
"array size exceeds the maximum allowed (%zu)",
346 nbytes += dataoffset;
435 errmsg(
"number of array dimensions exceeds the maximum allowed (%d)",
445 errdetail(
"\"[\" must introduce explicitly-specified array dimensions.")));
459 errdetail(
"Missing array dimension value.")));
471 errdetail(
"Missing \"%s\" after array dimensions.",
485 errmsg(
"upper bound cannot be less than lower bound")));
491 errmsg(
"array upper bound is too large: %d",
ub)));
498 errmsg(
"array size exceeds the maximum allowed (%zu)",
530 if (!
isdigit((
unsigned char) *p) && *p !=
'-' && *p !=
'+')
542 errmsg(
"array bound is out of integer range")));
641 errdetail(
"Unexpected \"%c\" character.",
'{')));
647 errmsg(
"number of array dimensions exceeds the maximum allowed (%d)",
650 nelems[nest_level] = 0;
652 if (nest_level > ndim)
673 errdetail(
"Unexpected \"%c\" character.",
678 nelems[nest_level - 1]++;
685 if (dim[nest_level] < 0)
688 dim[nest_level] = nelems[nest_level];
690 else if (nelems[nest_level] != dim[nest_level])
708 errdetail(
"Unexpected \"%c\" character.",
723 errdetail(
"Unexpected array element.")));
731 errmsg(
"array size exceeds the maximum allowed (%zu)",
754 if (nest_level != ndim)
757 nelems[nest_level - 1]++;
766 }
while (nest_level > 0);
782 errdetail(
"Specified array dimensions do not match array contents.")));
787 errdetail(
"Multidimensional arrays must have sub-arrays with matching dimensions.")));
864 while (*(++p) !=
'\0')
866 if (*p == typdelim || *p ==
'}' || *p ==
'{')
875 errdetail(
"Incorrectly quoted array element.")));
902 errdetail(
"Unexpected \"%c\" character.",
909 errdetail(
"Incorrectly quoted array element.")));
921 if (*p == typdelim || *p ==
'}')
986 if (nulls && nulls[
i])
989 elog(
ERROR,
"null array element where not supported");
1002 if (bitmask == 0x100)
1011 if (bitmap && bitmask != 1)
1068 if (
my_extra->element_type != element_type)
1078 fcinfo->flinfo->fn_mcxt);
1079 my_extra->element_type = element_type;
1101 for (
i = 0;
i < ndim;
i++)
1148 for (tmp =
values[
i]; *tmp !=
'\0'; tmp++)
1153 if (
ch ==
'"' ||
ch ==
'\\')
1158 else if (
ch ==
'{' ||
ch ==
'}' ||
ch == typdelim ||
1179 for (
i =
j = 0, k = 1;
i < ndim;
i++)
1181 j += k, k *= dims[
i];
1191 for (
i = 0;
i < ndim;
i++)
1193 sprintf(ptr,
"[%d:%d]", lb[
i], lb[
i] + dims[
i] - 1);
1205#define APPENDSTR(str) (strcpy(p, (str)), p += strlen(p))
1206#define APPENDCHAR(ch) (*p++ = (ch), *p = '\0')
1211 for (
i = 0;
i < ndim;
i++)
1217 for (
i =
j;
i < ndim - 1;
i++)
1223 for (tmp =
values[k]; *tmp; tmp++)
1227 if (
ch ==
'"' ||
ch ==
'\\')
1238 for (
i = ndim - 1;
i >= 0;
i--)
1240 if (++(
indx[
i]) < dims[
i])
1305 errmsg(
"invalid number of dimensions: %d", ndim)));
1309 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
1313 if (flags != 0 && flags != 1)
1316 errmsg(
"invalid array flags")));
1338 errmsg(
"binary data has array element type %u (%s) instead of expected %u (%s)",
1348 for (
i = 0;
i < ndim;
i++)
1372 if (
my_extra->element_type != element_type)
1382 errmsg(
"no binary input function available for type %s",
1385 fcinfo->flinfo->fn_mcxt);
1386 my_extra->element_type = element_type;
1403 &
my_extra->proc, typioparam, typmod,
1410 nbytes += dataoffset;
1419 retval->
ndim = ndim;
1486 errmsg(
"insufficient data left in message")));
1492 typioparam, typmod);
1507 typioparam, typmod);
1514 errmsg(
"improper binary format in array element %d",
1538 errmsg(
"array size exceeds the maximum allowed (%zu)",
1583 if (
my_extra->element_type != element_type)
1593 errmsg(
"no binary output function available for type %s",
1596 fcinfo->flinfo->fn_mcxt);
1597 my_extra->element_type = element_type;
1614 for (
i = 0;
i < ndim;
i++)
1889 for (
i = 0;
i < ndim;
i++)
1928 int elmlen,
bool elmbyval,
char elmalign,
1961 for (
i = 0;
i < ndim;
i++)
1981 dvalues =
eah->dvalues;
1982 dnulls =
eah->dnulls;
1987 if (dnulls && dnulls[offset])
2000 return dvalues[offset];
2071 errmsg(
"slices of fixed-length arrays not implemented")));
2118 for (;
i < ndim;
i++)
2140 bytes += dataoffset;
2160 for (
i = 0;
i < ndim;
i++)
2250 errmsg(
"wrong number of array subscripts")));
2255 errmsg(
"array subscript out of range")));
2260 errmsg(
"cannot assign null value to an element of a fixed-length array")));
2272 errmsg(
"wrong number of array subscripts")));
2275 if (elmlen == -1 && !isNull)
2321 errmsg(
"wrong number of array subscripts")));
2338 if (
indx[0] < lb[0])
2346 errmsg(
"array size exceeds the maximum allowed (%zu)",
2352 if (
indx[0] >= (dim[0] + lb[0]))
2361 errmsg(
"array size exceeds the maximum allowed (%zu)",
2373 for (
i = 0;
i < ndim;
i++)
2379 errmsg(
"array subscript out of range")));
2510 int elmlen,
bool elmbyval,
char elmalign)
2542 memcpy(dim,
eah->dims, ndim *
sizeof(
int));
2543 memcpy(lb,
eah->lbound, ndim *
sizeof(
int));
2575 errmsg(
"wrong number of array subscripts")));
2593 if (!
eah->typbyval && !isNull)
2601 dvalues =
eah->dvalues;
2602 dnulls =
eah->dnulls;
2615 if (
indx[0] < lb[0])
2623 errmsg(
"array size exceeds the maximum allowed (%zu)",
2630 if (
indx[0] >= (dim[0] + lb[0]))
2639 errmsg(
"array size exceeds the maximum allowed (%zu)",
2652 for (
i = 0;
i < ndim;
i++)
2658 errmsg(
"array subscript out of range")));
2673 if (dim[0] >
eah->dvalueslen)
2676 int newlen = dim[0] + dim[0] / 8;
2682 eah->dnulls = dnulls = (
bool *)
2692 eah->dnulls = dnulls = (
bool *)
2694 eah->dvalueslen *
sizeof(
bool));
2710 memcpy(
eah->dims, dim, ndim *
sizeof(
int));
2711 memcpy(
eah->lbound, lb, ndim *
sizeof(
int));
2737 dnulls[
eah->nelems +
i] =
true;
2743 if (!
eah->typbyval && (dnulls ==
NULL || !dnulls[offset]))
2751 dnulls[offset] = isNull;
2860 errmsg(
"updates on slices of fixed-length arrays not implemented")));
2884 &dvalues, &dnulls, &nelems);
2891 errmsg(
"array slice subscript must provide both boundaries"),
2892 errdetail(
"When assigning to a slice of an empty array value,"
2893 " slice boundaries must be fully specified.")));
2900 errmsg(
"array size exceeds the maximum allowed (%zu)",
2910 errmsg(
"source array too small")));
2920 errmsg(
"wrong number of array subscripts")));
2945 errmsg(
"upper bound cannot be less than lower bound")));
2954 errmsg(
"array size exceeds the maximum allowed (%zu)",
2969 errmsg(
"array size exceeds the maximum allowed (%zu)",
2990 errmsg(
"upper bound cannot be less than lower bound")));
2995 errmsg(
"array subscript out of range")));
2998 for (;
i < ndim;
i++)
3005 errmsg(
"upper bound cannot be less than lower bound")));
3022 errmsg(
"source array too small")));
3275 typlen = ret_extra->
typlen;
3311 errmsg(
"array size exceeds the maximum allowed (%zu)",
3320 nbytes += dataoffset;
3329 result->
ndim = ndim;
3369 int elmlen,
bool elmbyval,
char elmalign)
3420 elmlen =
sizeof(
int16);
3426 elmlen =
sizeof(
int32);
3432 elmlen =
sizeof(
int64);
3445 elmlen =
sizeof(
Oid);
3469 elog(
ERROR,
"type %u not supported by construct_array_builtin()",
elmtype);
3518 errmsg(
"invalid number of dimensions: %d", ndims)));
3522 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
3536 for (
i = 0;
i < nelems;
i++)
3538 if (nulls && nulls[
i])
3552 errmsg(
"array size exceeds the maximum allowed (%zu)",
3560 nbytes += dataoffset;
3569 result->
ndim = ndims;
3576 elems, nulls, nelems,
3640 int elmlen,
bool elmbyval,
char elmalign,
3666 for (
i = 0;
i < nelems;
i++)
3669 if (bitmap && (*bitmap & bitmask) == 0)
3677 errmsg(
"null array element not allowed in this context")));
3690 if (bitmask == 0x100)
3734 elmlen =
sizeof(
int16);
3740 elmlen =
sizeof(
Oid);
3758 elog(
ERROR,
"type %u not supported by deconstruct_array_builtin()",
elmtype);
3792 if (*bitmap != 0xFF)
3802 if ((*bitmap & bitmask) == 0)
3848 errmsg(
"cannot compare arrays of different element types")));
3864 if (typentry ==
NULL ||
3865 typentry->
type_id != element_type)
3872 errmsg(
"could not identify an equality operator for type %s",
3874 fcinfo->flinfo->fn_extra = typentry;
3876 typlen = typentry->
typlen;
4017 errmsg(
"cannot compare arrays of different element types")));
4026 if (typentry ==
NULL ||
4027 typentry->
type_id != element_type)
4034 errmsg(
"could not identify a comparison function for type %s",
4038 typlen = typentry->
typlen;
4141 result = (lbound1[
i] <
lbound2[
i]) ? -1 : 1;
4187 if (typentry ==
NULL ||
4188 typentry->
type_id != element_type)
4195 errmsg(
"could not identify a hash function for type %s",
4231 fcinfo->flinfo->fn_extra = typentry;
4234 typlen = typentry->
typlen;
4283 result = (result << 5) - result +
elthash;
4315 if (typentry ==
NULL ||
4316 typentry->
type_id != element_type)
4323 errmsg(
"could not identify an extended hash function for type %s",
4325 fcinfo->flinfo->fn_extra = typentry;
4327 typlen = typentry->
typlen;
4363 result = (result << 5) - result +
elthash;
4408 errmsg(
"cannot compare arrays of different element types")));
4417 if (typentry ==
NULL ||
4418 typentry->
type_id != element_type)
4425 errmsg(
"could not identify an equality operator for type %s",
4427 *fn_extra = typentry;
4429 typlen = typentry->
typlen;
4448 element_type, typlen, typbyval,
typalign,
4538 &fcinfo->flinfo->fn_extra);
4556 &fcinfo->flinfo->fn_extra);
4574 &fcinfo->flinfo->fn_extra);
4612 elog(
ERROR,
"invalid arguments to array_create_iterator");
4720 bool *nulls =
iterator->slice_nulls;
4790 if (nullbitmap ==
NULL)
4792 if (nullbitmap[offset / 8] & (1 << (offset % 8)))
4809 nullbitmap += offset / 8;
4810 bitmask = 1 << (offset % 8);
4814 *nullbitmap |= bitmask;
4874 int typlen,
bool typbyval,
char typalign)
4881 if (typlen > 0 && !nullbitmap)
4887 nullbitmap += offset / 8;
4888 bitmask = 1 << (offset % 8);
4892 if (*nullbitmap & bitmask)
4898 if (bitmask == 0x100)
4923 int typlen,
bool typbyval,
char typalign)
4946 int typlen,
bool typbyval,
char typalign)
5046 int ndim,
int *dim,
int *lb,
5048 int typlen,
bool typbyval,
char typalign)
5074 for (
i = 0;
i < ndim;
i++)
5137 for (
i = 0;
i < ndim;
i++)
5223 for (
i = 0;
i < ndim;
i++)
5310 subcontext ? 64 : 8);
5338 astate->
dnulls = (
bool *)
5386 errmsg(
"array size exceeds the maximum allowed (%zu)",
5390 astate->
dnulls = (
bool *)
5404 if (astate->
typlen == -1)
5437 ndims = (astate->
nelems > 0) ? 1 : 0;
5438 dims[0] = astate->
nelems;
5527 errmsg(
"data type %s is not an array type",
5534 "accumArrayResultArr",
5582 errmsg(
"cannot accumulate null arrays")));
5602 if (astate->
ndims == 0)
5610 errmsg(
"cannot accumulate empty arrays")));
5614 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
5621 astate->
ndims = ndims + 1;
5622 astate->
dims[0] = 0;
5623 memcpy(&astate->
dims[1], dims, ndims *
sizeof(
int));
5625 memcpy(&astate->
lbs[1], lbs, ndims *
sizeof(
int));
5634 if (astate->
ndims != ndims + 1)
5637 errmsg(
"cannot accumulate arrays of different dimensionality")));
5638 for (
i = 0;
i < ndims;
i++)
5640 if (astate->
dims[
i + 1] != dims[
i] || astate->
lbs[
i + 1] != lbs[
i])
5643 errmsg(
"cannot accumulate arrays of different dimensionality")));
5693 astate->
dims[0] += 1;
5722 if (astate->
ndims == 0)
5741 nbytes += dataoffset;
6013 errmsg(
"dimension array or low bound array cannot be null")));
6031 elog(
ERROR,
"could not determine data type of input");
6053 errmsg(
"dimension array or low bound array cannot be null")));
6070 elog(
ERROR,
"could not determine data type of input");
6084 result->
ndim = ndims;
6116 errmsg(
"wrong number of array subscripts"),
6117 errdetail(
"Dimension array must be one dimensional.")));
6122 errmsg(
"dimension values cannot be null")));
6130 errmsg(
"invalid number of dimensions: %d", ndims)));
6134 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
6142 errmsg(
"wrong number of array subscripts"),
6143 errdetail(
"Dimension array must be one dimensional.")));
6148 errmsg(
"dimension values cannot be null")));
6153 errmsg(
"wrong number of array subscripts"),
6154 errdetail(
"Low bound array has different size than dimensions array.")));
6227 errmsg(
"array size exceeds the maximum allowed (%zu)",
6249 nbytes = dataoffset;
6333 if (
fctx->nextelem <
fctx->numelems)
6335 int offset =
fctx->nextelem++;
6395 bool remove,
Oid collation,
6434 if (remove && ndim > 1)
6437 errmsg(
"removing elements from multidimensional arrays is not supported")));
6444 if (typentry ==
NULL ||
6445 typentry->
type_id != element_type)
6452 errmsg(
"could not identify an equality operator for type %s",
6456 typlen = typentry->
typlen;
6497 if (bitmap && (*bitmap & bitmask) == 0)
6573 errmsg(
"array size exceeds the maximum allowed (%zu)",
6583 if (bitmask == 0x100)
6613 nbytes += dataoffset;
6622 result->
ndim = ndim;
6715 errmsg(
"thresholds must be one-dimensional array")));
6720 errmsg(
"thresholds array must not contain NULLs")));
6731 if (typentry ==
NULL ||
6732 typentry->
type_id != element_type)
6739 errmsg(
"could not identify a comparison function for type %s",
6741 fcinfo->flinfo->fn_extra = typentry;
6748 if (typentry->
typlen > 0)
6750 collation, typentry);
6753 collation, typentry);
6793 while (left < right)
6795 int mid = (left + right) / 2;
6817 int typlen = typentry->
typlen;
6818 bool typbyval = typentry->
typbyval;
6834 while (left < right)
6836 int mid = (left + right) / 2;
6872 int typlen = typentry->
typlen;
6873 bool typbyval = typentry->
typbyval;
6887 while (left < right)
6889 int mid = (left + right) / 2;
6896 for (
i = left;
i < mid;
i++)
6954 errmsg(
"number of elements to trim must be between 0 and %d",
#define PG_GETARG_ANY_ARRAY_P(n)
#define PG_GETARG_ARRAYTYPE_P(n)
#define ARR_NULLBITMAP(a)
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
#define DatumGetArrayTypeP(X)
#define PG_RETURN_ARRAYTYPE_P(x)
#define ARR_OVERHEAD_NONULLS(ndims)
#define ARR_DATA_OFFSET(a)
Datum expand_array(Datum arraydatum, MemoryContext parentcontext, ArrayMetaState *metacache)
void deconstruct_expanded_array(ExpandedArrayHeader *eah)
ExpandedArrayHeader * DatumGetExpandedArray(Datum d)
AnyArrayType * DatumGetAnyArrayP(Datum d)
static Datum array_iter_next(array_iter *it, bool *isnull, int i)
static void array_iter_setup(array_iter *it, AnyArrayType *a, int elmlen, bool elmbyval, char elmalign)
Datum array_eq(PG_FUNCTION_ARGS)
Datum arraycontained(PG_FUNCTION_ARGS)
Datum array_lt(PG_FUNCTION_ARGS)
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
static bool ReadArrayStr(char **srcptr, FmgrInfo *inputproc, Oid typioparam, int32 typmod, char typdelim, int typlen, bool typbyval, char typalign, int *ndim_p, int *dim, int *nitems_p, Datum **values_p, bool **nulls_p, const char *origStr, Node *escontext)
Datum array_fill(PG_FUNCTION_ARGS)
Datum array_replace(PG_FUNCTION_ARGS)
static ArrayType * array_replace_internal(ArrayType *array, Datum search, bool search_isnull, Datum replace, bool replace_isnull, bool remove, Oid collation, FunctionCallInfo fcinfo)
Datum array_smaller(PG_FUNCTION_ARGS)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
static bool ReadArrayDimensions(char **srcptr, int *ndim_p, int *dim, int *lBound, const char *origStr, Node *escontext)
Datum array_cardinality(PG_FUNCTION_ARGS)
ExpandedArrayHeader * construct_empty_expanded_array(Oid element_type, MemoryContext parentcontext, ArrayMetaState *metacache)
bool array_iterate(ArrayIterator iterator, Datum *value, bool *isnull)
static Datum array_set_element_expanded(Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
void array_free_iterator(ArrayIterator iterator)
Datum array_recv(PG_FUNCTION_ARGS)
Datum generate_subscripts_nodir(PG_FUNCTION_ARGS)
Datum hash_array(PG_FUNCTION_ARGS)
static int width_bucket_array_float8(Datum operand, ArrayType *thresholds)
ArrayBuildStateAny * initArrayResultAny(Oid input_type, MemoryContext rcontext, bool subcontext)
ArrayBuildStateAny * accumArrayResultAny(ArrayBuildStateAny *astate, Datum dvalue, bool disnull, Oid input_type, MemoryContext rcontext)
ArrayType * construct_empty_array(Oid elmtype)
Datum array_dims(PG_FUNCTION_ARGS)
bool array_contains_nulls(const ArrayType *array)
static ArrayToken ReadArrayToken(char **srcptr, StringInfo elembuf, char typdelim, const char *origStr, Node *escontext)
Datum arraycontains(PG_FUNCTION_ARGS)
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 bool array_get_isnull(const bits8 *nullbitmap, int offset)
Datum makeArrayResultArr(ArrayBuildStateArr *astate, MemoryContext rcontext, bool release)
#define AARR_FREE_IF_COPY(array, n)
Datum array_upper(PG_FUNCTION_ARGS)
Datum makeArrayResultAny(ArrayBuildStateAny *astate, MemoryContext rcontext, bool release)
static ArrayType * array_fill_internal(ArrayType *dims, ArrayType *lbs, Datum value, bool isnull, Oid elmtype, FunctionCallInfo fcinfo)
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Datum array_map(Datum arrayd, ExprState *exprstate, ExprContext *econtext, Oid retType, ArrayMapState *amstate)
Datum array_set_element(Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Datum makeMdArrayResult(ArrayBuildState *astate, int ndims, int *dims, int *lbs, MemoryContext rcontext, bool release)
static bool ReadDimensionInt(char **srcptr, int *result, const char *origStr, Node *escontext)
ArrayBuildStateArr * initArrayResultArr(Oid array_type, Oid element_type, MemoryContext rcontext, bool subcontext)
static bool array_contain_compare(AnyArrayType *array1, AnyArrayType *array2, Oid collation, bool matchall, void **fn_extra)
Datum array_lower(PG_FUNCTION_ARGS)
static int width_bucket_array_fixed(Datum operand, ArrayType *thresholds, Oid collation, TypeCacheEntry *typentry)
ArrayBuildStateArr * accumArrayResultArr(ArrayBuildStateArr *astate, Datum dvalue, bool disnull, Oid array_type, MemoryContext rcontext)
static int array_cmp(FunctionCallInfo fcinfo)
ArrayIterator array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate)
Datum btarraycmp(PG_FUNCTION_ARGS)
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
static void ReadArrayBinary(StringInfo buf, int nitems, FmgrInfo *receiveproc, Oid typioparam, int32 typmod, int typlen, bool typbyval, char typalign, Datum *values, bool *nulls, bool *hasnulls, int32 *nbytes)
static Datum array_get_element_expanded(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
ArrayBuildState * initArrayResultWithSize(Oid element_type, MemoryContext rcontext, bool subcontext, int initsize)
Datum hash_array_extended(PG_FUNCTION_ARGS)
Datum generate_subscripts(PG_FUNCTION_ARGS)
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)
Datum array_send(PG_FUNCTION_ARGS)
Datum array_le(PG_FUNCTION_ARGS)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
static int array_copy(char *destptr, int nitems, char *srcptr, int offset, bits8 *nullbitmap, int typlen, bool typbyval, char typalign)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
Datum array_gt(PG_FUNCTION_ARGS)
Datum array_unnest(PG_FUNCTION_ARGS)
static ArrayType * create_array_envelope(int ndims, int *dimv, int *lbsv, int nbytes, Oid elmtype, int dataoffset)
Datum array_remove(PG_FUNCTION_ARGS)
Datum array_ne(PG_FUNCTION_ARGS)
Datum array_larger(PG_FUNCTION_ARGS)
Datum array_in(PG_FUNCTION_ARGS)
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)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
static int width_bucket_array_variable(Datum operand, ArrayType *thresholds, Oid collation, TypeCacheEntry *typentry)
Datum array_length(PG_FUNCTION_ARGS)
void deconstruct_array_builtin(const ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
static int array_nelems_size(char *ptr, int offset, bits8 *nullbitmap, int nitems, int typlen, bool typbyval, char typalign)
static void array_set_isnull(bits8 *nullbitmap, int offset, bool isNull)
void deconstruct_array(const ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
static int ArrayCastAndSet(Datum src, int typlen, bool typbyval, uint8 typalignby, char *dest)
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
static Datum ArrayCast(char *value, bool byval, int len)
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Datum array_out(PG_FUNCTION_ARGS)
Datum array_fill_with_lower_bounds(PG_FUNCTION_ARGS)
Datum array_ndims(PG_FUNCTION_ARGS)
static char * array_seek(char *ptr, int offset, bits8 *nullbitmap, int nitems, int typlen, bool typbyval, char typalign)
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_ge(PG_FUNCTION_ARGS)
Datum width_bucket_array(PG_FUNCTION_ARGS)
Datum arrayoverlap(PG_FUNCTION_ARGS)
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)
void CopyArrayEls(ArrayType *array, const Datum *values, const bool *nulls, int nitems, int typlen, bool typbyval, char typalign, bool freedata)
Datum trim_array(PG_FUNCTION_ARGS)
Datum array_unnest_support(PG_FUNCTION_ARGS)
void mda_get_offset_values(int n, int *dist, const int *prod, const int *span)
int ArrayGetOffset(int n, const int *dim, const int *lb, const int *indx)
void mda_get_range(int n, int *span, const int *st, const int *endp)
int ArrayGetNItems(int ndim, const int *dims)
void mda_get_prod(int n, const int *range, int *prod)
void ArrayCheckBounds(int ndim, const int *dims, const int *lb)
int mda_next_tuple(int n, int *curr, const int *span)
static Datum values[MAXATTR]
#define FORMAT_TYPE_ALLOW_INVALID
#define Assert(condition)
#define OidIsValid(objectId)
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Datum datumCopy(Datum value, bool typByVal, int typLen)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
ExpandedObjectHeader * DatumGetEOHP(Datum d)
#define VARATT_IS_EXPANDED_HEADER(PTR)
static Datum EOHPGetRWDatum(const struct ExpandedObjectHeader *eohptr)
#define palloc_object(type)
#define repalloc_array(pointer, type, count)
#define palloc_array(type, count)
#define palloc0_array(type, count)
#define palloc0_object(type)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
bool InputFunctionCallSafe(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod, Node *escontext, Datum *result)
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_RETURN_UINT32(x)
#define PG_RETURN_BYTEA_P(x)
#define PG_DETOAST_DATUM_COPY(datum)
#define PG_GETARG_POINTER(n)
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
#define PG_RETURN_CSTRING(x)
#define PG_GETARG_DATUM(n)
#define LOCAL_FCINFO(name, nargs)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_RETURN_UINT64(x)
#define PG_DETOAST_DATUM(datum)
#define FunctionCallInvoke(fcinfo)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_POINTER(x)
#define PG_GET_COLLATION()
#define PG_RETURN_BOOL(x)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
#define SRF_RETURN_DONE(_funcctx)
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Oid get_element_type(Oid typid)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
void get_type_io_data(Oid typid, IOFuncSelector which_func, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *func)
Oid get_array_type(Oid typid)
void * MemoryContextAlloc(MemoryContext context, Size size)
void * MemoryContextAllocZero(MemoryContext context, Size size)
char * pstrdup(const char *in)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define AllocSizeIsValid(size)
static bool is_funcclause(const void *clause)
#define IsA(nodeptr, _type_)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static uint32 pg_nextpower2_32(uint32 num)
static const struct exclude_list_item skip[]
static char buf[DEFAULT_XLOG_SEG_SIZE]
int pg_strcasecmp(const char *s1, const char *s2)
static uint32 DatumGetUInt32(Datum X)
static Datum Int64GetDatum(int64 X)
static uint64 DatumGetUInt64(Datum X)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static float8 DatumGetFloat8(Datum X)
static Pointer DatumGetPointer(Datum X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
bool scanner_isspace(char ch)
double estimate_array_length(PlannerInfo *root, Node *arrayexpr)
struct StringInfoData * StringInfo
void resetStringInfo(StringInfo str)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
static void initReadOnlyStringInfo(StringInfo str, char *data, int len)
ArrayBuildStateArr * arraystate
ArrayBuildState * scalarstate
bool * innermost_casenull
Datum * innermost_caseval
FmgrInfo hash_extended_proc_finfo
#define FirstGenbkiObjectId
#define att_nominal_alignby(cur_offset, attalignby)
#define att_addlength_pointer(cur_offset, attlen, attptr)
static uint8 typalign_to_alignby(char typalign)
static Datum fetch_att(const void *T, bool attbyval, int attlen)
#define att_addlength_datum(cur_offset, attlen, attdatum)
static void store_att_byval(void *T, Datum newdatum, int attlen)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
#define TYPECACHE_HASH_PROC_FINFO
#define TYPECACHE_EQ_OPR_FINFO
#define TYPECACHE_HASH_EXTENDED_PROC_FINFO
#define TYPECACHE_CMP_PROC_FINFO
static Size VARSIZE(const void *PTR)
static char * VARDATA(const void *PTR)
static bool VARATT_IS_EXTERNAL_EXPANDED(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)
text * cstring_to_text(const char *s)