summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2002-08-26 17:54:02 +0000
committerTom Lane2002-08-26 17:54:02 +0000
commit5cabcfccce4b8b826c9b30828f3012b7926a6946 (patch)
tree3e14c0710a45b4195734dd3189eb89eac4969073 /src/include
parent8009c275925dda90f1275ba70f5c2a63abaa520b (diff)
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.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/catalog/catversion.h4
-rw-r--r--src/include/catalog/pg_proc.h8
-rw-r--r--src/include/catalog/pg_type.h3
-rw-r--r--src/include/nodes/primnodes.h14
-rw-r--r--src/include/utils/array.h34
-rw-r--r--src/include/utils/lsyscache.h4
6 files changed, 34 insertions, 33 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index a45b775dc7e..4656f2ee97b 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: catversion.h,v 1.152 2002/08/24 15:00:46 tgl Exp $
+ * $Id: catversion.h,v 1.153 2002/08/26 17:53:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 200208231
+#define CATALOG_VERSION_NO 200208251
#endif
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 4129ea73b40..1e0c775b537 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_proc.h,v 1.264 2002/08/23 16:41:37 tgl Exp $
+ * $Id: pg_proc.h,v 1.265 2002/08/26 17:53:59 tgl Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
@@ -985,9 +985,9 @@ DESCR("session user name");
DATA(insert OID = 747 ( array_dims PGNSP PGUID 12 f f t f i 1 25 "2277" array_dims - _null_ ));
DESCR("array dimensions");
-DATA(insert OID = 750 ( array_in PGNSP PGUID 12 f f t f i 3 2277 "2275 26 23" array_in - _null_ ));
+DATA(insert OID = 750 ( array_in PGNSP PGUID 12 f f t f s 3 2277 "2275 26 23" array_in - _null_ ));
DESCR("array");
-DATA(insert OID = 751 ( array_out PGNSP PGUID 12 f f t f i 2 2275 "2281 26" array_out - _null_ ));
+DATA(insert OID = 751 ( array_out PGNSP PGUID 12 f f t f s 1 2275 "2277" array_out - _null_ ));
DESCR("array");
DATA(insert OID = 760 ( smgrin PGNSP PGUID 12 f f t f s 1 210 "2275" smgrin - _null_ ));
@@ -3083,7 +3083,7 @@ DATA(insert OID = 2295 ( any_out PGNSP PGUID 12 f f t f i 1 2275 "2276" any_o
DESCR("(internal)");
DATA(insert OID = 2296 ( anyarray_in PGNSP PGUID 12 f f t f i 1 2277 "2275" anyarray_in - _null_ ));
DESCR("(internal)");
-DATA(insert OID = 2297 ( anyarray_out PGNSP PGUID 12 f f t f i 1 2275 "2277" anyarray_out - _null_ ));
+DATA(insert OID = 2297 ( anyarray_out PGNSP PGUID 12 f f t f s 1 2275 "2277" anyarray_out - _null_ ));
DESCR("(internal)");
DATA(insert OID = 2298 ( void_in PGNSP PGUID 12 f f t f i 1 2278 "2275" void_in - _null_ ));
DESCR("(internal)");
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index e72a9c4c84e..8efb6c07a3d 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_type.h,v 1.129 2002/08/24 15:00:46 tgl Exp $
+ * $Id: pg_type.h,v 1.130 2002/08/26 17:54:01 tgl Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@@ -413,6 +413,7 @@ DATA(insert OID = 1025 ( _tinterval PGNSP PGUID -1 f b t \054 0 704 array_in ar
DATA(insert OID = 1027 ( _polygon PGNSP PGUID -1 f b t \054 0 604 array_in array_out d x f 0 -1 0 _null_ _null_ ));
DATA(insert OID = 1033 ( aclitem PGNSP PGUID 8 f b t \054 0 0 aclitemin aclitemout i p f 0 -1 0 _null_ _null_ ));
DESCR("access control list");
+#define ACLITEMOID 1033
DATA(insert OID = 1034 ( _aclitem PGNSP PGUID -1 f b t \054 0 1033 array_in array_out i x f 0 -1 0 _null_ _null_ ));
DATA(insert OID = 1040 ( _macaddr PGNSP PGUID -1 f b t \054 0 829 array_in array_out i x f 0 -1 0 _null_ _null_ ));
DATA(insert OID = 1041 ( _inet PGNSP PGUID -1 f b t \054 0 869 array_in array_out i x f 0 -1 0 _null_ _null_ ));
diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index 647ff8bb392..8fbb9442b41 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -10,7 +10,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: primnodes.h,v 1.65 2002/07/04 15:24:11 thomas Exp $
+ * $Id: primnodes.h,v 1.66 2002/08/26 17:54:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -397,20 +397,20 @@ typedef struct SubLink
* varlena structures and have refattrlength = -1. In any case,
* an array type is never pass-by-value.
*
- * Note: currently, refelemtype is NOT the element type, but the array type,
- * when doing subarray fetch or either type of store. It would be cleaner
- * to add more fields so we can distinguish the array element type from the
- * result type of the ArrayRef operator...
+ * Note: refrestype is NOT the element type, but the array type,
+ * when doing subarray fetch or either type of store. It might be a good
+ * idea to include a refelemtype field as well.
* ----------------
*/
typedef struct ArrayRef
{
NodeTag type;
+ Oid refrestype; /* type of the result of the ArrayRef
+ * operation */
int refattrlength; /* typlen of array type */
int refelemlength; /* typlen of the array element type */
- Oid refelemtype; /* type of the result of the ArrayRef
- * operation */
bool refelembyval; /* is the element type pass-by-value? */
+ char refelemalign; /* typalign of the element type */
List *refupperindexpr;/* expressions that evaluate to upper
* array indexes */
List *reflowerindexpr;/* expressions that evaluate to lower
diff --git a/src/include/utils/array.h b/src/include/utils/array.h
index 459d2caaff2..b0920c70d9d 100644
--- a/src/include/utils/array.h
+++ b/src/include/utils/array.h
@@ -10,13 +10,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: array.h,v 1.32 2002/06/20 20:29:52 momjian Exp $
- *
- * NOTES
- * XXX the data array should be MAXALIGN'd -- currently we only INTALIGN
- * which is NOT good enough for, eg, arrays of Interval. Changing this
- * will break existing user tables so hold off until we have some other
- * reason to break user tables (like WAL).
+ * $Id: array.h,v 1.33 2002/08/26 17:54:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -35,6 +29,7 @@ typedef struct
int ndim; /* # of dimensions */
int flags; /* implementation flags */
/* flags field is currently unused, always zero. */
+ Oid elemtype; /* element type OID */
} ArrayType;
/*
@@ -61,6 +56,7 @@ typedef struct
*/
#define ARR_SIZE(a) (((ArrayType *) (a))->size)
#define ARR_NDIM(a) (((ArrayType *) (a))->ndim)
+#define ARR_ELEMTYPE(a) (((ArrayType *) (a))->elemtype)
#define ARR_DIMS(a) \
((int *) (((char *) (a)) + sizeof(ArrayType)))
@@ -90,29 +86,31 @@ extern Datum array_eq(PG_FUNCTION_ARGS);
extern Datum array_dims(PG_FUNCTION_ARGS);
extern Datum array_ref(ArrayType *array, int nSubscripts, int *indx,
- bool elmbyval, int elmlen,
- int arraylen, bool *isNull);
+ int arraylen, int elmlen, bool elmbyval, char elmalign,
+ bool *isNull);
extern ArrayType *array_set(ArrayType *array, int nSubscripts, int *indx,
Datum dataValue,
- bool elmbyval, int elmlen,
- int arraylen, bool *isNull);
+ int arraylen, int elmlen, bool elmbyval, char elmalign,
+ bool *isNull);
extern ArrayType *array_get_slice(ArrayType *array, int nSubscripts,
int *upperIndx, int *lowerIndx,
- bool elmbyval, int elmlen,
- int arraylen, bool *isNull);
+ int arraylen, int elmlen, bool elmbyval, char elmalign,
+ bool *isNull);
extern ArrayType *array_set_slice(ArrayType *array, int nSubscripts,
int *upperIndx, int *lowerIndx,
ArrayType *srcArray,
- bool elmbyval, int elmlen,
- int arraylen, bool *isNull);
+ int arraylen, int elmlen, bool elmbyval, char elmalign,
+ bool *isNull);
extern Datum array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType);
extern ArrayType *construct_array(Datum *elems, int nelems,
- bool elmbyval, int elmlen, char elmalign);
+ Oid elmtype,
+ int elmlen, bool elmbyval, char elmalign);
extern void deconstruct_array(ArrayType *array,
- bool elmbyval, int elmlen, char elmalign,
- Datum **elemsp, int *nelemsp);
+ Oid elmtype,
+ int elmlen, bool elmbyval, char elmalign,
+ Datum **elemsp, int *nelemsp);
/*
diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h
index ccd385b7779..78d09908659 100644
--- a/src/include/utils/lsyscache.h
+++ b/src/include/utils/lsyscache.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: lsyscache.h,v 1.58 2002/08/22 00:01:49 tgl Exp $
+ * $Id: lsyscache.h,v 1.59 2002/08/26 17:54:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -49,6 +49,8 @@ extern bool get_typisdefined(Oid typid);
extern int16 get_typlen(Oid typid);
extern bool get_typbyval(Oid typid);
extern void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval);
+extern void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval,
+ char *typalign);
extern char get_typstorage(Oid typid);
extern Node *get_typdefault(Oid typid);
extern char get_typtype(Oid typid);