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); \
100 int typlen,
bool typbyval,
char typalign,
109 int typlen,
bool typbyval,
char typalign,
126 int typlen,
bool typbyval,
char typalign,
129 int typlen,
bool typbyval,
char typalign);
134 int typlen,
bool typbyval,
char typalign);
136 int ndim,
int *dim,
int *lb,
138 int typlen,
bool typbyval,
char typalign);
140 int ndim,
int *dim,
int *lb,
143 int typlen,
bool typbyval,
char typalign);
146 int ndim,
int *dim,
int *lb,
148 int typlen,
bool typbyval,
char typalign);
158 bool remove,
Oid collation,
186 Node *escontext = fcinfo->context;
219 if (
my_extra->element_type != element_type)
229 fcinfo->flinfo->fn_mcxt);
230 my_extra->element_type = element_type;
265 errmsg(
"malformed array literal: \"%s\"",
string),
266 errdetail(
"Array value must start with \"{\" or dimension information.")));
274 errmsg(
"malformed array literal: \"%s\"",
string),
275 errdetail(
"Missing \"%s\" after array dimensions.",
285 errmsg(
"malformed array literal: \"%s\"",
string),
286 errdetail(
"Array contents must start with \"{\".")));
291 &
my_extra->proc, typioparam, typmod,
308 errmsg(
"malformed array literal: \"%s\"",
string),
309 errdetail(
"Junk after closing right brace.")));
336 errmsg(
"array size exceeds the maximum allowed (%zu)",
343 nbytes += dataoffset;
432 errmsg(
"number of array dimensions exceeds the maximum allowed (%d)",
442 errdetail(
"\"[\" must introduce explicitly-specified array dimensions.")));
456 errdetail(
"Missing array dimension value.")));
468 errdetail(
"Missing \"%s\" after array dimensions.",
482 errmsg(
"upper bound cannot be less than lower bound")));
488 errmsg(
"array upper bound is too large: %d",
ub)));
495 errmsg(
"array size exceeds the maximum allowed (%zu)",
527 if (!
isdigit((
unsigned char) *p) && *p !=
'-' && *p !=
'+')
539 errmsg(
"array bound is out of integer range")));
638 errdetail(
"Unexpected \"%c\" character.",
'{')));
644 errmsg(
"number of array dimensions exceeds the maximum allowed (%d)",
647 nelems[nest_level] = 0;
649 if (nest_level > ndim)
670 errdetail(
"Unexpected \"%c\" character.",
675 nelems[nest_level - 1]++;
682 if (dim[nest_level] < 0)
685 dim[nest_level] = nelems[nest_level];
687 else if (nelems[nest_level] != dim[nest_level])
705 errdetail(
"Unexpected \"%c\" character.",
720 errdetail(
"Unexpected array element.")));
728 errmsg(
"array size exceeds the maximum allowed (%zu)",
751 if (nest_level != ndim)
754 nelems[nest_level - 1]++;
763 }
while (nest_level > 0);
779 errdetail(
"Specified array dimensions do not match array contents.")));
784 errdetail(
"Multidimensional arrays must have sub-arrays with matching dimensions.")));
861 while (*(++p) !=
'\0')
863 if (*p == typdelim || *p ==
'}' || *p ==
'{')
872 errdetail(
"Incorrectly quoted array element.")));
899 errdetail(
"Unexpected \"%c\" character.",
906 errdetail(
"Incorrectly quoted array element.")));
918 if (*p == typdelim || *p ==
'}')
982 if (nulls && nulls[
i])
985 elog(
ERROR,
"null array element where not supported");
998 if (bitmask == 0x100)
1007 if (bitmap && bitmask != 1)
1064 if (
my_extra->element_type != element_type)
1074 fcinfo->flinfo->fn_mcxt);
1075 my_extra->element_type = element_type;
1097 for (
i = 0;
i < ndim;
i++)
1145 for (tmp =
values[
i]; *tmp !=
'\0'; tmp++)
1150 if (
ch ==
'"' ||
ch ==
'\\')
1155 else if (
ch ==
'{' ||
ch ==
'}' ||
ch == typdelim ||
1176 for (
i =
j = 0, k = 1;
i < ndim;
i++)
1178 j += k, k *= dims[
i];
1188 for (
i = 0;
i < ndim;
i++)
1190 sprintf(ptr,
"[%d:%d]", lb[
i], lb[
i] + dims[
i] - 1);
1202#define APPENDSTR(str) (strcpy(p, (str)), p += strlen(p))
1203#define APPENDCHAR(ch) (*p++ = (ch), *p = '\0')
1208 for (
i = 0;
i < ndim;
i++)
1214 for (
i =
j;
i < ndim - 1;
i++)
1220 for (tmp =
values[k]; *tmp; tmp++)
1224 if (
ch ==
'"' ||
ch ==
'\\')
1235 for (
i = ndim - 1;
i >= 0;
i--)
1237 if (++(
indx[
i]) < dims[
i])
1302 errmsg(
"invalid number of dimensions: %d", ndim)));
1306 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
1310 if (flags != 0 && flags != 1)
1313 errmsg(
"invalid array flags")));
1335 errmsg(
"binary data has array element type %u (%s) instead of expected %u (%s)",
1345 for (
i = 0;
i < ndim;
i++)
1369 if (
my_extra->element_type != element_type)
1379 errmsg(
"no binary input function available for type %s",
1382 fcinfo->flinfo->fn_mcxt);
1383 my_extra->element_type = element_type;
1400 &
my_extra->proc, typioparam, typmod,
1407 nbytes += dataoffset;
1416 retval->
ndim = ndim;
1482 errmsg(
"insufficient data left in message")));
1488 typioparam, typmod);
1503 typioparam, typmod);
1510 errmsg(
"improper binary format in array element %d",
1534 errmsg(
"array size exceeds the maximum allowed (%zu)",
1579 if (
my_extra->element_type != element_type)
1589 errmsg(
"no binary output function available for type %s",
1592 fcinfo->flinfo->fn_mcxt);
1593 my_extra->element_type = element_type;
1610 for (
i = 0;
i < ndim;
i++)
1886 for (
i = 0;
i < ndim;
i++)
1958 for (
i = 0;
i < ndim;
i++)
1978 dvalues =
eah->dvalues;
1979 dnulls =
eah->dnulls;
1984 if (dnulls && dnulls[offset])
1997 return dvalues[offset];
2068 errmsg(
"slices of fixed-length arrays not implemented")));
2115 for (;
i < ndim;
i++)
2137 bytes += dataoffset;
2157 for (
i = 0;
i < ndim;
i++)
2246 errmsg(
"wrong number of array subscripts")));
2251 errmsg(
"array subscript out of range")));
2256 errmsg(
"cannot assign null value to an element of a fixed-length array")));
2268 errmsg(
"wrong number of array subscripts")));
2271 if (
elmlen == -1 && !isNull)
2317 errmsg(
"wrong number of array subscripts")));
2334 if (
indx[0] < lb[0])
2342 errmsg(
"array size exceeds the maximum allowed (%zu)",
2348 if (
indx[0] >= (dim[0] + lb[0]))
2357 errmsg(
"array size exceeds the maximum allowed (%zu)",
2369 for (
i = 0;
i < ndim;
i++)
2375 errmsg(
"array subscript out of range")));
2538 memcpy(dim,
eah->dims, ndim *
sizeof(
int));
2539 memcpy(lb,
eah->lbound, ndim *
sizeof(
int));
2571 errmsg(
"wrong number of array subscripts")));
2589 if (!
eah->typbyval && !isNull)
2597 dvalues =
eah->dvalues;
2598 dnulls =
eah->dnulls;
2611 if (
indx[0] < lb[0])
2619 errmsg(
"array size exceeds the maximum allowed (%zu)",
2626 if (
indx[0] >= (dim[0] + lb[0]))
2635 errmsg(
"array size exceeds the maximum allowed (%zu)",
2648 for (
i = 0;
i < ndim;
i++)
2654 errmsg(
"array subscript out of range")));
2669 if (dim[0] >
eah->dvalueslen)
2672 int newlen = dim[0] + dim[0] / 8;
2678 eah->dnulls = dnulls = (
bool *)
2688 eah->dnulls = dnulls = (
bool *)
2690 eah->dvalueslen *
sizeof(
bool));
2706 memcpy(
eah->dims, dim, ndim *
sizeof(
int));
2707 memcpy(
eah->lbound, lb, ndim *
sizeof(
int));
2733 dnulls[
eah->nelems +
i] =
true;
2739 if (!
eah->typbyval && (dnulls ==
NULL || !dnulls[offset]))
2747 dnulls[offset] = isNull;
2856 errmsg(
"updates on slices of fixed-length arrays not implemented")));
2880 &dvalues, &dnulls, &nelems);
2887 errmsg(
"array slice subscript must provide both boundaries"),
2888 errdetail(
"When assigning to a slice of an empty array value,"
2889 " slice boundaries must be fully specified.")));
2896 errmsg(
"array size exceeds the maximum allowed (%zu)",
2906 errmsg(
"source array too small")));
2916 errmsg(
"wrong number of array subscripts")));
2941 errmsg(
"upper bound cannot be less than lower bound")));
2950 errmsg(
"array size exceeds the maximum allowed (%zu)",
2965 errmsg(
"array size exceeds the maximum allowed (%zu)",
2986 errmsg(
"upper bound cannot be less than lower bound")));
2991 errmsg(
"array subscript out of range")));
2994 for (;
i < ndim;
i++)
3001 errmsg(
"upper bound cannot be less than lower bound")));
3018 errmsg(
"source array too small")));
3270 typlen = ret_extra->
typlen;
3306 errmsg(
"array size exceeds the maximum allowed (%zu)",
3315 nbytes += dataoffset;
3324 result->
ndim = ndim;
3464 elog(
ERROR,
"type %u not supported by construct_array_builtin()",
elmtype);
3512 errmsg(
"invalid number of dimensions: %d", ndims)));
3516 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
3530 for (
i = 0;
i < nelems;
i++)
3532 if (nulls && nulls[
i])
3546 errmsg(
"array size exceeds the maximum allowed (%zu)",
3554 nbytes += dataoffset;
3563 result->
ndim = ndims;
3570 elems, nulls, nelems,
3659 for (
i = 0;
i < nelems;
i++)
3662 if (bitmap && (*bitmap & bitmask) == 0)
3670 errmsg(
"null array element not allowed in this context")));
3683 if (bitmask == 0x100)
3751 elog(
ERROR,
"type %u not supported by deconstruct_array_builtin()",
elmtype);
3785 if (*bitmap != 0xFF)
3795 if ((*bitmap & bitmask) == 0)
3841 errmsg(
"cannot compare arrays of different element types")));
3857 if (typentry ==
NULL ||
3858 typentry->
type_id != element_type)
3865 errmsg(
"could not identify an equality operator for type %s",
3867 fcinfo->flinfo->fn_extra = typentry;
3869 typlen = typentry->
typlen;
4012 errmsg(
"cannot compare arrays of different element types")));
4021 if (typentry ==
NULL ||
4022 typentry->
type_id != element_type)
4029 errmsg(
"could not identify a comparison function for type %s",
4033 typlen = typentry->
typlen;
4136 result = (lbound1[
i] <
lbound2[
i]) ? -1 : 1;
4182 if (typentry ==
NULL ||
4183 typentry->
type_id != element_type)
4190 errmsg(
"could not identify a hash function for type %s",
4226 fcinfo->flinfo->fn_extra = typentry;
4229 typlen = typentry->
typlen;
4278 result = (result << 5) - result +
elthash;
4310 if (typentry ==
NULL ||
4311 typentry->
type_id != element_type)
4318 errmsg(
"could not identify an extended hash function for type %s",
4320 fcinfo->flinfo->fn_extra = typentry;
4322 typlen = typentry->
typlen;
4358 result = (result << 5) - result +
elthash;
4403 errmsg(
"cannot compare arrays of different element types")));
4412 if (typentry ==
NULL ||
4413 typentry->
type_id != element_type)
4420 errmsg(
"could not identify an equality operator for type %s",
4422 *fn_extra = typentry;
4424 typlen = typentry->
typlen;
4443 element_type, typlen, typbyval,
typalign,
4533 &fcinfo->flinfo->fn_extra);
4551 &fcinfo->flinfo->fn_extra);
4569 &fcinfo->flinfo->fn_extra);
4607 elog(
ERROR,
"invalid arguments to array_create_iterator");
4714 bool *nulls =
iterator->slice_nulls;
4784 if (nullbitmap ==
NULL)
4786 if (nullbitmap[offset / 8] & (1 << (offset % 8)))
4803 nullbitmap += offset / 8;
4804 bitmask = 1 << (offset % 8);
4808 *nullbitmap |= bitmask;
4868 int typlen,
bool typbyval,
char typalign)
4874 if (typlen > 0 && !nullbitmap)
4880 nullbitmap += offset / 8;
4881 bitmask = 1 << (offset % 8);
4885 if (*nullbitmap & bitmask)
4891 if (bitmask == 0x100)
4916 int typlen,
bool typbyval,
char typalign)
4939 int typlen,
bool typbyval,
char typalign)
5039 int ndim,
int *dim,
int *lb,
5041 int typlen,
bool typbyval,
char typalign)
5066 for (
i = 0;
i < ndim;
i++)
5129 for (
i = 0;
i < ndim;
i++)
5215 for (
i = 0;
i < ndim;
i++)
5302 subcontext ? 64 : 8);
5330 astate->
dnulls = (
bool *)
5378 errmsg(
"array size exceeds the maximum allowed (%zu)",
5382 astate->
dnulls = (
bool *)
5396 if (astate->
typlen == -1)
5429 ndims = (astate->
nelems > 0) ? 1 : 0;
5430 dims[0] = astate->
nelems;
5519 errmsg(
"data type %s is not an array type",
5526 "accumArrayResultArr",
5574 errmsg(
"cannot accumulate null arrays")));
5594 if (astate->
ndims == 0)
5602 errmsg(
"cannot accumulate empty arrays")));
5606 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
5613 astate->
ndims = ndims + 1;
5614 astate->
dims[0] = 0;
5615 memcpy(&astate->
dims[1], dims, ndims *
sizeof(
int));
5617 memcpy(&astate->
lbs[1], lbs, ndims *
sizeof(
int));
5626 if (astate->
ndims != ndims + 1)
5629 errmsg(
"cannot accumulate arrays of different dimensionality")));
5630 for (
i = 0;
i < ndims;
i++)
5632 if (astate->
dims[
i + 1] != dims[
i] || astate->
lbs[
i + 1] != lbs[
i])
5635 errmsg(
"cannot accumulate arrays of different dimensionality")));
5685 astate->
dims[0] += 1;
5714 if (astate->
ndims == 0)
5733 nbytes += dataoffset;
6005 errmsg(
"dimension array or low bound array cannot be null")));
6023 elog(
ERROR,
"could not determine data type of input");
6045 errmsg(
"dimension array or low bound array cannot be null")));
6062 elog(
ERROR,
"could not determine data type of input");
6076 result->
ndim = ndims;
6107 errmsg(
"wrong number of array subscripts"),
6108 errdetail(
"Dimension array must be one dimensional.")));
6113 errmsg(
"dimension values cannot be null")));
6121 errmsg(
"invalid number of dimensions: %d", ndims)));
6125 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
6133 errmsg(
"wrong number of array subscripts"),
6134 errdetail(
"Dimension array must be one dimensional.")));
6139 errmsg(
"dimension values cannot be null")));
6144 errmsg(
"wrong number of array subscripts"),
6145 errdetail(
"Low bound array has different size than dimensions array.")));
6217 errmsg(
"array size exceeds the maximum allowed (%zu)",
6239 nbytes = dataoffset;
6322 if (
fctx->nextelem <
fctx->numelems)
6324 int offset =
fctx->nextelem++;
6385 bool remove,
Oid collation,
6423 if (remove && ndim > 1)
6426 errmsg(
"removing elements from multidimensional arrays is not supported")));
6433 if (typentry ==
NULL ||
6434 typentry->
type_id != element_type)
6441 errmsg(
"could not identify an equality operator for type %s",
6445 typlen = typentry->
typlen;
6485 if (bitmap && (*bitmap & bitmask) == 0)
6561 errmsg(
"array size exceeds the maximum allowed (%zu)",
6571 if (bitmask == 0x100)
6601 nbytes += dataoffset;
6610 result->
ndim = ndim;
6703 errmsg(
"thresholds must be one-dimensional array")));
6708 errmsg(
"thresholds array must not contain NULLs")));
6719 if (typentry ==
NULL ||
6720 typentry->
type_id != element_type)
6727 errmsg(
"could not identify a comparison function for type %s",
6729 fcinfo->flinfo->fn_extra = typentry;
6736 if (typentry->
typlen > 0)
6738 collation, typentry);
6741 collation, typentry);
6781 while (left < right)
6783 int mid = (left + right) / 2;
6805 int typlen = typentry->
typlen;
6806 bool typbyval = typentry->
typbyval;
6822 while (left < right)
6824 int mid = (left + right) / 2;
6860 int typlen = typentry->
typlen;
6861 bool typbyval = typentry->
typbyval;
6874 while (left < right)
6876 int mid = (left + right) / 2;
6883 for (
i = left;
i < mid;
i++)
6941 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, int elmlen, bool elmbyval, char elmalign)
static void array_iter_setup(array_iter *it, AnyArrayType *a)
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)
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
static int ArrayCastAndSet(Datum src, int typlen, bool typbyval, char typalign, char *dest)
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_align_nominal(cur_offset, attalign)
#define att_addlength_pointer(cur_offset, attlen, attptr)
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)