mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Modify array operations to include array's element type OID in the
array header, and to compute sizing and alignment of array elements the same way normal tuple access operations do --- viz, using the tupmacs.h macros att_addlength and att_align. This makes the world safe for arrays of cstrings or intervals, and should make it much easier to write array-type-polymorphic functions; as examples see the cleanups of array_out and contrib/array_iterator. By Joe Conway and Tom Lane.
This commit is contained in:
34
src/backend/utils/cache/lsyscache.c
vendored
34
src/backend/utils/cache/lsyscache.c
vendored
@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.79 2002/08/22 00:01:44 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.80 2002/08/26 17:53:59 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Eventually, the index information should go through here, too.
|
||||
@ -885,6 +885,30 @@ get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
|
||||
ReleaseSysCache(tp);
|
||||
}
|
||||
|
||||
/*
|
||||
* get_typlenbyvalalign
|
||||
*
|
||||
* A three-fer: given the type OID, return typlen, typbyval, typalign.
|
||||
*/
|
||||
void
|
||||
get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval,
|
||||
char *typalign)
|
||||
{
|
||||
HeapTuple tp;
|
||||
Form_pg_type typtup;
|
||||
|
||||
tp = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(typid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "cache lookup failed for type %u", typid);
|
||||
typtup = (Form_pg_type) GETSTRUCT(tp);
|
||||
*typlen = typtup->typlen;
|
||||
*typbyval = typtup->typbyval;
|
||||
*typalign = typtup->typalign;
|
||||
ReleaseSysCache(tp);
|
||||
}
|
||||
|
||||
#ifdef NOT_USED
|
||||
char
|
||||
get_typalign(Oid typid)
|
||||
@ -1287,7 +1311,9 @@ get_attstatsslot(HeapTuple statstuple,
|
||||
* Do initial examination of the array. This produces a list of
|
||||
* text Datums --- ie, pointers into the text array value.
|
||||
*/
|
||||
deconstruct_array(statarray, false, -1, 'i', values, nvalues);
|
||||
deconstruct_array(statarray,
|
||||
TEXTOID, -1, false, 'i',
|
||||
values, nvalues);
|
||||
narrayelem = *nvalues;
|
||||
|
||||
/*
|
||||
@ -1346,8 +1372,8 @@ get_attstatsslot(HeapTuple statstuple,
|
||||
*/
|
||||
narrayelem = ARR_DIMS(statarray)[0];
|
||||
if (ARR_NDIM(statarray) != 1 || narrayelem <= 0 ||
|
||||
ARR_SIZE(statarray) != (ARR_OVERHEAD(1) + narrayelem * sizeof(float4)))
|
||||
elog(ERROR, "get_attstatsslot: stanumbers is bogus");
|
||||
ARR_ELEMTYPE(statarray) != FLOAT4OID)
|
||||
elog(ERROR, "get_attstatsslot: stanumbers is not a 1-D float4 array");
|
||||
*numbers = (float4 *) palloc(narrayelem * sizeof(float4));
|
||||
memcpy(*numbers, ARR_DATA_PTR(statarray), narrayelem * sizeof(float4));
|
||||
*nnumbers = narrayelem;
|
||||
|
Reference in New Issue
Block a user