Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging community commit - d746021de18baf0f29eff0388204a0664f41eb8b Add construct_array_builtin, deconstruct_array_builtin #53

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions contrib/hstore/hstore_gin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 2 additions & 6 deletions contrib/hstore/hstore_gist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;

Expand Down
12 changes: 3 additions & 9 deletions contrib/hstore/hstore_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down
11 changes: 3 additions & 8 deletions contrib/hstore/hstore_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 1 addition & 5 deletions contrib/pageinspect/btreefuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions contrib/pageinspect/ginfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions contrib/pageinspect/gistfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 2 additions & 12 deletions contrib/pageinspect/hashfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions contrib/pageinspect/heapfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*
Expand All @@ -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);

Expand Down
7 changes: 1 addition & 6 deletions contrib/pg_trgm/trgm_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down
9 changes: 2 additions & 7 deletions contrib/pgcrypto/pgp-pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions src/backend/access/common/reloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,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++)
{
Expand Down Expand Up @@ -1346,8 +1345,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++)
{
Expand Down Expand Up @@ -1437,8 +1435,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++)
{
Expand Down
12 changes: 4 additions & 8 deletions src/backend/catalog/objectaddress.c
Original file line number Diff line number Diff line change
Expand Up @@ -2111,8 +2111,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++)
{
Expand Down Expand Up @@ -2168,8 +2167,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),
Expand All @@ -2186,8 +2184,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),
Expand Down Expand Up @@ -2225,8 +2222,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++)
Expand Down
21 changes: 7 additions & 14 deletions src/backend/catalog/pg_constraint.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/backend/catalog/pg_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/backend/catalog/pg_subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/backend/commands/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/backend/commands/event_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/*
Expand Down
Loading
Loading