8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -67,17 +67,24 @@ static Datum ExecMakeFunctionResult(Node *node, List *arguments,
67
67
/*
68
68
* ExecEvalArrayRef
69
69
*
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).
73
79
*/
74
80
static Datum
75
81
ExecEvalArrayRef (ArrayRef * arrayRef ,
76
82
ExprContext * econtext ,
77
83
bool * isNull ,
78
84
bool * isDone )
79
85
{
80
- ArrayType * array_scanner ;
86
+ ArrayType * array_source ;
87
+ ArrayType * resultArray ;
81
88
List * elt ;
82
89
int i = 0 ,
83
90
j = 0 ;
@@ -90,7 +97,7 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
90
97
91
98
if (arrayRef -> refexpr != NULL )
92
99
{
93
- array_scanner = (ArrayType * )
100
+ array_source = (ArrayType * )
94
101
DatumGetPointer (ExecEvalExpr (arrayRef -> refexpr ,
95
102
econtext ,
96
103
isNull ,
@@ -110,7 +117,7 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
110
117
* the INSERT column list. This is a kluge, but it's not real
111
118
* clear what the semantics ought to be...
112
119
*/
113
- array_scanner = NULL ;
120
+ array_source = NULL ;
114
121
}
115
122
116
123
foreach (elt , arrayRef -> refupperindexpr )
@@ -162,43 +169,45 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
162
169
if (* isNull )
163
170
return (Datum ) NULL ;
164
171
165
- if (array_scanner == NULL )
172
+ if (array_source == NULL )
166
173
return sourceData ; /* XXX do something else? */
167
174
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
- */
174
175
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 );
188
192
}
189
193
190
194
if (lIndex == NULL )
191
- return array_ref (array_scanner , i ,
195
+ return array_ref (array_source , i ,
192
196
upper .indx ,
193
197
arrayRef -> refelembyval ,
194
198
arrayRef -> refelemlength ,
195
199
arrayRef -> refattrlength ,
196
200
isNull );
197
- return PointerGetDatum (array_clip (array_scanner , i ,
201
+ else
202
+ {
203
+ resultArray = array_get_slice (array_source , i ,
198
204
upper .indx , lower .indx ,
199
205
arrayRef -> refelembyval ,
200
206
arrayRef -> refelemlength ,
201
- isNull ));
207
+ arrayRef -> refattrlength ,
208
+ isNull );
209
+ return PointerGetDatum (resultArray );
210
+ }
202
211
}
203
212
204
213
0 commit comments