mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
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:
@ -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,
|
||||
|
Reference in New Issue
Block a user