mirror of https://github.com/postgres/postgres
Add construct_array_builtin, deconstruct_array_builtin
There were many calls to construct_array() and deconstruct_array() for built-in types, for example, when dealing with system catalog columns. These all hardcoded the type attributes necessary to pass to these functions. To simplify this a bit, add construct_array_builtin(), deconstruct_array_builtin() as wrappers that centralize this hardcoded knowledge. This simplifies many call sites and reduces the amount of hardcoded stuff that is spread around. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/2914356f-9e5f-8c59-2995-5997fc48bcba%40enterprisedb.com
This commit is contained in:
parent
7c2d6f8d34
commit
d746021de1
|
@ -118,9 +118,7 @@ gin_extract_hstore_query(PG_FUNCTION_ARGS)
|
|||
j;
|
||||
text *item;
|
||||
|
||||
deconstruct_array(query,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &key_count);
|
||||
deconstruct_array_builtin(query, TEXTOID, &key_datums, &key_nulls, &key_count);
|
||||
|
||||
entries = (Datum *) palloc(sizeof(Datum) * key_count);
|
||||
|
||||
|
|
|
@ -560,9 +560,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
|
|||
int key_count;
|
||||
int i;
|
||||
|
||||
deconstruct_array(query,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &key_count);
|
||||
deconstruct_array_builtin(query, TEXTOID, &key_datums, &key_nulls, &key_count);
|
||||
|
||||
for (i = 0; res && i < key_count; ++i)
|
||||
{
|
||||
|
@ -583,9 +581,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
|
|||
int key_count;
|
||||
int i;
|
||||
|
||||
deconstruct_array(query,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &key_count);
|
||||
deconstruct_array_builtin(query, TEXTOID, &key_datums, &key_nulls, &key_count);
|
||||
|
||||
res = false;
|
||||
|
||||
|
|
|
@ -567,9 +567,7 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
|
|||
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
|
||||
errmsg("wrong number of array subscripts")));
|
||||
|
||||
deconstruct_array(key_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &key_count);
|
||||
deconstruct_array_builtin(key_array, TEXTOID, &key_datums, &key_nulls, &key_count);
|
||||
|
||||
/* see discussion in hstoreArrayToPairs() */
|
||||
if (key_count > MaxAllocSize / sizeof(Pairs))
|
||||
|
@ -606,9 +604,7 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
|
|||
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
|
||||
errmsg("arrays must have same bounds")));
|
||||
|
||||
deconstruct_array(value_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&value_datums, &value_nulls, &value_count);
|
||||
deconstruct_array_builtin(value_array, TEXTOID, &value_datums, &value_nulls, &value_count);
|
||||
|
||||
Assert(key_count == value_count);
|
||||
}
|
||||
|
@ -696,9 +692,7 @@ hstore_from_array(PG_FUNCTION_ARGS)
|
|||
errmsg("wrong number of array subscripts")));
|
||||
}
|
||||
|
||||
deconstruct_array(in_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&in_datums, &in_nulls, &in_count);
|
||||
deconstruct_array_builtin(in_array, TEXTOID, &in_datums, &in_nulls, &in_count);
|
||||
|
||||
count = in_count / 2;
|
||||
|
||||
|
|
|
@ -80,9 +80,7 @@ hstoreArrayToPairs(ArrayType *a, int *npairs)
|
|||
int i,
|
||||
j;
|
||||
|
||||
deconstruct_array(a,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &key_count);
|
||||
deconstruct_array_builtin(a, TEXTOID, &key_datums, &key_nulls, &key_count);
|
||||
|
||||
if (key_count == 0)
|
||||
{
|
||||
|
@ -582,9 +580,7 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
|
|||
int key_count;
|
||||
int i;
|
||||
|
||||
deconstruct_array(key_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &key_count);
|
||||
deconstruct_array_builtin(key_array, TEXTOID, &key_datums, &key_nulls, &key_count);
|
||||
|
||||
if (key_count == 0)
|
||||
{
|
||||
|
@ -719,8 +715,7 @@ hstore_akeys(PG_FUNCTION_ARGS)
|
|||
d[i] = PointerGetDatum(t);
|
||||
}
|
||||
|
||||
a = construct_array(d, count,
|
||||
TEXTOID, -1, false, TYPALIGN_INT);
|
||||
a = construct_array_builtin(d, count, TEXTOID);
|
||||
|
||||
PG_RETURN_POINTER(a);
|
||||
}
|
||||
|
|
|
@ -425,11 +425,7 @@ bt_page_print_tuples(struct user_args *uargs)
|
|||
tids_datum = (Datum *) palloc(nposting * sizeof(Datum));
|
||||
for (int i = 0; i < nposting; i++)
|
||||
tids_datum[i] = ItemPointerGetDatum(&tids[i]);
|
||||
values[j++] = PointerGetDatum(construct_array(tids_datum,
|
||||
nposting,
|
||||
TIDOID,
|
||||
sizeof(ItemPointerData),
|
||||
false, TYPALIGN_SHORT));
|
||||
values[j++] = PointerGetDatum(construct_array_builtin(tids_datum, nposting, TIDOID));
|
||||
pfree(tids_datum);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -166,9 +166,7 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
|
|||
|
||||
values[0] = Int64GetDatum(opaq->rightlink);
|
||||
values[1] = Int32GetDatum(opaq->maxoff);
|
||||
values[2] = PointerGetDatum(construct_array(flags, nflags,
|
||||
TEXTOID,
|
||||
-1, false, TYPALIGN_INT));
|
||||
values[2] = PointerGetDatum(construct_array_builtin(flags, nflags, TEXTOID));
|
||||
|
||||
/* Build and return the result tuple. */
|
||||
resultTuple = heap_form_tuple(tupdesc, values, nulls);
|
||||
|
@ -273,11 +271,7 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
|
|||
tids_datum = (Datum *) palloc(ndecoded * sizeof(Datum));
|
||||
for (i = 0; i < ndecoded; i++)
|
||||
tids_datum[i] = ItemPointerGetDatum(&tids[i]);
|
||||
values[2] = PointerGetDatum(construct_array(tids_datum,
|
||||
ndecoded,
|
||||
TIDOID,
|
||||
sizeof(ItemPointerData),
|
||||
false, TYPALIGN_SHORT));
|
||||
values[2] = PointerGetDatum(construct_array_builtin(tids_datum, ndecoded, TIDOID));
|
||||
pfree(tids_datum);
|
||||
pfree(tids);
|
||||
|
||||
|
|
|
@ -104,9 +104,7 @@ gist_page_opaque_info(PG_FUNCTION_ARGS)
|
|||
values[0] = LSNGetDatum(PageGetLSN(page));
|
||||
values[1] = LSNGetDatum(GistPageGetNSN(page));
|
||||
values[2] = Int64GetDatum(opaq->rightlink);
|
||||
values[3] = PointerGetDatum(construct_array(flags, nflags,
|
||||
TEXTOID,
|
||||
-1, false, TYPALIGN_INT));
|
||||
values[3] = PointerGetDatum(construct_array_builtin(flags, nflags, TEXTOID));
|
||||
|
||||
/* Build and return the result tuple. */
|
||||
resultTuple = heap_form_tuple(tupdesc, values, nulls);
|
||||
|
|
|
@ -564,21 +564,11 @@ hash_metapage_info(PG_FUNCTION_ARGS)
|
|||
|
||||
for (i = 0; i < HASH_MAX_SPLITPOINTS; i++)
|
||||
spares[i] = Int64GetDatum((int64) metad->hashm_spares[i]);
|
||||
values[j++] = PointerGetDatum(construct_array(spares,
|
||||
HASH_MAX_SPLITPOINTS,
|
||||
INT8OID,
|
||||
sizeof(int64),
|
||||
FLOAT8PASSBYVAL,
|
||||
TYPALIGN_DOUBLE));
|
||||
values[j++] = PointerGetDatum(construct_array_builtin(spares, HASH_MAX_SPLITPOINTS, INT8OID));
|
||||
|
||||
for (i = 0; i < HASH_MAX_BITMAPS; i++)
|
||||
mapp[i] = Int64GetDatum((int64) metad->hashm_mapp[i]);
|
||||
values[j++] = PointerGetDatum(construct_array(mapp,
|
||||
HASH_MAX_BITMAPS,
|
||||
INT8OID,
|
||||
sizeof(int64),
|
||||
FLOAT8PASSBYVAL,
|
||||
TYPALIGN_DOUBLE));
|
||||
values[j++] = PointerGetDatum(construct_array_builtin(mapp, HASH_MAX_BITMAPS, INT8OID));
|
||||
|
||||
tuple = heap_form_tuple(tupleDesc, values, nulls);
|
||||
|
||||
|
|
|
@ -590,7 +590,7 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
|
|||
|
||||
/* build value */
|
||||
Assert(cnt <= bitcnt);
|
||||
a = construct_array(flags, cnt, TEXTOID, -1, false, TYPALIGN_INT);
|
||||
a = construct_array_builtin(flags, cnt, TEXTOID);
|
||||
values[0] = PointerGetDatum(a);
|
||||
|
||||
/*
|
||||
|
@ -612,7 +612,7 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
|
|||
if (cnt == 0)
|
||||
a = construct_empty_array(TEXTOID);
|
||||
else
|
||||
a = construct_array(flags, cnt, TEXTOID, -1, false, TYPALIGN_INT);
|
||||
a = construct_array_builtin(flags, cnt, TEXTOID);
|
||||
pfree(flags);
|
||||
values[1] = PointerGetDatum(a);
|
||||
|
||||
|
|
|
@ -977,12 +977,7 @@ show_trgm(PG_FUNCTION_ARGS)
|
|||
d[i] = PointerGetDatum(item);
|
||||
}
|
||||
|
||||
a = construct_array(d,
|
||||
ARRNELEM(trg),
|
||||
TEXTOID,
|
||||
-1,
|
||||
false,
|
||||
TYPALIGN_INT);
|
||||
a = construct_array_builtin(d, ARRNELEM(trg), TEXTOID);
|
||||
|
||||
for (i = 0; i < ARRNELEM(trg); i++)
|
||||
pfree(DatumGetPointer(d[i]));
|
||||
|
|
|
@ -774,13 +774,8 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
|
|||
if (nkdims == 0)
|
||||
return 0;
|
||||
|
||||
deconstruct_array(key_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &key_count);
|
||||
|
||||
deconstruct_array(val_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&val_datums, &val_nulls, &val_count);
|
||||
deconstruct_array_builtin(key_array, TEXTOID, &key_datums, &key_nulls, &key_count);
|
||||
deconstruct_array_builtin(val_array, TEXTOID, &val_datums, &val_nulls, &val_count);
|
||||
|
||||
if (key_count != val_count)
|
||||
ereport(ERROR,
|
||||
|
|
|
@ -1177,8 +1177,7 @@ transformRelOptions(Datum oldOptions, List *defList, const char *namspace,
|
|||
int noldoptions;
|
||||
int i;
|
||||
|
||||
deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&oldoptions, NULL, &noldoptions);
|
||||
deconstruct_array_builtin(array, TEXTOID, &oldoptions, NULL, &noldoptions);
|
||||
|
||||
for (i = 0; i < noldoptions; i++)
|
||||
{
|
||||
|
@ -1345,8 +1344,7 @@ untransformRelOptions(Datum options)
|
|||
|
||||
array = DatumGetArrayTypeP(options);
|
||||
|
||||
deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&optiondatums, NULL, &noptions);
|
||||
deconstruct_array_builtin(array, TEXTOID, &optiondatums, NULL, &noptions);
|
||||
|
||||
for (i = 0; i < noptions; i++)
|
||||
{
|
||||
|
@ -1436,8 +1434,7 @@ parseRelOptionsInternal(Datum options, bool validate,
|
|||
int noptions;
|
||||
int i;
|
||||
|
||||
deconstruct_array(array, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&optiondatums, NULL, &noptions);
|
||||
deconstruct_array_builtin(array, TEXTOID, &optiondatums, NULL, &noptions);
|
||||
|
||||
for (i = 0; i < noptions; i++)
|
||||
{
|
||||
|
|
|
@ -2099,8 +2099,7 @@ textarray_to_strvaluelist(ArrayType *arr)
|
|||
List *list = NIL;
|
||||
int i;
|
||||
|
||||
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&elems, &nulls, &nelems);
|
||||
deconstruct_array_builtin(arr, TEXTOID, &elems, &nulls, &nelems);
|
||||
|
||||
for (i = 0; i < nelems; i++)
|
||||
{
|
||||
|
@ -2156,8 +2155,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
|
|||
bool *nulls;
|
||||
int nelems;
|
||||
|
||||
deconstruct_array(namearr, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&elems, &nulls, &nelems);
|
||||
deconstruct_array_builtin(namearr, TEXTOID, &elems, &nulls, &nelems);
|
||||
if (nelems != 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
|
@ -2174,8 +2172,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
|
|||
bool *nulls;
|
||||
int nelems;
|
||||
|
||||
deconstruct_array(namearr, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&elems, &nulls, &nelems);
|
||||
deconstruct_array_builtin(namearr, TEXTOID, &elems, &nulls, &nelems);
|
||||
if (nelems != 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
|
@ -2213,8 +2210,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
|
|||
int nelems;
|
||||
int i;
|
||||
|
||||
deconstruct_array(argsarr, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&elems, &nulls, &nelems);
|
||||
deconstruct_array_builtin(argsarr, TEXTOID, &elems, &nulls, &nelems);
|
||||
|
||||
args = NIL;
|
||||
for (i = 0; i < nelems; i++)
|
||||
|
|
|
@ -112,8 +112,7 @@ CreateConstraintEntry(const char *constraintName,
|
|||
conkey = (Datum *) palloc(constraintNKeys * sizeof(Datum));
|
||||
for (i = 0; i < constraintNKeys; i++)
|
||||
conkey[i] = Int16GetDatum(constraintKey[i]);
|
||||
conkeyArray = construct_array(conkey, constraintNKeys,
|
||||
INT2OID, 2, true, TYPALIGN_SHORT);
|
||||
conkeyArray = construct_array_builtin(conkey, constraintNKeys, INT2OID);
|
||||
}
|
||||
else
|
||||
conkeyArray = NULL;
|
||||
|
@ -125,27 +124,22 @@ CreateConstraintEntry(const char *constraintName,
|
|||
fkdatums = (Datum *) palloc(foreignNKeys * sizeof(Datum));
|
||||
for (i = 0; i < foreignNKeys; i++)
|
||||
fkdatums[i] = Int16GetDatum(foreignKey[i]);
|
||||
confkeyArray = construct_array(fkdatums, foreignNKeys,
|
||||
INT2OID, 2, true, TYPALIGN_SHORT);
|
||||
confkeyArray = construct_array_builtin(fkdatums, foreignNKeys, INT2OID);
|
||||
for (i = 0; i < foreignNKeys; i++)
|
||||
fkdatums[i] = ObjectIdGetDatum(pfEqOp[i]);
|
||||
conpfeqopArray = construct_array(fkdatums, foreignNKeys,
|
||||
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
|
||||
conpfeqopArray = construct_array_builtin(fkdatums, foreignNKeys, OIDOID);
|
||||
for (i = 0; i < foreignNKeys; i++)
|
||||
fkdatums[i] = ObjectIdGetDatum(ppEqOp[i]);
|
||||
conppeqopArray = construct_array(fkdatums, foreignNKeys,
|
||||
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
|
||||
conppeqopArray = construct_array_builtin(fkdatums, foreignNKeys, OIDOID);
|
||||
for (i = 0; i < foreignNKeys; i++)
|
||||
fkdatums[i] = ObjectIdGetDatum(ffEqOp[i]);
|
||||
conffeqopArray = construct_array(fkdatums, foreignNKeys,
|
||||
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
|
||||
conffeqopArray = construct_array_builtin(fkdatums, foreignNKeys, OIDOID);
|
||||
|
||||
if (numFkDeleteSetCols > 0)
|
||||
{
|
||||
for (i = 0; i < numFkDeleteSetCols; i++)
|
||||
fkdatums[i] = Int16GetDatum(fkDeleteSetCols[i]);
|
||||
confdelsetcolsArray = construct_array(fkdatums, numFkDeleteSetCols,
|
||||
INT2OID, 2, true, TYPALIGN_SHORT);
|
||||
confdelsetcolsArray = construct_array_builtin(fkdatums, numFkDeleteSetCols, INT2OID);
|
||||
}
|
||||
else
|
||||
confdelsetcolsArray = NULL;
|
||||
|
@ -166,8 +160,7 @@ CreateConstraintEntry(const char *constraintName,
|
|||
opdatums = (Datum *) palloc(constraintNKeys * sizeof(Datum));
|
||||
for (i = 0; i < constraintNKeys; i++)
|
||||
opdatums[i] = ObjectIdGetDatum(exclOp[i]);
|
||||
conexclopArray = construct_array(opdatums, constraintNKeys,
|
||||
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
|
||||
conexclopArray = construct_array_builtin(opdatums, constraintNKeys, OIDOID);
|
||||
}
|
||||
else
|
||||
conexclopArray = NULL;
|
||||
|
|
|
@ -1193,10 +1193,7 @@ oid_array_to_list(Datum datum)
|
|||
int i;
|
||||
List *result = NIL;
|
||||
|
||||
deconstruct_array(array,
|
||||
OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT,
|
||||
&values, NULL, &nelems);
|
||||
deconstruct_array_builtin(array, OIDOID, &values, NULL, &nelems);
|
||||
for (i = 0; i < nelems; i++)
|
||||
result = lappend_oid(result, values[i]);
|
||||
return result;
|
||||
|
|
|
@ -260,9 +260,7 @@ textarray_to_stringlist(ArrayType *textarray)
|
|||
i;
|
||||
List *res = NIL;
|
||||
|
||||
deconstruct_array(textarray,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&elems, NULL, &nelems);
|
||||
deconstruct_array_builtin(textarray, TEXTOID, &elems, NULL, &nelems);
|
||||
|
||||
if (nelems == 0)
|
||||
return NIL;
|
||||
|
|
|
@ -1688,10 +1688,7 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
|
|||
|
||||
for (n = 0; n < nnum; n++)
|
||||
numdatums[n] = Float4GetDatum(stats->stanumbers[k][n]);
|
||||
/* XXX knows more than it should about type float4: */
|
||||
arry = construct_array(numdatums, nnum,
|
||||
FLOAT4OID,
|
||||
sizeof(float4), true, TYPALIGN_INT);
|
||||
arry = construct_array_builtin(numdatums, nnum, FLOAT4OID);
|
||||
values[i++] = PointerGetDatum(arry); /* stanumbersN */
|
||||
}
|
||||
else
|
||||
|
|
|
@ -351,8 +351,7 @@ filter_list_to_array(List *filterlist)
|
|||
pfree(result);
|
||||
}
|
||||
|
||||
return PointerGetDatum(construct_array(data, l, TEXTOID,
|
||||
-1, false, TYPALIGN_INT));
|
||||
return PointerGetDatum(construct_array_builtin(data, l, TEXTOID));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -2251,9 +2251,7 @@ convert_requires_to_datum(List *requires)
|
|||
datums[ndatums++] =
|
||||
DirectFunctionCall1(namein, CStringGetDatum(curreq));
|
||||
}
|
||||
a = construct_array(datums, ndatums,
|
||||
NAMEOID,
|
||||
NAMEDATALEN, false, TYPALIGN_CHAR);
|
||||
a = construct_array_builtin(datums, ndatums, NAMEOID);
|
||||
return PointerGetDatum(a);
|
||||
}
|
||||
|
||||
|
@ -2433,9 +2431,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
|
|||
arrayLength = 0;
|
||||
arrayIndex = 1;
|
||||
|
||||
a = construct_array(&elementDatum, 1,
|
||||
OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
a = construct_array_builtin(&elementDatum, 1, OIDOID);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2486,9 +2482,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
|
|||
if (arrayLength != 0)
|
||||
elog(ERROR, "extconfig and extcondition arrays do not match");
|
||||
|
||||
a = construct_array(&elementDatum, 1,
|
||||
TEXTOID,
|
||||
-1, false, TYPALIGN_INT);
|
||||
a = construct_array_builtin(&elementDatum, 1, TEXTOID);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2630,14 +2624,12 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
|
|||
int i;
|
||||
|
||||
/* We already checked there are no nulls */
|
||||
deconstruct_array(a, OIDOID, sizeof(Oid), true, TYPALIGN_INT,
|
||||
&dvalues, NULL, &nelems);
|
||||
deconstruct_array_builtin(a, OIDOID, &dvalues, NULL, &nelems);
|
||||
|
||||
for (i = arrayIndex; i < arrayLength - 1; i++)
|
||||
dvalues[i] = dvalues[i + 1];
|
||||
|
||||
a = construct_array(dvalues, arrayLength - 1,
|
||||
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
|
||||
a = construct_array_builtin(dvalues, arrayLength - 1, OIDOID);
|
||||
|
||||
repl_val[Anum_pg_extension_extconfig - 1] = PointerGetDatum(a);
|
||||
}
|
||||
|
@ -2676,14 +2668,12 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
|
|||
int i;
|
||||
|
||||
/* We already checked there are no nulls */
|
||||
deconstruct_array(a, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&dvalues, NULL, &nelems);
|
||||
deconstruct_array_builtin(a, TEXTOID, &dvalues, NULL, &nelems);
|
||||
|
||||
for (i = arrayIndex; i < arrayLength - 1; i++)
|
||||
dvalues[i] = dvalues[i + 1];
|
||||
|
||||
a = construct_array(dvalues, arrayLength - 1,
|
||||
TEXTOID, -1, false, TYPALIGN_INT);
|
||||
a = construct_array_builtin(dvalues, arrayLength - 1, TEXTOID);
|
||||
|
||||
repl_val[Anum_pg_extension_extcondition - 1] = PointerGetDatum(a);
|
||||
}
|
||||
|
|
|
@ -468,10 +468,8 @@ interpret_function_parameter_list(ParseState *pstate,
|
|||
|
||||
if (outCount > 0 || varCount > 0)
|
||||
{
|
||||
*allParameterTypes = construct_array(allTypes, parameterCount, OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
*parameterModes = construct_array(paramModes, parameterCount, CHAROID,
|
||||
1, true, TYPALIGN_CHAR);
|
||||
*allParameterTypes = construct_array_builtin(allTypes, parameterCount, OIDOID);
|
||||
*parameterModes = construct_array_builtin(paramModes, parameterCount, CHAROID);
|
||||
if (outCount > 1)
|
||||
*requiredResultType = RECORDOID;
|
||||
/* otherwise we set requiredResultType correctly above */
|
||||
|
@ -489,8 +487,7 @@ interpret_function_parameter_list(ParseState *pstate,
|
|||
if (paramNames[i] == PointerGetDatum(NULL))
|
||||
paramNames[i] = CStringGetTextDatum("");
|
||||
}
|
||||
*parameterNames = construct_array(paramNames, parameterCount, TEXTOID,
|
||||
-1, false, TYPALIGN_INT);
|
||||
*parameterNames = construct_array_builtin(paramNames, parameterCount, TEXTOID);
|
||||
}
|
||||
else
|
||||
*parameterNames = NULL;
|
||||
|
@ -1222,8 +1219,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
|
|||
i = 0;
|
||||
foreach(lc, trftypes_list)
|
||||
arr[i++] = ObjectIdGetDatum(lfirst_oid(lc));
|
||||
trftypes = construct_array(arr, list_length(trftypes_list),
|
||||
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
|
||||
trftypes = construct_array_builtin(arr, list_length(trftypes_list), OIDOID);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -500,8 +500,7 @@ RemoveRoleFromObjectPolicy(Oid roleid, Oid classid, Oid policy_id)
|
|||
memset(isnull, 0, sizeof(isnull));
|
||||
|
||||
/* This is the array for the new tuple */
|
||||
role_ids = construct_array(role_oids, num_roles, OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
role_ids = construct_array_builtin(role_oids, num_roles, OIDOID);
|
||||
|
||||
replaces[Anum_pg_policy_polroles - 1] = true;
|
||||
values[Anum_pg_policy_polroles - 1] = PointerGetDatum(role_ids);
|
||||
|
@ -617,8 +616,7 @@ CreatePolicy(CreatePolicyStmt *stmt)
|
|||
|
||||
/* Collect role ids */
|
||||
role_oids = policy_role_list_to_array(stmt->roles, &nitems);
|
||||
role_ids = construct_array(role_oids, nitems, OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
role_ids = construct_array_builtin(role_oids, nitems, OIDOID);
|
||||
|
||||
/* Parse the supplied clause */
|
||||
qual_pstate = make_parsestate(NULL);
|
||||
|
@ -801,8 +799,7 @@ AlterPolicy(AlterPolicyStmt *stmt)
|
|||
if (stmt->roles != NULL)
|
||||
{
|
||||
role_oids = policy_role_list_to_array(stmt->roles, &nitems);
|
||||
role_ids = construct_array(role_oids, nitems, OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
role_ids = construct_array_builtin(role_oids, nitems, OIDOID);
|
||||
}
|
||||
|
||||
/* Get id of table. Also handles permissions checks. */
|
||||
|
|
|
@ -722,8 +722,6 @@ build_regtype_array(Oid *param_types, int num_params)
|
|||
for (i = 0; i < num_params; i++)
|
||||
tmp_ary[i] = ObjectIdGetDatum(param_types[i]);
|
||||
|
||||
/* XXX: this hardcodes assumptions about the regtype type */
|
||||
result = construct_array(tmp_ary, num_params, REGTYPEOID,
|
||||
4, true, TYPALIGN_INT);
|
||||
result = construct_array_builtin(tmp_ary, num_params, REGTYPEOID);
|
||||
return PointerGetDatum(result);
|
||||
}
|
||||
|
|
|
@ -467,7 +467,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
|||
if (build_expressions)
|
||||
types[ntypes++] = CharGetDatum(STATS_EXT_EXPRESSIONS);
|
||||
Assert(ntypes > 0 && ntypes <= lengthof(types));
|
||||
stxkind = construct_array(types, ntypes, CHAROID, 1, true, TYPALIGN_CHAR);
|
||||
stxkind = construct_array_builtin(types, ntypes, CHAROID);
|
||||
|
||||
/* convert the expressions (if any) to a text datum */
|
||||
if (stxexprs != NIL)
|
||||
|
|
|
@ -494,8 +494,7 @@ publicationListToArray(List *publist)
|
|||
|
||||
MemoryContextSwitchTo(oldcxt);
|
||||
|
||||
arr = construct_array(datums, list_length(publist),
|
||||
TEXTOID, -1, false, TYPALIGN_INT);
|
||||
arr = construct_array_builtin(datums, list_length(publist), TEXTOID);
|
||||
|
||||
MemoryContextDelete(memcxt);
|
||||
|
||||
|
|
|
@ -1893,12 +1893,9 @@ makeMultirangeConstructors(const char *name, Oid namespace,
|
|||
/* n-arg constructor - vararg */
|
||||
argtypes = buildoidvector(&rangeArrayOid, 1);
|
||||
allParamTypes = ObjectIdGetDatum(rangeArrayOid);
|
||||
allParameterTypes = construct_array(&allParamTypes,
|
||||
1, OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
allParameterTypes = construct_array_builtin(&allParamTypes, 1, OIDOID);
|
||||
paramModes = CharGetDatum(FUNC_PARAM_VARIADIC);
|
||||
parameterModes = construct_array(¶mModes, 1, CHAROID,
|
||||
1, true, TYPALIGN_CHAR);
|
||||
parameterModes = construct_array_builtin(¶mModes, 1, CHAROID);
|
||||
myself = ProcedureCreate(name, /* name: same as multirange type */
|
||||
namespace,
|
||||
false, /* replace */
|
||||
|
|
|
@ -206,9 +206,7 @@ TidListEval(TidScanState *tidstate)
|
|||
if (isNull)
|
||||
continue;
|
||||
itemarray = DatumGetArrayTypeP(arraydatum);
|
||||
deconstruct_array(itemarray,
|
||||
TIDOID, sizeof(ItemPointerData), false, TYPALIGN_SHORT,
|
||||
&ipdatums, &ipnulls, &ndatums);
|
||||
deconstruct_array_builtin(itemarray, TIDOID, &ipdatums, &ipnulls, &ndatums);
|
||||
if (numTids + ndatums > numAllocTids)
|
||||
{
|
||||
numAllocTids = numTids + ndatums;
|
||||
|
|
|
@ -411,9 +411,7 @@ typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
|
|||
datums[n++] = CStringGetDatum(cstr);
|
||||
}
|
||||
|
||||
/* hardwired knowledge about cstring's representation details here */
|
||||
arrtypmod = construct_array(datums, n, CSTRINGOID,
|
||||
-2, false, TYPALIGN_CHAR);
|
||||
arrtypmod = construct_array_builtin(datums, n, CSTRINGOID);
|
||||
|
||||
/* arrange to report location if type's typmodin function fails */
|
||||
setup_parser_errposition_callback(&pcbstate, pstate, typeName->location);
|
||||
|
|
|
@ -1642,9 +1642,7 @@ generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx,
|
|||
elog(ERROR, "null conexclop for constraint %u",
|
||||
constraintId);
|
||||
|
||||
deconstruct_array(DatumGetArrayTypeP(datum),
|
||||
OIDOID, sizeof(Oid), true, TYPALIGN_INT,
|
||||
&elems, NULL, &nElems);
|
||||
deconstruct_array_builtin(DatumGetArrayTypeP(datum), OIDOID, &elems, NULL, &nElems);
|
||||
|
||||
for (i = 0; i < nElems; i++)
|
||||
{
|
||||
|
|
|
@ -172,8 +172,7 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
|
|||
|
||||
Assert(ARR_ELEMTYPE(arr) == TEXTOID);
|
||||
|
||||
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&datum_opts, NULL, &nelems);
|
||||
deconstruct_array_builtin(arr, TEXTOID, &datum_opts, NULL, &nelems);
|
||||
|
||||
if (nelems % 2 != 0)
|
||||
ereport(ERROR,
|
||||
|
|
|
@ -2345,10 +2345,7 @@ serialize_expr_stats(AnlExprData *exprdata, int nexprs)
|
|||
|
||||
for (n = 0; n < nnum; n++)
|
||||
numdatums[n] = Float4GetDatum(stats->stanumbers[k][n]);
|
||||
/* XXX knows more than it should about type float4: */
|
||||
arry = construct_array(numdatums, nnum,
|
||||
FLOAT4OID,
|
||||
sizeof(float4), true, TYPALIGN_INT);
|
||||
arry = construct_array_builtin(numdatums, nnum, FLOAT4OID);
|
||||
values[i++] = PointerGetDatum(arry); /* stanumbersN */
|
||||
}
|
||||
else
|
||||
|
|
|
@ -68,12 +68,7 @@ ts_lexize(PG_FUNCTION_ARGS)
|
|||
ptr++;
|
||||
}
|
||||
|
||||
a = construct_array(da,
|
||||
ptr - res,
|
||||
TEXTOID,
|
||||
-1,
|
||||
false,
|
||||
TYPALIGN_INT);
|
||||
a = construct_array_builtin(da, ptr - res, TEXTOID);
|
||||
|
||||
ptr = res;
|
||||
while (ptr->lexeme)
|
||||
|
|
|
@ -3330,6 +3330,92 @@ construct_array(Datum *elems, int nelems,
|
|||
elmtype, elmlen, elmbyval, elmalign);
|
||||
}
|
||||
|
||||
/*
|
||||
* Like construct_array(), where elmtype must be a built-in type, and
|
||||
* elmlen/elmbyval/elmalign is looked up from hardcoded data. This is often
|
||||
* useful when manipulating arrays from/for system catalogs.
|
||||
*/
|
||||
ArrayType *
|
||||
construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
|
||||
{
|
||||
int elmlen;
|
||||
bool elmbyval;
|
||||
char elmalign;
|
||||
|
||||
switch (elmtype)
|
||||
{
|
||||
case CHAROID:
|
||||
elmlen = 1;
|
||||
elmbyval = true;
|
||||
elmalign = TYPALIGN_CHAR;
|
||||
break;
|
||||
|
||||
case CSTRINGOID:
|
||||
elmlen = -2;
|
||||
elmbyval = false;
|
||||
elmalign = TYPALIGN_CHAR;
|
||||
break;
|
||||
|
||||
case FLOAT4OID:
|
||||
elmlen = sizeof(float4);
|
||||
elmbyval = true;
|
||||
elmalign = TYPALIGN_INT;
|
||||
break;
|
||||
|
||||
case INT2OID:
|
||||
elmlen = sizeof(int16);
|
||||
elmbyval = true;
|
||||
elmalign = TYPALIGN_SHORT;
|
||||
break;
|
||||
|
||||
case INT4OID:
|
||||
elmlen = sizeof(int32);
|
||||
elmbyval = true;
|
||||
elmalign = TYPALIGN_INT;
|
||||
break;
|
||||
|
||||
case INT8OID:
|
||||
elmlen = sizeof(int64);
|
||||
elmbyval = FLOAT8PASSBYVAL;
|
||||
elmalign = TYPALIGN_DOUBLE;
|
||||
break;
|
||||
|
||||
case NAMEOID:
|
||||
elmlen = NAMEDATALEN;
|
||||
elmbyval = false;
|
||||
elmalign = TYPALIGN_CHAR;
|
||||
break;
|
||||
|
||||
case OIDOID:
|
||||
case REGTYPEOID:
|
||||
elmlen = sizeof(Oid);
|
||||
elmbyval = true;
|
||||
elmalign = TYPALIGN_INT;
|
||||
break;
|
||||
|
||||
case TEXTOID:
|
||||
elmlen = -1;
|
||||
elmbyval = false;
|
||||
elmalign = TYPALIGN_INT;
|
||||
break;
|
||||
|
||||
case TIDOID:
|
||||
elmlen = sizeof(ItemPointerData);
|
||||
elmbyval = false;
|
||||
elmalign = TYPALIGN_SHORT;
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "type %u not supported by construct_array_builtin()", elmtype);
|
||||
/* keep compiler quiet */
|
||||
elmlen = 0;
|
||||
elmbyval = false;
|
||||
elmalign = 0;
|
||||
}
|
||||
|
||||
return construct_array(elems, nelems, elmtype, elmlen, elmbyval, elmalign);
|
||||
}
|
||||
|
||||
/*
|
||||
* construct_md_array --- simple method for constructing an array object
|
||||
* with arbitrary dimensions and possible NULLs
|
||||
|
@ -3483,9 +3569,9 @@ construct_empty_expanded_array(Oid element_type,
|
|||
* be pointers into the array object.
|
||||
*
|
||||
* NOTE: it would be cleaner to look up the elmlen/elmbval/elmalign info
|
||||
* from the system catalogs, given the elmtype. However, in most current
|
||||
* uses the type is hard-wired into the caller and so we can save a lookup
|
||||
* cycle by hard-wiring the type info as well.
|
||||
* from the system catalogs, given the elmtype. However, the caller is
|
||||
* in a better position to cache this info across multiple uses, or even
|
||||
* to hard-wire values if the element type is hard-wired.
|
||||
*/
|
||||
void
|
||||
deconstruct_array(ArrayType *array,
|
||||
|
@ -3548,6 +3634,75 @@ deconstruct_array(ArrayType *array,
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Like deconstruct_array(), where elmtype must be a built-in type, and
|
||||
* elmlen/elmbyval/elmalign is looked up from hardcoded data. This is often
|
||||
* useful when manipulating arrays from/for system catalogs.
|
||||
*/
|
||||
void
|
||||
deconstruct_array_builtin(ArrayType *array,
|
||||
Oid elmtype,
|
||||
Datum **elemsp, bool **nullsp, int *nelemsp)
|
||||
{
|
||||
int elmlen;
|
||||
bool elmbyval;
|
||||
char elmalign;
|
||||
|
||||
switch (elmtype)
|
||||
{
|
||||
case CHAROID:
|
||||
elmlen = 1;
|
||||
elmbyval = true;
|
||||
elmalign = TYPALIGN_CHAR;
|
||||
break;
|
||||
|
||||
case CSTRINGOID:
|
||||
elmlen = -2;
|
||||
elmbyval = false;
|
||||
elmalign = TYPALIGN_CHAR;
|
||||
break;
|
||||
|
||||
case FLOAT8OID:
|
||||
elmlen = sizeof(float8);
|
||||
elmbyval = FLOAT8PASSBYVAL;
|
||||
elmalign = TYPALIGN_DOUBLE;
|
||||
break;
|
||||
|
||||
case INT2OID:
|
||||
elmlen = sizeof(int16);
|
||||
elmbyval = true;
|
||||
elmalign = TYPALIGN_SHORT;
|
||||
break;
|
||||
|
||||
case OIDOID:
|
||||
elmlen = sizeof(Oid);
|
||||
elmbyval = true;
|
||||
elmalign = TYPALIGN_INT;
|
||||
break;
|
||||
|
||||
case TEXTOID:
|
||||
elmlen = -1;
|
||||
elmbyval = false;
|
||||
elmalign = TYPALIGN_INT;
|
||||
break;
|
||||
|
||||
case TIDOID:
|
||||
elmlen = sizeof(ItemPointerData);
|
||||
elmbyval = false;
|
||||
elmalign = TYPALIGN_SHORT;
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "type %u not supported by deconstruct_array_builtin()", elmtype);
|
||||
/* keep compiler quiet */
|
||||
elmlen = 0;
|
||||
elmbyval = false;
|
||||
elmalign = 0;
|
||||
}
|
||||
|
||||
deconstruct_array(array, elmtype, elmlen, elmbyval, elmalign, elemsp, nullsp, nelemsp);
|
||||
}
|
||||
|
||||
/*
|
||||
* array_contains_nulls --- detect whether an array has any null elements
|
||||
*
|
||||
|
|
|
@ -249,10 +249,7 @@ ArrayGetIntegerTypmods(ArrayType *arr, int *n)
|
|||
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
|
||||
errmsg("typmod array must not contain nulls")));
|
||||
|
||||
/* hardwired knowledge about cstring's representation details here */
|
||||
deconstruct_array(arr, CSTRINGOID,
|
||||
-2, false, TYPALIGN_CHAR,
|
||||
&elem_values, NULL, n);
|
||||
deconstruct_array_builtin(arr, CSTRINGOID, &elem_values, NULL, n);
|
||||
|
||||
result = (int32 *) palloc(*n * sizeof(int32));
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ get_hba_options(HbaLine *hba)
|
|||
Assert(noptions <= MAX_HBA_OPTIONS);
|
||||
|
||||
if (noptions > 0)
|
||||
return construct_array(options, noptions, TEXTOID, -1, false, TYPALIGN_INT);
|
||||
return construct_array_builtin(options, noptions, TEXTOID);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -1450,9 +1450,7 @@ json_object(PG_FUNCTION_ARGS)
|
|||
errmsg("wrong number of array subscripts")));
|
||||
}
|
||||
|
||||
deconstruct_array(in_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&in_datums, &in_nulls, &in_count);
|
||||
deconstruct_array_builtin(in_array, TEXTOID, &in_datums, &in_nulls, &in_count);
|
||||
|
||||
count = in_count / 2;
|
||||
|
||||
|
@ -1526,13 +1524,8 @@ json_object_two_arg(PG_FUNCTION_ARGS)
|
|||
if (nkdims == 0)
|
||||
PG_RETURN_DATUM(CStringGetTextDatum("{}"));
|
||||
|
||||
deconstruct_array(key_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &key_count);
|
||||
|
||||
deconstruct_array(val_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&val_datums, &val_nulls, &val_count);
|
||||
deconstruct_array_builtin(key_array, TEXTOID, &key_datums, &key_nulls, &key_count);
|
||||
deconstruct_array_builtin(val_array, TEXTOID, &val_datums, &val_nulls, &val_count);
|
||||
|
||||
if (key_count != val_count)
|
||||
ereport(ERROR,
|
||||
|
|
|
@ -1378,9 +1378,7 @@ jsonb_object(PG_FUNCTION_ARGS)
|
|||
errmsg("wrong number of array subscripts")));
|
||||
}
|
||||
|
||||
deconstruct_array(in_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&in_datums, &in_nulls, &in_count);
|
||||
deconstruct_array_builtin(in_array, TEXTOID, &in_datums, &in_nulls, &in_count);
|
||||
|
||||
count = in_count / 2;
|
||||
|
||||
|
@ -1466,13 +1464,8 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
|
|||
if (nkdims == 0)
|
||||
goto close_object;
|
||||
|
||||
deconstruct_array(key_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &key_count);
|
||||
|
||||
deconstruct_array(val_array,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&val_datums, &val_nulls, &val_count);
|
||||
deconstruct_array_builtin(key_array, TEXTOID, &key_datums, &key_nulls, &key_count);
|
||||
deconstruct_array_builtin(val_array, TEXTOID, &val_datums, &val_nulls, &val_count);
|
||||
|
||||
if (key_count != val_count)
|
||||
ereport(ERROR,
|
||||
|
|
|
@ -885,9 +885,7 @@ gin_extract_jsonb_query(PG_FUNCTION_ARGS)
|
|||
int i,
|
||||
j;
|
||||
|
||||
deconstruct_array(query,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &key_count);
|
||||
deconstruct_array_builtin(query, TEXTOID, &key_datums, &key_nulls, &key_count);
|
||||
|
||||
entries = (Datum *) palloc(sizeof(Datum) * key_count);
|
||||
|
||||
|
|
|
@ -53,8 +53,7 @@ jsonb_exists_any(PG_FUNCTION_ARGS)
|
|||
bool *key_nulls;
|
||||
int elem_count;
|
||||
|
||||
deconstruct_array(keys, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &elem_count);
|
||||
deconstruct_array_builtin(keys, TEXTOID, &key_datums, &key_nulls, &elem_count);
|
||||
|
||||
for (i = 0; i < elem_count; i++)
|
||||
{
|
||||
|
@ -86,8 +85,7 @@ jsonb_exists_all(PG_FUNCTION_ARGS)
|
|||
bool *key_nulls;
|
||||
int elem_count;
|
||||
|
||||
deconstruct_array(keys, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&key_datums, &key_nulls, &elem_count);
|
||||
deconstruct_array_builtin(keys, TEXTOID, &key_datums, &key_nulls, &elem_count);
|
||||
|
||||
for (i = 0; i < elem_count; i++)
|
||||
{
|
||||
|
|
|
@ -1000,8 +1000,7 @@ get_path_all(FunctionCallInfo fcinfo, bool as_text)
|
|||
if (array_contains_nulls(path))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&pathtext, &pathnulls, &npath);
|
||||
deconstruct_array_builtin(path, TEXTOID, &pathtext, &pathnulls, &npath);
|
||||
|
||||
tpath = palloc(npath * sizeof(char *));
|
||||
ipath = palloc(npath * sizeof(int));
|
||||
|
@ -1456,8 +1455,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
|
|||
if (array_contains_nulls(path))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&pathtext, &pathnulls, &npath);
|
||||
deconstruct_array_builtin(path, TEXTOID, &pathtext, &pathnulls, &npath);
|
||||
|
||||
res = jsonb_get_element(jb, pathtext, npath, &isnull, as_text);
|
||||
|
||||
|
@ -4370,8 +4368,7 @@ jsonb_delete_array(PG_FUNCTION_ARGS)
|
|||
if (JB_ROOT_COUNT(in) == 0)
|
||||
PG_RETURN_JSONB_P(in);
|
||||
|
||||
deconstruct_array(keys, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&keys_elems, &keys_nulls, &keys_len);
|
||||
deconstruct_array_builtin(keys, TEXTOID, &keys_elems, &keys_nulls, &keys_len);
|
||||
|
||||
if (keys_len == 0)
|
||||
PG_RETURN_JSONB_P(in);
|
||||
|
@ -4523,8 +4520,7 @@ jsonb_set(PG_FUNCTION_ARGS)
|
|||
if (JB_ROOT_COUNT(in) == 0 && !create)
|
||||
PG_RETURN_JSONB_P(in);
|
||||
|
||||
deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&path_elems, &path_nulls, &path_len);
|
||||
deconstruct_array_builtin(path, TEXTOID, &path_elems, &path_nulls, &path_len);
|
||||
|
||||
if (path_len == 0)
|
||||
PG_RETURN_JSONB_P(in);
|
||||
|
@ -4635,8 +4631,7 @@ jsonb_delete_path(PG_FUNCTION_ARGS)
|
|||
if (JB_ROOT_COUNT(in) == 0)
|
||||
PG_RETURN_JSONB_P(in);
|
||||
|
||||
deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&path_elems, &path_nulls, &path_len);
|
||||
deconstruct_array_builtin(path, TEXTOID, &path_elems, &path_nulls, &path_len);
|
||||
|
||||
if (path_len == 0)
|
||||
PG_RETURN_JSONB_P(in);
|
||||
|
@ -4681,8 +4676,7 @@ jsonb_insert(PG_FUNCTION_ARGS)
|
|||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("cannot set path in scalar")));
|
||||
|
||||
deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&path_elems, &path_nulls, &path_len);
|
||||
deconstruct_array_builtin(path, TEXTOID, &path_elems, &path_nulls, &path_len);
|
||||
|
||||
if (path_len == 0)
|
||||
PG_RETURN_JSONB_P(in);
|
||||
|
|
|
@ -538,10 +538,7 @@ pg_blocking_pids(PG_FUNCTION_ARGS)
|
|||
/* Assert we didn't overrun arrayelems[] */
|
||||
Assert(narrayelems <= lockData->nlocks);
|
||||
|
||||
/* Construct array, using hardwired knowledge about int4 type */
|
||||
PG_RETURN_ARRAYTYPE_P(construct_array(arrayelems, narrayelems,
|
||||
INT4OID,
|
||||
sizeof(int32), true, TYPALIGN_INT));
|
||||
PG_RETURN_ARRAYTYPE_P(construct_array_builtin(arrayelems, narrayelems, INT4OID));
|
||||
}
|
||||
|
||||
|
||||
|
@ -579,10 +576,7 @@ pg_safe_snapshot_blocking_pids(PG_FUNCTION_ARGS)
|
|||
else
|
||||
blocker_datums = NULL;
|
||||
|
||||
/* Construct array, using hardwired knowledge about int4 type */
|
||||
PG_RETURN_ARRAYTYPE_P(construct_array(blocker_datums, num_blockers,
|
||||
INT4OID,
|
||||
sizeof(int32), true, TYPALIGN_INT));
|
||||
PG_RETURN_ARRAYTYPE_P(construct_array_builtin(blocker_datums, num_blockers, INT4OID));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -314,11 +314,7 @@ current_schemas(PG_FUNCTION_ARGS)
|
|||
}
|
||||
list_free(search_path);
|
||||
|
||||
array = construct_array(names, i,
|
||||
NAMEOID,
|
||||
NAMEDATALEN, /* sizeof(Name) */
|
||||
false, /* Name is not by-val */
|
||||
TYPALIGN_CHAR); /* alignment of Name */
|
||||
array = construct_array_builtin(names, i, NAMEOID);
|
||||
|
||||
PG_RETURN_POINTER(array);
|
||||
}
|
||||
|
|
|
@ -759,9 +759,7 @@ percentile_disc_multi_final(PG_FUNCTION_ARGS)
|
|||
PG_RETURN_NULL();
|
||||
param = PG_GETARG_ARRAYTYPE_P(1);
|
||||
|
||||
deconstruct_array(param, FLOAT8OID,
|
||||
/* hard-wired info on type float8 */
|
||||
sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE,
|
||||
deconstruct_array_builtin(param, FLOAT8OID,
|
||||
&percentiles_datum,
|
||||
&percentiles_null,
|
||||
&num_percentiles);
|
||||
|
@ -883,9 +881,7 @@ percentile_cont_multi_final_common(FunctionCallInfo fcinfo,
|
|||
PG_RETURN_NULL();
|
||||
param = PG_GETARG_ARRAYTYPE_P(1);
|
||||
|
||||
deconstruct_array(param, FLOAT8OID,
|
||||
/* hard-wired info on type float8 */
|
||||
sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE,
|
||||
deconstruct_array_builtin(param, FLOAT8OID,
|
||||
&percentiles_datum,
|
||||
&percentiles_null,
|
||||
&num_percentiles);
|
||||
|
|
|
@ -214,9 +214,7 @@ binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
|
|||
int ndatums;
|
||||
int i;
|
||||
|
||||
deconstruct_array(textArray,
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&textDatums, NULL, &ndatums);
|
||||
deconstruct_array_builtin(textArray, TEXTOID, &textDatums, NULL, &ndatums);
|
||||
for (i = 0; i < ndatums; i++)
|
||||
{
|
||||
char *extName = TextDatumGetCString(textDatums[i]);
|
||||
|
|
|
@ -2406,8 +2406,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
|
|||
if (isnull)
|
||||
elog(ERROR, "null indkey for index %u", indexId);
|
||||
|
||||
deconstruct_array(DatumGetArrayTypeP(cols),
|
||||
INT2OID, 2, true, TYPALIGN_SHORT,
|
||||
deconstruct_array_builtin(DatumGetArrayTypeP(cols), INT2OID,
|
||||
&keys, NULL, &nKeys);
|
||||
|
||||
for (j = keyatts; j < nKeys; j++)
|
||||
|
@ -2531,8 +2530,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
|
|||
elog(ERROR, "null conexclop for constraint %u",
|
||||
constraintId);
|
||||
|
||||
deconstruct_array(DatumGetArrayTypeP(val),
|
||||
OIDOID, sizeof(Oid), true, TYPALIGN_INT,
|
||||
deconstruct_array_builtin(DatumGetArrayTypeP(val), OIDOID,
|
||||
&elems, NULL, &nElems);
|
||||
|
||||
operators = (Oid *) palloc(nElems * sizeof(Oid));
|
||||
|
@ -2587,8 +2585,7 @@ decompile_column_index_array(Datum column_index_array, Oid relId,
|
|||
int j;
|
||||
|
||||
/* Extract data from array of int16 */
|
||||
deconstruct_array(DatumGetArrayTypeP(column_index_array),
|
||||
INT2OID, 2, true, TYPALIGN_SHORT,
|
||||
deconstruct_array_builtin(DatumGetArrayTypeP(column_index_array), INT2OID,
|
||||
&keys, NULL, &nKeys);
|
||||
|
||||
for (j = 0; j < nKeys; j++)
|
||||
|
@ -12752,8 +12749,7 @@ get_reloptions(StringInfo buf, Datum reloptions)
|
|||
int noptions;
|
||||
int i;
|
||||
|
||||
deconstruct_array(DatumGetArrayTypeP(reloptions),
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
deconstruct_array_builtin(DatumGetArrayTypeP(reloptions), TEXTOID,
|
||||
&options, NULL, &noptions);
|
||||
|
||||
for (i = 0; i < noptions; i++)
|
||||
|
|
|
@ -308,8 +308,7 @@ tsvector_setweight_by_filter(PG_FUNCTION_ARGS)
|
|||
memcpy(tsout, tsin, VARSIZE(tsin));
|
||||
entry = ARRPTR(tsout);
|
||||
|
||||
deconstruct_array(lexemes, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&dlexemes, &nulls, &nlexemes);
|
||||
deconstruct_array_builtin(lexemes, TEXTOID, &dlexemes, &nulls, &nlexemes);
|
||||
|
||||
/*
|
||||
* Assuming that lexemes array is significantly shorter than tsvector we
|
||||
|
@ -586,8 +585,7 @@ tsvector_delete_arr(PG_FUNCTION_ARGS)
|
|||
Datum *dlexemes;
|
||||
bool *nulls;
|
||||
|
||||
deconstruct_array(lexemes, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&dlexemes, &nulls, &nlex);
|
||||
deconstruct_array_builtin(lexemes, TEXTOID, &dlexemes, &nulls, &nlex);
|
||||
|
||||
/*
|
||||
* In typical use case array of lexemes to delete is relatively small. So
|
||||
|
@ -694,10 +692,8 @@ tsvector_unnest(PG_FUNCTION_ARGS)
|
|||
1));
|
||||
}
|
||||
|
||||
values[1] = PointerGetDatum(construct_array(positions, posv->npos,
|
||||
INT2OID, 2, true, TYPALIGN_SHORT));
|
||||
values[2] = PointerGetDatum(construct_array(weights, posv->npos,
|
||||
TEXTOID, -1, false, TYPALIGN_INT));
|
||||
values[1] = PointerGetDatum(construct_array_builtin(positions, posv->npos, INT2OID));
|
||||
values[2] = PointerGetDatum(construct_array_builtin(weights, posv->npos, TEXTOID));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -733,7 +729,7 @@ tsvector_to_array(PG_FUNCTION_ARGS)
|
|||
arrin[i].len));
|
||||
}
|
||||
|
||||
array = construct_array(elements, tsin->size, TEXTOID, -1, false, TYPALIGN_INT);
|
||||
array = construct_array_builtin(elements, tsin->size, TEXTOID);
|
||||
|
||||
pfree(elements);
|
||||
PG_FREE_IF_COPY(tsin, 0);
|
||||
|
@ -757,7 +753,7 @@ array_to_tsvector(PG_FUNCTION_ARGS)
|
|||
datalen = 0;
|
||||
char *cur;
|
||||
|
||||
deconstruct_array(v, TEXTOID, -1, false, TYPALIGN_INT, &dlexemes, &nulls, &nitems);
|
||||
deconstruct_array_builtin(v, TEXTOID, &dlexemes, &nulls, &nitems);
|
||||
|
||||
/*
|
||||
* Reject nulls and zero length strings (maybe we should just ignore them,
|
||||
|
@ -833,8 +829,7 @@ tsvector_filter(PG_FUNCTION_ARGS)
|
|||
int cur_pos = 0;
|
||||
char mask = 0;
|
||||
|
||||
deconstruct_array(weights, CHAROID, 1, true, TYPALIGN_CHAR,
|
||||
&dweights, &nulls, &nweights);
|
||||
deconstruct_array_builtin(weights, CHAROID, &dweights, &nulls, &nweights);
|
||||
|
||||
for (i = 0; i < nweights; i++)
|
||||
{
|
||||
|
|
|
@ -4017,7 +4017,7 @@ xpath_internal(text *xpath_expr_text, xmltype *data, ArrayType *namespaces,
|
|||
|
||||
Assert(ARR_ELEMTYPE(namespaces) == TEXTOID);
|
||||
|
||||
deconstruct_array(namespaces, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
deconstruct_array_builtin(namespaces, TEXTOID,
|
||||
&ns_names_uris, &ns_names_uris_nulls,
|
||||
&ns_count);
|
||||
|
||||
|
|
|
@ -228,8 +228,7 @@ DecodeTextArrayToBitmapset(Datum array)
|
|||
|
||||
if (ARR_NDIM(arr) != 1 || ARR_HASNULL(arr) || ARR_ELEMTYPE(arr) != TEXTOID)
|
||||
elog(ERROR, "expected 1-D text array");
|
||||
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&elems, NULL, &nelems);
|
||||
deconstruct_array_builtin(arr, TEXTOID, &elems, NULL, &nelems);
|
||||
|
||||
for (bms = NULL, i = 0; i < nelems; ++i)
|
||||
{
|
||||
|
|
|
@ -1390,8 +1390,7 @@ get_func_arg_info(HeapTuple procTup,
|
|||
*p_argnames = NULL;
|
||||
else
|
||||
{
|
||||
deconstruct_array(DatumGetArrayTypeP(proargnames),
|
||||
TEXTOID, -1, false, TYPALIGN_INT,
|
||||
deconstruct_array_builtin(DatumGetArrayTypeP(proargnames), TEXTOID,
|
||||
&elems, NULL, &nelems);
|
||||
if (nelems != numargs) /* should not happen */
|
||||
elog(ERROR, "proargnames must have the same number of elements as the function has arguments");
|
||||
|
@ -1506,8 +1505,7 @@ get_func_input_arg_names(Datum proargnames, Datum proargmodes,
|
|||
ARR_HASNULL(arr) ||
|
||||
ARR_ELEMTYPE(arr) != TEXTOID)
|
||||
elog(ERROR, "proargnames is not a 1-D text array or it contains nulls");
|
||||
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&argnames, NULL, &numargs);
|
||||
deconstruct_array_builtin(arr, TEXTOID, &argnames, NULL, &numargs);
|
||||
if (proargmodes != PointerGetDatum(NULL))
|
||||
{
|
||||
arr = DatumGetArrayTypeP(proargmodes); /* ensure not toasted */
|
||||
|
@ -1621,8 +1619,7 @@ get_func_result_name(Oid functionId)
|
|||
ARR_ELEMTYPE(arr) != TEXTOID)
|
||||
elog(ERROR, "proargnames is not a 1-D text array of length %d or it contains nulls",
|
||||
numargs);
|
||||
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&argnames, NULL, &nargnames);
|
||||
deconstruct_array_builtin(arr, TEXTOID, &argnames, NULL, &nargnames);
|
||||
Assert(nargnames == numargs);
|
||||
|
||||
/* scan for output argument(s) */
|
||||
|
@ -1770,8 +1767,7 @@ build_function_result_tupdesc_d(char prokind,
|
|||
ARR_ELEMTYPE(arr) != TEXTOID)
|
||||
elog(ERROR, "proargnames is not a 1-D text array of length %d or it contains nulls",
|
||||
numargs);
|
||||
deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&argnames, NULL, &nargnames);
|
||||
deconstruct_array_builtin(arr, TEXTOID, &argnames, NULL, &nargnames);
|
||||
Assert(nargnames == numargs);
|
||||
}
|
||||
|
||||
|
|
|
@ -9974,7 +9974,7 @@ pg_settings_get_flags(PG_FUNCTION_ARGS)
|
|||
Assert(cnt <= MAX_GUC_FLAGS);
|
||||
|
||||
/* Returns the record as Datum */
|
||||
a = construct_array(flags, cnt, TEXTOID, -1, false, TYPALIGN_INT);
|
||||
a = construct_array_builtin(flags, cnt, TEXTOID);
|
||||
PG_RETURN_ARRAYTYPE_P(a);
|
||||
}
|
||||
|
||||
|
@ -11507,9 +11507,7 @@ GUCArrayAdd(ArrayType *array, const char *name, const char *value)
|
|||
TYPALIGN_INT /* TEXT's typalign */ );
|
||||
}
|
||||
else
|
||||
a = construct_array(&datum, 1,
|
||||
TEXTOID,
|
||||
-1, false, TYPALIGN_INT);
|
||||
a = construct_array_builtin(&datum, 1, TEXTOID);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
@ -11576,9 +11574,7 @@ GUCArrayDelete(ArrayType *array, const char *name)
|
|||
false /* TEXT's typbyval */ ,
|
||||
TYPALIGN_INT /* TEXT's typalign */ );
|
||||
else
|
||||
newarray = construct_array(&d, 1,
|
||||
TEXTOID,
|
||||
-1, false, TYPALIGN_INT);
|
||||
newarray = construct_array_builtin(&d, 1, TEXTOID);
|
||||
|
||||
index++;
|
||||
}
|
||||
|
@ -11644,9 +11640,7 @@ GUCArrayReset(ArrayType *array)
|
|||
false /* TEXT's typbyval */ ,
|
||||
TYPALIGN_INT /* TEXT's typalign */ );
|
||||
else
|
||||
newarray = construct_array(&d, 1,
|
||||
TEXTOID,
|
||||
-1, false, TYPALIGN_INT);
|
||||
newarray = construct_array_builtin(&d, 1, TEXTOID);
|
||||
|
||||
index++;
|
||||
pfree(val);
|
||||
|
|
|
@ -387,6 +387,7 @@ extern void array_bitmap_copy(bits8 *destbitmap, int destoffset,
|
|||
extern ArrayType *construct_array(Datum *elems, int nelems,
|
||||
Oid elmtype,
|
||||
int elmlen, bool elmbyval, char elmalign);
|
||||
extern ArrayType *construct_array_builtin(Datum *elems, int nelems, Oid elmtype);
|
||||
extern ArrayType *construct_md_array(Datum *elems,
|
||||
bool *nulls,
|
||||
int ndims,
|
||||
|
@ -401,6 +402,9 @@ extern void deconstruct_array(ArrayType *array,
|
|||
Oid elmtype,
|
||||
int elmlen, bool elmbyval, char elmalign,
|
||||
Datum **elemsp, bool **nullsp, int *nelemsp);
|
||||
extern void deconstruct_array_builtin(ArrayType *array,
|
||||
Oid elmtype,
|
||||
Datum **elemsp, bool **nullsp, int *nelemsp);
|
||||
extern bool array_contains_nulls(ArrayType *array);
|
||||
|
||||
extern ArrayBuildState *initArrayResult(Oid element_type,
|
||||
|
|
|
@ -70,7 +70,7 @@ test_rls_hooks_permissive(CmdType cmdtype, Relation relation)
|
|||
|
||||
policy->policy_name = pstrdup("extension policy");
|
||||
policy->polcmd = '*';
|
||||
policy->roles = construct_array(&role, 1, OIDOID, sizeof(Oid), true, TYPALIGN_INT);
|
||||
policy->roles = construct_array_builtin(&role, 1, OIDOID);
|
||||
|
||||
/*
|
||||
* policy->qual = (Expr *) makeConst(BOOLOID, -1, InvalidOid,
|
||||
|
@ -138,7 +138,7 @@ test_rls_hooks_restrictive(CmdType cmdtype, Relation relation)
|
|||
|
||||
policy->policy_name = pstrdup("extension policy");
|
||||
policy->polcmd = '*';
|
||||
policy->roles = construct_array(&role, 1, OIDOID, sizeof(Oid), true, TYPALIGN_INT);
|
||||
policy->roles = construct_array_builtin(&role, 1, OIDOID);
|
||||
|
||||
n = makeFuncCall(list_make2(makeString("pg_catalog"),
|
||||
makeString("current_user")),
|
||||
|
|
Loading…
Reference in New Issue