Skip to content

Commit d0e17e2

Browse files
committed
Arrays are toastable. (At least if you initdb, which I didn't force.)
Remove a bunch of crufty code for large-object-based arrays, which is superseded by TOAST and likely hasn't worked in a long time anyway. Clean up array code a little, and in particular eliminate its habit of scribbling on the input array (ie, modifying the input tuple :-().
1 parent ec37ea1 commit d0e17e2

File tree

9 files changed

+463
-1726
lines changed

9 files changed

+463
-1726
lines changed

contrib/array/array_iterator.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
4747
FmgrInfo finfo;
4848

4949
/* Sanity checks */
50-
if ((array == (ArrayType *) NULL)
51-
|| (ARR_IS_LO(array) == true))
50+
if (array == (ArrayType *) NULL)
5251
{
5352
/* elog(NOTICE, "array_iterator: array is null"); */
5453
return (0);
5554
}
55+
56+
/* detoast input if necessary */
57+
array = DatumGetArrayTypeP(PointerGetDatum(array));
58+
5659
ndim = ARR_NDIM(array);
5760
dim = ARR_DIMS(array);
58-
nitems = getNitems(ndim, dim);
61+
nitems = ArrayGetNItems(ndim, dim);
5962
if (nitems == 0)
6063
{
6164
/* elog(NOTICE, "array_iterator: nitems = 0"); */

src/backend/commands/define.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.45 2000/07/17 03:04:44 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.46 2000/07/22 03:34:26 tgl Exp $
1414
*
1515
* DESCRIPTION
1616
* The "DefineFoo" routines take the parse tree and pick out the
@@ -691,10 +691,10 @@ DefineType(char *typeName, List *parameters)
691691
"array_in", /* receive procedure */
692692
"array_out", /* send procedure */
693693
typeName, /* element type name */
694-
defaultValue, /* default type value */
694+
NULL, /* never a default type value */
695695
false, /* never passed by value */
696-
alignment,
697-
'p'); /* ARRAY doesn't support TOAST yet */
696+
alignment, /* NB: must be 'i' or 'd' for arrays... */
697+
'x'); /* ARRAY is always toastable */
698698

699699
pfree(shadow_type);
700700
}

src/backend/executor/execQual.c

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.74 2000/07/17 03:04:51 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.75 2000/07/22 03:34:27 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -67,17 +67,24 @@ static Datum ExecMakeFunctionResult(Node *node, List *arguments,
6767
/*
6868
* ExecEvalArrayRef
6969
*
70-
* This function takes an ArrayRef and returns a Const Node if it
71-
* is an array reference or returns the changed Array Node if it is
72-
* an array assignment.
70+
* This function takes an ArrayRef and returns the extracted Datum
71+
* if it's a simple reference, or the modified array value if it's
72+
* an array assignment (read array element insertion).
73+
*
74+
* NOTE: we deliberately refrain from applying DatumGetArrayTypeP() here,
75+
* even though that might seem natural, because this code needs to support
76+
* both varlena arrays and fixed-length array types. DatumGetArrayTypeP()
77+
* only works for the varlena kind. The routines we call in arrayfuncs.c
78+
* have to know the difference (that's what they need refattrlength for).
7379
*/
7480
static Datum
7581
ExecEvalArrayRef(ArrayRef *arrayRef,
7682
ExprContext *econtext,
7783
bool *isNull,
7884
bool *isDone)
7985
{
80-
ArrayType *array_scanner;
86+
ArrayType *array_source;
87+
ArrayType *resultArray;
8188
List *elt;
8289
int i = 0,
8390
j = 0;
@@ -90,7 +97,7 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
9097

9198
if (arrayRef->refexpr != NULL)
9299
{
93-
array_scanner = (ArrayType *)
100+
array_source = (ArrayType *)
94101
DatumGetPointer(ExecEvalExpr(arrayRef->refexpr,
95102
econtext,
96103
isNull,
@@ -110,7 +117,7 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
110117
* the INSERT column list. This is a kluge, but it's not real
111118
* clear what the semantics ought to be...
112119
*/
113-
array_scanner = NULL;
120+
array_source = NULL;
114121
}
115122

116123
foreach(elt, arrayRef->refupperindexpr)
@@ -162,43 +169,45 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
162169
if (*isNull)
163170
return (Datum) NULL;
164171

165-
if (array_scanner == NULL)
172+
if (array_source == NULL)
166173
return sourceData; /* XXX do something else? */
167174

168-
/*
169-
* XXX shouldn't we copy the array value before modifying it??
170-
*
171-
* Or perhaps these array routines should deliver a modified copy
172-
* instead of changing the source in-place.
173-
*/
174175
if (lIndex == NULL)
175-
return PointerGetDatum(array_set(array_scanner, i,
176-
upper.indx,
177-
sourceData,
178-
arrayRef->refelembyval,
179-
arrayRef->refelemlength,
180-
arrayRef->refattrlength,
181-
isNull));
182-
return PointerGetDatum(array_assgn(array_scanner, i,
183-
upper.indx, lower.indx,
184-
(ArrayType *) DatumGetPointer(sourceData),
185-
arrayRef->refelembyval,
186-
arrayRef->refelemlength,
187-
isNull));
176+
resultArray = array_set(array_source, i,
177+
upper.indx,
178+
sourceData,
179+
arrayRef->refelembyval,
180+
arrayRef->refelemlength,
181+
arrayRef->refattrlength,
182+
isNull);
183+
else
184+
resultArray = array_set_slice(array_source, i,
185+
upper.indx, lower.indx,
186+
(ArrayType *) DatumGetPointer(sourceData),
187+
arrayRef->refelembyval,
188+
arrayRef->refelemlength,
189+
arrayRef->refattrlength,
190+
isNull);
191+
return PointerGetDatum(resultArray);
188192
}
189193

190194
if (lIndex == NULL)
191-
return array_ref(array_scanner, i,
195+
return array_ref(array_source, i,
192196
upper.indx,
193197
arrayRef->refelembyval,
194198
arrayRef->refelemlength,
195199
arrayRef->refattrlength,
196200
isNull);
197-
return PointerGetDatum(array_clip(array_scanner, i,
201+
else
202+
{
203+
resultArray = array_get_slice(array_source, i,
198204
upper.indx, lower.indx,
199205
arrayRef->refelembyval,
200206
arrayRef->refelemlength,
201-
isNull));
207+
arrayRef->refattrlength,
208+
isNull);
209+
return PointerGetDatum(resultArray);
210+
}
202211
}
203212

204213

src/backend/utils/adt/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Makefile for utils/adt
33
#
4-
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.39 2000/07/13 16:07:14 petere Exp $
4+
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.40 2000/07/22 03:34:43 tgl Exp $
55
#
66

77
subdir = src/backend/utils/adt
@@ -15,7 +15,7 @@ CFLAGS+= -mieee
1515
endif
1616
endif
1717

18-
OBJS = acl.o arrayfuncs.o arrayutils.o bool.o cash.o char.o chunk.o \
18+
OBJS = acl.o arrayfuncs.o arrayutils.o bool.o cash.o char.o \
1919
date.o datetime.o datum.o filename.o float.o format_type.o \
2020
geo_ops.o geo_selfuncs.o int.o int8.o like.o lztext.o \
2121
misc.o nabstime.o name.o not_in.o numeric.o numutils.o \

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy