handle-empty-arrays-correctly-always.patch
text/x-diff
Filename: handle-empty-arrays-correctly-always.patch
Type: text/x-diff
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/executor/execExprInterp.c | 0 | 0 |
| src/backend/utils/adt/arrayfuncs.c | 0 | 0 |
diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c
index bd8a15d..09abd46 100644
*** a/src/backend/executor/execExprInterp.c
--- b/src/backend/executor/execExprInterp.c
*************** ExecEvalArrayExpr(ExprState *state, Expr
*** 2131,2144 ****
Datum *dvalues = op->d.arrayexpr.elemvalues;
bool *dnulls = op->d.arrayexpr.elemnulls;
- /* Shouldn't happen here, but if length is 0, return empty array */
- if (nelems == 0)
- {
- *op->resvalue =
- PointerGetDatum(construct_empty_array(element_type));
- return;
- }
-
/* setup for 1-D array of the given length */
ndims = 1;
dims[0] = nelems;
--- 2131,2136 ----
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index e4101c9..d1f2fe7 100644
*** a/src/backend/utils/adt/arrayfuncs.c
--- b/src/backend/utils/adt/arrayfuncs.c
*************** array_map(FunctionCallInfo fcinfo, Oid r
*** 3297,3302 ****
--- 3297,3303 ----
*
* A palloc'd 1-D array object is constructed and returned. Note that
* elem values will be copied into the object even if pass-by-ref type.
+ * Also note the result will be 0-D not 1-D if nelems = 0.
*
* NOTE: it would be cleaner to look up the elmlen/elmbval/elmalign info
* from the system catalogs, given the elmtype. However, the caller is
*************** construct_array(Datum *elems, int nelems
*** 3331,3336 ****
--- 3332,3338 ----
*
* A palloc'd ndims-D array object is constructed and returned. Note that
* elem values will be copied into the object even if pass-by-ref type.
+ * Also note the result will be 0-D not ndims-D if any dims[i] = 0.
*
* NOTE: it would be cleaner to look up the elmlen/elmbval/elmalign info
* from the system catalogs, given the elmtype. However, the caller is
*************** construct_md_array(Datum *elems,
*** 3362,3373 ****
errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
ndims, MAXDIM)));
- /* fast track for empty array */
- if (ndims == 0)
- return construct_empty_array(elmtype);
-
nelems = ArrayGetNItems(ndims, dims);
/* compute required space */
nbytes = 0;
hasnulls = false;
--- 3364,3375 ----
errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
ndims, MAXDIM)));
nelems = ArrayGetNItems(ndims, dims);
+ /* if ndims <= 0 or any dims[i] == 0, return empty array */
+ if (nelems <= 0)
+ return construct_empty_array(elmtype);
+
/* compute required space */
nbytes = 0;
hasnulls = false;