This is an automated email from the ASF dual-hosted git repository.
chenjinbao1989 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
The following commit(s) were added to refs/heads/cbdb-postgres-merge by this
push:
new 32d6dc5cc83 Fix conflict errors for utils/adt
32d6dc5cc83 is described below
commit 32d6dc5cc8307deb041e97bf7e1783fdb5c32aa3
Author: Jinbao Chen <[email protected]>
AuthorDate: Mon Oct 6 16:18:59 2025 +0800
Fix conflict errors for utils/adt
---
src/backend/utils/activity/backend_status.c | 1 -
src/backend/utils/activity/pgstat_io.c | 2 +
src/backend/utils/adt/array_userfuncs.c | 1117 ++++++---------------------
src/backend/utils/adt/dbsize.c | 19 +-
src/backend/utils/adt/genfile.c | 3 +-
src/backend/utils/adt/gp_dump_oids.c | 2 +-
src/backend/utils/adt/lockfuncs.c | 2 +-
src/backend/utils/adt/mcxtfuncs.c | 5 +-
src/backend/utils/adt/misc.c | 5 +-
src/backend/utils/adt/numeric.c | 50 +-
src/backend/utils/adt/pg_upgrade_support.c | 4 +
src/backend/utils/adt/pgstatfuncs.c | 2 +-
src/backend/utils/adt/rowtypes.c | 1 -
src/backend/utils/adt/ruleutils.c | 59 +-
src/backend/utils/adt/timestamp.c | 27 +-
src/backend/utils/adt/xid8funcs.c | 2 +-
src/include/commands/tablespace.h | 1 +
src/include/utils/builtins.h | 4 +-
src/include/utils/numeric.h | 3 +-
src/test/regress/regress_gp.c | 2 +-
20 files changed, 347 insertions(+), 964 deletions(-)
diff --git a/src/backend/utils/activity/backend_status.c
b/src/backend/utils/activity/backend_status.c
index 78a5f257a1f..57a4949f2da 100644
--- a/src/backend/utils/activity/backend_status.c
+++ b/src/backend/utils/activity/backend_status.c
@@ -454,7 +454,6 @@ pgstat_bestart(void)
/*
* GPDB: Initialize per-portal statistics hash for resource queues.
*/
- pgstat_init_localportalhash();
/* Update app name to current GUC setting */
if (application_name)
diff --git a/src/backend/utils/activity/pgstat_io.c
b/src/backend/utils/activity/pgstat_io.c
index 8ec86701997..4fd4d95291b 100644
--- a/src/backend/utils/activity/pgstat_io.c
+++ b/src/backend/utils/activity/pgstat_io.c
@@ -314,6 +314,8 @@ pgstat_tracks_io_bktype(BackendType bktype)
case B_LOGGER:
case B_WAL_RECEIVER:
case B_WAL_WRITER:
+ case B_LOGIN_MONITOR:
+ case B_LOGIN_MONITOR_WORKER:
return false;
case B_AUTOVAC_LAUNCHER:
diff --git a/src/backend/utils/adt/array_userfuncs.c
b/src/backend/utils/adt/array_userfuncs.c
index 331b59980e0..e906a85daf4 100644
--- a/src/backend/utils/adt/array_userfuncs.c
+++ b/src/backend/utils/adt/array_userfuncs.c
@@ -523,6 +523,38 @@ array_agg_transfn(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(state);
}
+Datum
+array_agg_finalfn(PG_FUNCTION_ARGS)
+{
+ Datum result;
+ ArrayBuildState *state;
+ int dims[1];
+ int lbs[1];
+
+ /* cannot be called directly because of internal-type argument */
+ Assert(AggCheckCallContext(fcinfo, NULL));
+
+ state = PG_ARGISNULL(0) ? NULL : (ArrayBuildState *)
PG_GETARG_POINTER(0);
+
+ if (state == NULL)
+ PG_RETURN_NULL(); /* returns null iff no input
values */
+
+ dims[0] = state->nelems;
+ lbs[0] = 1;
+
+ /*
+ * Make the result. We cannot release the ArrayBuildState because
+ * sometimes aggregate final functions are re-executed. Rather, it is
+ * nodeAgg.c's responsibility to reset the aggcontext when it's safe to
do
+ * so.
+ */
+ result = makeMdArrayResult(state, 1, dims, lbs,
+ CurrentMemoryContext,
+ false);
+
+ PG_RETURN_DATUM(result);
+}
+
Datum
array_agg_combine(PG_FUNCTION_ARGS)
{
@@ -530,6 +562,7 @@ array_agg_combine(PG_FUNCTION_ARGS)
ArrayBuildState *state2;
MemoryContext agg_context;
MemoryContext old_context;
+ int i;
if (!AggCheckCallContext(fcinfo, &agg_context))
elog(ERROR, "aggregate function called in non-aggregate
context");
@@ -556,7 +589,7 @@ array_agg_combine(PG_FUNCTION_ARGS)
old_context = MemoryContextSwitchTo(agg_context);
- for (int i = 0; i < state2->nelems; i++)
+ for (i = 0; i < state2->nelems; i++)
{
if (!state2->dnulls[i])
state1->dvalues[i] =
datumCopy(state2->dvalues[i],
@@ -586,7 +619,9 @@ array_agg_combine(PG_FUNCTION_ARGS)
if (state1->alen < reqsize)
{
/* Use a power of 2 size rather than allocating just
reqsize */
- state1->alen = pg_nextpower2_32(reqsize);
+ while (state1->alen < reqsize)
+ state1->alen *= 2;
+
state1->dvalues = (Datum *) repalloc(state1->dvalues,
state1->alen * sizeof(Datum));
state1->dnulls = (bool *) repalloc(state1->dnulls,
@@ -594,7 +629,7 @@ array_agg_combine(PG_FUNCTION_ARGS)
}
/* Copy in the state2 elements to the end of the state1 arrays
*/
- for (int i = 0; i < state2->nelems; i++)
+ for (i = 0; i < state2->nelems; i++)
{
if (!state2->dnulls[i])
state1->dvalues[i + state1->nelems] =
@@ -637,7 +672,7 @@ array_agg_serialize(PG_FUNCTION_ARGS)
/*
* element_type. Putting this first is more convenient in
deserialization
*/
- pq_sendint32(&buf, state->element_type);
+ pq_sendint(&buf, state->element_type, sizeof(Oid));
/*
* nelems -- send first so we know how large to make the dvalues and
@@ -648,7 +683,7 @@ array_agg_serialize(PG_FUNCTION_ARGS)
/* alen can be decided during deserialization */
/* typlen */
- pq_sendint16(&buf, state->typlen);
+ pq_sendint(&buf, state->typlen, sizeof(int16));
/* typbyval */
pq_sendbyte(&buf, state->typbyval);
@@ -657,7 +692,7 @@ array_agg_serialize(PG_FUNCTION_ARGS)
pq_sendbyte(&buf, state->typalign);
/* dnulls */
- pq_sendbytes(&buf, state->dnulls, sizeof(bool) * state->nelems);
+ pq_sendbytes(&buf, (char *) state->dnulls, sizeof(bool) *
state->nelems);
/*
* dvalues. By agreement with array_agg_deserialize, when the element
@@ -667,7 +702,8 @@ array_agg_serialize(PG_FUNCTION_ARGS)
* must be sent first).
*/
if (state->typbyval)
- pq_sendbytes(&buf, state->dvalues, sizeof(Datum) *
state->nelems);
+ pq_sendbytes(&buf, (char *) state->dvalues,
+ sizeof(Datum) * state->nelems);
else
{
SerialIOData *iodata;
@@ -698,7 +734,7 @@ array_agg_serialize(PG_FUNCTION_ARGS)
continue;
outputbytes = SendFunctionCall(&iodata->typsend,
state->dvalues[i]);
- pq_sendint32(&buf, VARSIZE(outputbytes) - VARHDRSZ);
+ pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ,
sizeof(int32));
pq_sendbytes(&buf, VARDATA(outputbytes),
VARSIZE(outputbytes) -
VARHDRSZ);
}
@@ -733,7 +769,7 @@ array_agg_deserialize(PG_FUNCTION_ARGS)
VARDATA_ANY(sstate),
VARSIZE_ANY_EXHDR(sstate));
/* element_type */
- element_type = pq_getmsgint(&buf, 4);
+ element_type = pq_getmsgint(&buf, sizeof(Oid));
/* nelems */
nelems = pq_getmsgint64(&buf);
@@ -744,7 +780,7 @@ array_agg_deserialize(PG_FUNCTION_ARGS)
result->nelems = nelems;
/* typlen */
- result->typlen = pq_getmsgint(&buf, 2);
+ result->typlen = pq_getmsgint(&buf, sizeof(int16));
/* typbyval */
result->typbyval = pq_getmsgbyte(&buf);
@@ -765,6 +801,7 @@ array_agg_deserialize(PG_FUNCTION_ARGS)
else
{
DeserialIOData *iodata;
+ int i;
/* Avoid repeat catalog lookups for typreceive function */
iodata = (DeserialIOData *) fcinfo->flinfo->fn_extra;
@@ -782,7 +819,7 @@ array_agg_deserialize(PG_FUNCTION_ARGS)
fcinfo->flinfo->fn_extra = (void *) iodata;
}
- for (int i = 0; i < nelems; i++)
+ for (i = 0; i < nelems; i++)
{
int itemlen;
StringInfoData elem_buf;
@@ -832,482 +869,136 @@ array_agg_deserialize(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(result);
}
-Datum
-array_agg_finalfn(PG_FUNCTION_ARGS)
-{
- Datum result;
- ArrayBuildState *state;
- int dims[1];
- int lbs[1];
-
- /* cannot be called directly because of internal-type argument */
- Assert(AggCheckCallContext(fcinfo, NULL));
-
- state = PG_ARGISNULL(0) ? NULL : (ArrayBuildState *)
PG_GETARG_POINTER(0);
-
- if (state == NULL)
- PG_RETURN_NULL(); /* returns null iff no input
values */
+/* Apache Cloudberry Additions: */
- dims[0] = state->nelems;
- lbs[0] = 1;
- /*
- * Make the result. We cannot release the ArrayBuildState because
- * sometimes aggregate final functions are re-executed. Rather, it is
- * nodeAgg.c's responsibility to reset the aggcontext when it's safe to
do
- * so.
- */
- result = makeMdArrayResult(state, 1, dims, lbs,
- CurrentMemoryContext,
- false);
+/*-----------------------------------------------------------------------------
+ * array_add :
+ * add two nD integer arrays element-wise to form an nD integer
array
+ * whose dimensions are the max of the corresponding argument dimensions.
+ * The result is zero-filled if necessary.
+ *
+ * For example, adding a 2x3 matrix of 1s to a 3x2 matrix of 2s will
+ * give the following 3x3 matrix:
+ *
3 3 1
+ *
3 3 1
+ *
2 2 0
+ *----------------------------------------------------------------------------
+ */
- PG_RETURN_DATUM(result);
-}
+static void accumToArray(int rank, int *rshape, int *rdata, int *ashape, int
*adata);
Datum
-array_agg_combine(PG_FUNCTION_ARGS)
+array_int4_add(PG_FUNCTION_ARGS)
{
- ArrayBuildState *state1;
- ArrayBuildState *state2;
- MemoryContext agg_context;
- MemoryContext old_context;
- int i;
+ ArrayType *v1, /* */
+ *v2; /* */
+ int *dims,
+ *lbs,
+ ndims,
+ ndatabytes,
+ nbytes;
+ int *dims1,
+ *lbs1,
+ ndims1,
+ ndatabytes1;
+ int *dims2,
+ *lbs2,
+ ndims2,
+ ndatabytes2;
+ bool bigenuf1,
+ bigenuf2;
+ int i,
+ nelem;
+ char *dat1,
+ *dat2;
+ int *idata;
+ Oid element_type; /* */
+ Oid element_type1; /* */
+ Oid element_type2; /* */
+ ArrayType *result;
- if (!AggCheckCallContext(fcinfo, &agg_context))
- elog(ERROR, "aggregate function called in non-aggregate
context");
+ v1 = PG_GETARG_ARRAYTYPE_P(0);
+ v2 = PG_GETARG_ARRAYTYPE_P(1);
- state1 = PG_ARGISNULL(0) ? NULL : (ArrayBuildState *)
PG_GETARG_POINTER(0);
- state2 = PG_ARGISNULL(1) ? NULL : (ArrayBuildState *)
PG_GETARG_POINTER(1);
+ element_type1 = ARR_ELEMTYPE(v1);
+ element_type2 = ARR_ELEMTYPE(v2);
- if (state2 == NULL)
- {
- /*
- * NULL state2 is easy, just return state1, which we know is
already
- * in the agg_context
- */
- if (state1 == NULL)
- PG_RETURN_NULL();
- PG_RETURN_POINTER(state1);
- }
+ /* Make sure we have int arrays. */
+ if (element_type1 != INT4OID || element_type2 != INT4OID)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ errmsg("cannot add non-int arrays"),
+ errdetail("Arrays with element types %s and %s
are not "
+ "compatible for array_add.",
+
format_type_be(element_type1),
+
format_type_be(element_type2))));
- if (state1 == NULL)
- {
- /* We must copy state2's data into the agg_context */
- state1 = initArrayResultWithSize(state2->element_type,
agg_context,
-
false, state2->alen);
+ /* Use the input element type as the output type too. */
+ element_type = element_type1;
- old_context = MemoryContextSwitchTo(agg_context);
+ /*----------
+ * We must have one of the following combinations of inputs:
+ * 1) one empty array, and one non-empty array
+ * 2) both arrays empty
+ * 3) two arrays with ndims1 == ndims2
+ *----------
+ */
+ ndims1 = ARR_NDIM(v1);
+ ndims2 = ARR_NDIM(v2);
- for (i = 0; i < state2->nelems; i++)
- {
- if (!state2->dnulls[i])
- state1->dvalues[i] =
datumCopy(state2->dvalues[i],
-
state1->typbyval,
-
state1->typlen);
- else
- state1->dvalues[i] = (Datum) 0;
- }
+ /*
+ * short circuit - if one input array is empty, and the other is not, we
+ * return the non-empty one as the result
+ *
+ * if both are empty, return the first one
+ */
+ if (ndims1 == 0 && ndims2 > 0)
+ PG_RETURN_ARRAYTYPE_P(v2);
- MemoryContextSwitchTo(old_context);
+ if (ndims2 == 0)
+ PG_RETURN_ARRAYTYPE_P(v1);
- memcpy(state1->dnulls, state2->dnulls, sizeof(bool) *
state2->nelems);
+ /* the rest fall under rule 3 */
+ if (ndims1 != ndims2)
+ ereport(ERROR,
+ (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+ errmsg("cannot add incompatible arrays"),
+ errdetail("Arrays of %d and %d dimensions are
not "
+ "compatible for array_add.",
+ ndims1, ndims2)));
- state1->nelems = state2->nelems;
+ /* get argument array details */
+ lbs1 = ARR_LBOUND(v1);
+ lbs2 = ARR_LBOUND(v2);
+ dims1 = ARR_DIMS(v1);
+ dims2 = ARR_DIMS(v2);
+ dat1 = ARR_DATA_PTR(v1);
+ dat2 = ARR_DATA_PTR(v2);
- PG_RETURN_POINTER(state1);
- }
- else if (state2->nelems > 0)
- {
- /* We only need to combine the two states if state2 has any
elements */
- int reqsize = state1->nelems +
state2->nelems;
- MemoryContext oldContext =
MemoryContextSwitchTo(state1->mcontext);
+ ndatabytes1 = ARR_SIZE(v1) - ARR_DATA_OFFSET(v1);
+ ndatabytes2 = ARR_SIZE(v2) - ARR_DATA_OFFSET(v2);
- Assert(state1->element_type == state2->element_type);
+ /*
+ * resulting array is made up of the elements (possibly arrays
+ * themselves) of the input argument arrays
+ */
+ ndims = ndims1;
+ dims = (int *) palloc(ndims * sizeof(int));
+ lbs = (int *) palloc(ndims * sizeof(int));
+ bigenuf1 = bigenuf2 = true;
+ nelem = 1; /* Neither is empty. */
- /* Enlarge state1 arrays if needed */
- if (state1->alen < reqsize)
+ for (i = 0; i < ndims; i++)
+ {
+ if ( dims1[i] == dims2[i] )
{
- /* Use a power of 2 size rather than allocating just
reqsize */
- while (state1->alen < reqsize)
- state1->alen *= 2;
-
- state1->dvalues = (Datum *) repalloc(state1->dvalues,
-
state1->alen * sizeof(Datum));
- state1->dnulls = (bool *) repalloc(state1->dnulls,
-
state1->alen * sizeof(bool));
+ dims[i] = dims1[i];
}
-
- /* Copy in the state2 elements to the end of the state1 arrays
*/
- for (i = 0; i < state2->nelems; i++)
+ else if ( dims1[i] < dims2[i] )
{
- if (!state2->dnulls[i])
- state1->dvalues[i + state1->nelems] =
- datumCopy(state2->dvalues[i],
- state1->typbyval,
- state1->typlen);
- else
- state1->dvalues[i + state1->nelems] = (Datum) 0;
- }
-
- memcpy(&state1->dnulls[state1->nelems], state2->dnulls,
- sizeof(bool) * state2->nelems);
-
- state1->nelems = reqsize;
-
- MemoryContextSwitchTo(oldContext);
- }
-
- PG_RETURN_POINTER(state1);
-}
-
-/*
- * array_agg_serialize
- * Serialize ArrayBuildState into bytea.
- */
-Datum
-array_agg_serialize(PG_FUNCTION_ARGS)
-{
- ArrayBuildState *state;
- StringInfoData buf;
- bytea *result;
-
- /* cannot be called directly because of internal-type argument */
- Assert(AggCheckCallContext(fcinfo, NULL));
-
- state = (ArrayBuildState *) PG_GETARG_POINTER(0);
-
- pq_begintypsend(&buf);
-
- /*
- * element_type. Putting this first is more convenient in
deserialization
- */
- pq_sendint(&buf, state->element_type, sizeof(Oid));
-
- /*
- * nelems -- send first so we know how large to make the dvalues and
- * dnulls array during deserialization.
- */
- pq_sendint64(&buf, state->nelems);
-
- /* alen can be decided during deserialization */
-
- /* typlen */
- pq_sendint(&buf, state->typlen, sizeof(int16));
-
- /* typbyval */
- pq_sendbyte(&buf, state->typbyval);
-
- /* typalign */
- pq_sendbyte(&buf, state->typalign);
-
- /* dnulls */
- pq_sendbytes(&buf, (char *) state->dnulls, sizeof(bool) *
state->nelems);
-
- /*
- * dvalues. By agreement with array_agg_deserialize, when the element
- * type is byval, we just transmit the Datum array as-is, including any
- * null elements. For by-ref types, we must invoke the element type's
- * send function, and we skip null elements (which is why the nulls
flags
- * must be sent first).
- */
- if (state->typbyval)
- pq_sendbytes(&buf, (char *) state->dvalues,
- sizeof(Datum) * state->nelems);
- else
- {
- SerialIOData *iodata;
- int i;
-
- /* Avoid repeat catalog lookups for typsend function */
- iodata = (SerialIOData *) fcinfo->flinfo->fn_extra;
- if (iodata == NULL)
- {
- Oid typsend;
- bool typisvarlena;
-
- iodata = (SerialIOData *)
- MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
-
sizeof(SerialIOData));
- getTypeBinaryOutputInfo(state->element_type, &typsend,
-
&typisvarlena);
- fmgr_info_cxt(typsend, &iodata->typsend,
- fcinfo->flinfo->fn_mcxt);
- fcinfo->flinfo->fn_extra = (void *) iodata;
- }
-
- for (i = 0; i < state->nelems; i++)
- {
- bytea *outputbytes;
-
- if (state->dnulls[i])
- continue;
- outputbytes = SendFunctionCall(&iodata->typsend,
-
state->dvalues[i]);
- pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ,
sizeof(int32));
- pq_sendbytes(&buf, VARDATA(outputbytes),
- VARSIZE(outputbytes) -
VARHDRSZ);
- }
- }
-
- result = pq_endtypsend(&buf);
-
- PG_RETURN_BYTEA_P(result);
-}
-
-Datum
-array_agg_deserialize(PG_FUNCTION_ARGS)
-{
- bytea *sstate;
- ArrayBuildState *result;
- StringInfoData buf;
- Oid element_type;
- int64 nelems;
- const char *temp;
-
- if (!AggCheckCallContext(fcinfo, NULL))
- elog(ERROR, "aggregate function called in non-aggregate
context");
-
- sstate = PG_GETARG_BYTEA_PP(0);
-
- /*
- * Copy the bytea into a StringInfo so that we can "receive" it using
the
- * standard recv-function infrastructure.
- */
- initStringInfo(&buf);
- appendBinaryStringInfo(&buf,
- VARDATA_ANY(sstate),
VARSIZE_ANY_EXHDR(sstate));
-
- /* element_type */
- element_type = pq_getmsgint(&buf, sizeof(Oid));
-
- /* nelems */
- nelems = pq_getmsgint64(&buf);
-
- /* Create output ArrayBuildState with the needed number of elements */
- result = initArrayResultWithSize(element_type, CurrentMemoryContext,
- false,
nelems);
- result->nelems = nelems;
-
- /* typlen */
- result->typlen = pq_getmsgint(&buf, sizeof(int16));
-
- /* typbyval */
- result->typbyval = pq_getmsgbyte(&buf);
-
- /* typalign */
- result->typalign = pq_getmsgbyte(&buf);
-
- /* dnulls */
- temp = pq_getmsgbytes(&buf, sizeof(bool) * nelems);
- memcpy(result->dnulls, temp, sizeof(bool) * nelems);
-
- /* dvalues --- see comment in array_agg_serialize */
- if (result->typbyval)
- {
- temp = pq_getmsgbytes(&buf, sizeof(Datum) * nelems);
- memcpy(result->dvalues, temp, sizeof(Datum) * nelems);
- }
- else
- {
- DeserialIOData *iodata;
- int i;
-
- /* Avoid repeat catalog lookups for typreceive function */
- iodata = (DeserialIOData *) fcinfo->flinfo->fn_extra;
- if (iodata == NULL)
- {
- Oid typreceive;
-
- iodata = (DeserialIOData *)
- MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
-
sizeof(DeserialIOData));
- getTypeBinaryInputInfo(element_type, &typreceive,
-
&iodata->typioparam);
- fmgr_info_cxt(typreceive, &iodata->typreceive,
- fcinfo->flinfo->fn_mcxt);
- fcinfo->flinfo->fn_extra = (void *) iodata;
- }
-
- for (i = 0; i < nelems; i++)
- {
- int itemlen;
- StringInfoData elem_buf;
- char csave;
-
- if (result->dnulls[i])
- {
- result->dvalues[i] = (Datum) 0;
- continue;
- }
-
- itemlen = pq_getmsgint(&buf, 4);
- if (itemlen < 0 || itemlen > (buf.len - buf.cursor))
- ereport(ERROR,
-
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
- errmsg("insufficient data left
in message")));
-
- /*
- * Rather than copying data around, we just set up a
phony
- * StringInfo pointing to the correct portion of the
input buffer.
- * We assume we can scribble on the input buffer so as
to maintain
- * the convention that StringInfos have a trailing null.
- */
- elem_buf.data = &buf.data[buf.cursor];
- elem_buf.maxlen = itemlen + 1;
- elem_buf.len = itemlen;
- elem_buf.cursor = 0;
-
- buf.cursor += itemlen;
-
- csave = buf.data[buf.cursor];
- buf.data[buf.cursor] = '\0';
-
- /* Now call the element's receiveproc */
- result->dvalues[i] =
ReceiveFunctionCall(&iodata->typreceive,
-
&elem_buf,
-
iodata->typioparam,
-
-1);
-
- buf.data[buf.cursor] = csave;
- }
- }
-
- pq_getmsgend(&buf);
- pfree(buf.data);
-
- PG_RETURN_POINTER(result);
-}
-
-/* Apache Cloudberry Additions: */
-
-
-/*-----------------------------------------------------------------------------
- * array_add :
- * add two nD integer arrays element-wise to form an nD integer
array
- * whose dimensions are the max of the corresponding argument dimensions.
- * The result is zero-filled if necessary.
- *
- * For example, adding a 2x3 matrix of 1s to a 3x2 matrix of 2s will
- * give the following 3x3 matrix:
- *
3 3 1
- *
3 3 1
- *
2 2 0
- *----------------------------------------------------------------------------
- */
-
-static void accumToArray(int rank, int *rshape, int *rdata, int *ashape, int
*adata);
-
-Datum
-array_int4_add(PG_FUNCTION_ARGS)
-{
- ArrayType *v1, /* */
- *v2; /* */
- int *dims,
- *lbs,
- ndims,
- ndatabytes,
- nbytes;
- int *dims1,
- *lbs1,
- ndims1,
- ndatabytes1;
- int *dims2,
- *lbs2,
- ndims2,
- ndatabytes2;
- bool bigenuf1,
- bigenuf2;
- int i,
- nelem;
- char *dat1,
- *dat2;
- int *idata;
- Oid element_type; /* */
- Oid element_type1; /* */
- Oid element_type2; /* */
- ArrayType *result;
-
- v1 = PG_GETARG_ARRAYTYPE_P(0);
- v2 = PG_GETARG_ARRAYTYPE_P(1);
-
- element_type1 = ARR_ELEMTYPE(v1);
- element_type2 = ARR_ELEMTYPE(v2);
-
- /* Make sure we have int arrays. */
- if (element_type1 != INT4OID || element_type2 != INT4OID)
- ereport(ERROR,
- (errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("cannot add non-int arrays"),
- errdetail("Arrays with element types %s and %s
are not "
- "compatible for array_add.",
-
format_type_be(element_type1),
-
format_type_be(element_type2))));
-
- /* Use the input element type as the output type too. */
- element_type = element_type1;
-
- /*----------
- * We must have one of the following combinations of inputs:
- * 1) one empty array, and one non-empty array
- * 2) both arrays empty
- * 3) two arrays with ndims1 == ndims2
- *----------
- */
- ndims1 = ARR_NDIM(v1);
- ndims2 = ARR_NDIM(v2);
-
- /*
- * short circuit - if one input array is empty, and the other is not, we
- * return the non-empty one as the result
- *
- * if both are empty, return the first one
- */
- if (ndims1 == 0 && ndims2 > 0)
- PG_RETURN_ARRAYTYPE_P(v2);
-
- if (ndims2 == 0)
- PG_RETURN_ARRAYTYPE_P(v1);
-
- /* the rest fall under rule 3 */
- if (ndims1 != ndims2)
- ereport(ERROR,
- (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("cannot add incompatible arrays"),
- errdetail("Arrays of %d and %d dimensions are
not "
- "compatible for array_add.",
- ndims1, ndims2)));
-
- /* get argument array details */
- lbs1 = ARR_LBOUND(v1);
- lbs2 = ARR_LBOUND(v2);
- dims1 = ARR_DIMS(v1);
- dims2 = ARR_DIMS(v2);
- dat1 = ARR_DATA_PTR(v1);
- dat2 = ARR_DATA_PTR(v2);
-
- ndatabytes1 = ARR_SIZE(v1) - ARR_DATA_OFFSET(v1);
- ndatabytes2 = ARR_SIZE(v2) - ARR_DATA_OFFSET(v2);
-
- /*
- * resulting array is made up of the elements (possibly arrays
- * themselves) of the input argument arrays
- */
- ndims = ndims1;
- dims = (int *) palloc(ndims * sizeof(int));
- lbs = (int *) palloc(ndims * sizeof(int));
- bigenuf1 = bigenuf2 = true;
- nelem = 1; /* Neither is empty. */
-
- for (i = 0; i < ndims; i++)
- {
- if ( dims1[i] == dims2[i] )
- {
- dims[i] = dims1[i];
- }
- else if ( dims1[i] < dims2[i] )
- {
- bigenuf1 = false;
- dims[i] = dims2[i];
+ bigenuf1 = false;
+ dims[i] = dims2[i];
}
else /* dims1[i] > dims2[i] */
{
@@ -1375,400 +1066,82 @@ array_int4_add(PG_FUNCTION_ARGS)
* at an index position of all zero align. The result is zero-filled.
*/
void accumToArray(int rank, int *rshape, int *rdata, int *ashape, int *adata)
-{
- int d, i, j, k;
- int m[MAXDIM];
-
- Assert( rank > 0 && rank <= MAXDIM );
-
- memset(m, 0, sizeof m);
-
- i = j = 0;
- do
- {
- rdata[j] += adata[i];
-
- for ( d = rank - 1; d >= 0; d-- )
- {
-
- m[d]++;
- if ( m[d] < ashape[d] )
- break;
- else
- m[d] = 0;
- }
-
- i++;
-
- for ( k = 1, j = m[0]; k < rank; k++ )
- j = j * rshape[k] + m[k];
- }
- while ( d >= 0 );
-}
-
-/*
- * ARRAY_AGG(anyarray) aggregate function
- */
-Datum
-array_agg_array_transfn(PG_FUNCTION_ARGS)
-{
- Oid arg1_typeid =
get_fn_expr_argtype(fcinfo->flinfo, 1);
- MemoryContext aggcontext;
- ArrayBuildStateArr *state;
-
- if (arg1_typeid == InvalidOid)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("could not determine input data
type")));
-
- /*
- * Note: we do not need a run-time check about whether arg1_typeid is a
- * valid array type, because the parser would have verified that while
- * resolving the input/result types of this polymorphic aggregate.
- */
-
- if (!AggCheckCallContext(fcinfo, &aggcontext))
- {
- /* cannot be called directly because of internal-type argument
*/
- elog(ERROR, "array_agg_array_transfn called in non-aggregate
context");
- }
-
-
- if (PG_ARGISNULL(0))
- state = initArrayResultArr(arg1_typeid, InvalidOid, aggcontext,
false);
- else
- state = (ArrayBuildStateArr *) PG_GETARG_POINTER(0);
-
- state = accumArrayResultArr(state,
-
PG_GETARG_DATUM(1),
- PG_ARGISNULL(1),
- arg1_typeid,
- aggcontext);
-
- /*
- * The transition type for array_agg() is declared to be "internal",
which
- * is a pass-by-value type the same size as a pointer. So we can safely
- * pass the ArrayBuildStateArr pointer through nodeAgg.c's machinations.
- */
- PG_RETURN_POINTER(state);
-}
-
-Datum
-array_agg_array_combine(PG_FUNCTION_ARGS)
-{
- ArrayBuildStateArr *state1;
- ArrayBuildStateArr *state2;
- MemoryContext agg_context;
- MemoryContext old_context;
-
- if (!AggCheckCallContext(fcinfo, &agg_context))
- elog(ERROR, "aggregate function called in non-aggregate
context");
-
- state1 = PG_ARGISNULL(0) ? NULL : (ArrayBuildStateArr *)
PG_GETARG_POINTER(0);
- state2 = PG_ARGISNULL(1) ? NULL : (ArrayBuildStateArr *)
PG_GETARG_POINTER(1);
-
- if (state2 == NULL)
- {
- /*
- * NULL state2 is easy, just return state1, which we know is
already
- * in the agg_context
- */
- if (state1 == NULL)
- PG_RETURN_NULL();
- PG_RETURN_POINTER(state1);
- }
-
- if (state1 == NULL)
- {
- /* We must copy state2's data into the agg_context */
- old_context = MemoryContextSwitchTo(agg_context);
-
- state1 = initArrayResultArr(state2->array_type, InvalidOid,
-
agg_context, false);
-
- state1->abytes = state2->abytes;
- state1->data = (char *) palloc(state1->abytes);
-
- if (state2->nullbitmap)
- {
- int size = (state2->aitems + 7) / 8;
-
- state1->nullbitmap = (bits8 *) palloc(size);
- memcpy(state1->nullbitmap, state2->nullbitmap, size);
- }
-
- memcpy(state1->data, state2->data, state2->nbytes);
- state1->nbytes = state2->nbytes;
- state1->aitems = state2->aitems;
- state1->nitems = state2->nitems;
- state1->ndims = state2->ndims;
- memcpy(state1->dims, state2->dims, sizeof(state2->dims));
- memcpy(state1->lbs, state2->lbs, sizeof(state2->lbs));
- state1->array_type = state2->array_type;
- state1->element_type = state2->element_type;
-
- MemoryContextSwitchTo(old_context);
-
- PG_RETURN_POINTER(state1);
- }
-
- /* We only need to combine the two states if state2 has any items */
- else if (state2->nitems > 0)
- {
- MemoryContext oldContext;
- int reqsize = state1->nbytes +
state2->nbytes;
- int i;
-
- /*
- * Check the states are compatible with each other. Ensure we
use the
- * same error messages that are listed in accumArrayResultArr
so that
- * the same error is shown as would have been if we'd not used
the
- * combine function for the aggregation.
- */
- if (state1->ndims != state2->ndims)
- ereport(ERROR,
- (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("cannot accumulate arrays of
different dimensionality")));
-
- /* Check dimensions match ignoring the first dimension. */
- for (i = 1; i < state1->ndims; i++)
- {
- if (state1->dims[i] != state2->dims[i] ||
state1->lbs[i] != state2->lbs[i])
- ereport(ERROR,
-
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("cannot accumulate
arrays of different dimensionality")));
- }
-
-
- oldContext = MemoryContextSwitchTo(state1->mcontext);
-
- /*
- * If there's not enough space in state1 then we'll need to
reallocate
- * more.
- */
- if (state1->abytes < reqsize)
- {
- /* use a power of 2 size rather than allocating just
reqsize */
- state1->abytes = pg_nextpower2_32(reqsize);
- state1->data = (char *) repalloc(state1->data,
state1->abytes);
- }
-
- if (state2->nullbitmap)
- {
- int newnitems = state1->nitems +
state2->nitems;
-
- if (state1->nullbitmap == NULL)
- {
- /*
- * First input with nulls; we must
retrospectively handle any
- * previous inputs by marking all their items
non-null.
- */
- state1->aitems = pg_nextpower2_32(Max(256,
newnitems + 1));
- state1->nullbitmap = (bits8 *)
palloc((state1->aitems + 7) / 8);
- array_bitmap_copy(state1->nullbitmap, 0,
- NULL, 0,
-
state1->nitems);
- }
- else if (newnitems > state1->aitems)
- {
- int newaitems =
state1->aitems + state2->aitems;
-
- state1->aitems = pg_nextpower2_32(newaitems);
- state1->nullbitmap = (bits8 *)
- repalloc(state1->nullbitmap,
(state1->aitems + 7) / 8);
- }
- array_bitmap_copy(state1->nullbitmap, state1->nitems,
- state2->nullbitmap, 0,
- state2->nitems);
- }
-
- memcpy(state1->data + state1->nbytes, state2->data,
state2->nbytes);
- state1->nbytes += state2->nbytes;
- state1->nitems += state2->nitems;
-
- state1->dims[0] += state2->dims[0];
- /* remaining dims already match, per test above */
-
- Assert(state1->array_type == state2->array_type);
- Assert(state1->element_type == state2->element_type);
+{
+ int d, i, j, k;
+ int m[MAXDIM];
+
+ Assert( rank > 0 && rank <= MAXDIM );
+
+ memset(m, 0, sizeof m);
+
+ i = j = 0;
+ do
+ {
+ rdata[j] += adata[i];
- MemoryContextSwitchTo(oldContext);
+ for ( d = rank - 1; d >= 0; d-- )
+ {
+
+ m[d]++;
+ if ( m[d] < ashape[d] )
+ break;
+ else
+ m[d] = 0;
+ }
+
+ i++;
+
+ for ( k = 1, j = m[0]; k < rank; k++ )
+ j = j * rshape[k] + m[k];
}
-
- PG_RETURN_POINTER(state1);
+ while ( d >= 0 );
}
/*
- * array_agg_array_serialize
- * Serialize ArrayBuildStateArr into bytea.
+ * ARRAY_AGG(anyarray) aggregate function
*/
Datum
-array_agg_array_serialize(PG_FUNCTION_ARGS)
+array_agg_array_transfn(PG_FUNCTION_ARGS)
{
+ Oid arg1_typeid =
get_fn_expr_argtype(fcinfo->flinfo, 1);
+ MemoryContext aggcontext;
ArrayBuildStateArr *state;
- StringInfoData buf;
- bytea *result;
-
- /* cannot be called directly because of internal-type argument */
- Assert(AggCheckCallContext(fcinfo, NULL));
-
- state = (ArrayBuildStateArr *) PG_GETARG_POINTER(0);
- pq_begintypsend(&buf);
+ if (arg1_typeid == InvalidOid)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("could not determine input data
type")));
/*
- * element_type. Putting this first is more convenient in
deserialization
- * so that we can init the new state sooner.
+ * Note: we do not need a run-time check about whether arg1_typeid is a
+ * valid array type, because the parser would have verified that while
+ * resolving the input/result types of this polymorphic aggregate.
*/
- pq_sendint32(&buf, state->element_type);
-
- /* array_type */
- pq_sendint32(&buf, state->array_type);
-
- /* nbytes */
- pq_sendint32(&buf, state->nbytes);
-
- /* data */
- pq_sendbytes(&buf, state->data, state->nbytes);
- /* abytes */
- pq_sendint32(&buf, state->abytes);
-
- /* aitems */
- pq_sendint32(&buf, state->aitems);
-
- /* nullbitmap */
- if (state->nullbitmap)
+ if (!AggCheckCallContext(fcinfo, &aggcontext))
{
- Assert(state->aitems > 0);
- pq_sendbytes(&buf, state->nullbitmap, (state->aitems + 7) / 8);
+ /* cannot be called directly because of internal-type argument
*/
+ elog(ERROR, "array_agg_array_transfn called in non-aggregate
context");
}
- /* nitems */
- pq_sendint32(&buf, state->nitems);
-
- /* ndims */
- pq_sendint32(&buf, state->ndims);
-
- /* dims: XXX should we just send ndims elements? */
- pq_sendbytes(&buf, state->dims, sizeof(state->dims));
-
- /* lbs */
- pq_sendbytes(&buf, state->lbs, sizeof(state->lbs));
-
- result = pq_endtypsend(&buf);
-
- PG_RETURN_BYTEA_P(result);
-}
-
-Datum
-array_agg_array_deserialize(PG_FUNCTION_ARGS)
-{
- bytea *sstate;
- ArrayBuildStateArr *result;
- StringInfoData buf;
- Oid element_type;
- Oid array_type;
- int nbytes;
- const char *temp;
-
- /* cannot be called directly because of internal-type argument */
- Assert(AggCheckCallContext(fcinfo, NULL));
-
- sstate = PG_GETARG_BYTEA_PP(0);
-
- /*
- * Copy the bytea into a StringInfo so that we can "receive" it using
the
- * standard recv-function infrastructure.
- */
- initStringInfo(&buf);
- appendBinaryStringInfo(&buf,
- VARDATA_ANY(sstate),
VARSIZE_ANY_EXHDR(sstate));
-
- /* element_type */
- element_type = pq_getmsgint(&buf, 4);
-
- /* array_type */
- array_type = pq_getmsgint(&buf, 4);
-
- /* nbytes */
- nbytes = pq_getmsgint(&buf, 4);
-
- result = initArrayResultArr(array_type, element_type,
-
CurrentMemoryContext, false);
-
- result->abytes = 1024;
- while (result->abytes < nbytes)
- result->abytes *= 2;
-
- result->data = (char *) palloc(result->abytes);
-
- /* data */
- temp = pq_getmsgbytes(&buf, nbytes);
- memcpy(result->data, temp, nbytes);
- result->nbytes = nbytes;
-
- /* abytes */
- result->abytes = pq_getmsgint(&buf, 4);
-
- /* aitems: might be 0 */
- result->aitems = pq_getmsgint(&buf, 4);
-
- /* nullbitmap */
- if (result->aitems > 0)
- {
- int size = (result->aitems + 7) / 8;
- result->nullbitmap = (bits8 *) palloc(size);
- temp = pq_getmsgbytes(&buf, size);
- memcpy(result->nullbitmap, temp, size);
- }
+ if (PG_ARGISNULL(0))
+ state = initArrayResultArr(arg1_typeid, InvalidOid, aggcontext,
false);
else
- result->nullbitmap = NULL;
-
- /* nitems */
- result->nitems = pq_getmsgint(&buf, 4);
-
- /* ndims */
- result->ndims = pq_getmsgint(&buf, 4);
-
- /* dims */
- temp = pq_getmsgbytes(&buf, sizeof(result->dims));
- memcpy(result->dims, temp, sizeof(result->dims));
-
- /* lbs */
- temp = pq_getmsgbytes(&buf, sizeof(result->lbs));
- memcpy(result->lbs, temp, sizeof(result->lbs));
-
- pq_getmsgend(&buf);
- pfree(buf.data);
-
- PG_RETURN_POINTER(result);
-}
-
-Datum
-array_agg_array_finalfn(PG_FUNCTION_ARGS)
-{
- Datum result;
- ArrayBuildStateArr *state;
-
- /* cannot be called directly because of internal-type argument */
- Assert(AggCheckCallContext(fcinfo, NULL));
-
- state = PG_ARGISNULL(0) ? NULL : (ArrayBuildStateArr *)
PG_GETARG_POINTER(0);
+ state = (ArrayBuildStateArr *) PG_GETARG_POINTER(0);
- if (state == NULL)
- PG_RETURN_NULL(); /* returns null iff no input
values */
+ state = accumArrayResultArr(state,
+
PG_GETARG_DATUM(1),
+ PG_ARGISNULL(1),
+ arg1_typeid,
+ aggcontext);
/*
- * Make the result. We cannot release the ArrayBuildStateArr because
- * sometimes aggregate final functions are re-executed. Rather, it is
- * nodeAgg.c's responsibility to reset the aggcontext when it's safe to
do
- * so.
+ * The transition type for array_agg() is declared to be "internal",
which
+ * is a pass-by-value type the same size as a pointer. So we can safely
+ * pass the ArrayBuildStateArr pointer through nodeAgg.c's machinations.
*/
- result = makeArrayResultArr(state, CurrentMemoryContext, false);
-
- PG_RETURN_DATUM(result);
+ PG_RETURN_POINTER(state);
}
Datum
@@ -1867,9 +1240,7 @@ array_agg_array_combine(PG_FUNCTION_ARGS)
if (state1->abytes < reqsize)
{
/* use a power of 2 size rather than allocating just
reqsize */
- while (state1->abytes < reqsize)
- state1->abytes *= 2;
-
+ state1->abytes = pg_nextpower2_32(reqsize);
state1->data = (char *) repalloc(state1->data,
state1->abytes);
}
@@ -1883,9 +1254,7 @@ array_agg_array_combine(PG_FUNCTION_ARGS)
* First input with nulls; we must
retrospectively handle any
* previous inputs by marking all their items
non-null.
*/
- state1->aitems = 256;
- while (state1->aitems <= newnitems)
- state1->aitems *= 2;
+ state1->aitems = pg_nextpower2_32(Max(256,
newnitems + 1));
state1->nullbitmap = (bits8 *)
palloc((state1->aitems + 7) / 8);
array_bitmap_copy(state1->nullbitmap, 0,
NULL, 0,
@@ -1895,9 +1264,7 @@ array_agg_array_combine(PG_FUNCTION_ARGS)
{
int newaitems =
state1->aitems + state2->aitems;
- while (state1->aitems < newaitems)
- state1->aitems *= 2;
-
+ state1->aitems = pg_nextpower2_32(newaitems);
state1->nullbitmap = (bits8 *)
repalloc(state1->nullbitmap,
(state1->aitems + 7) / 8);
}
@@ -1911,10 +1278,10 @@ array_agg_array_combine(PG_FUNCTION_ARGS)
state1->nitems += state2->nitems;
state1->dims[0] += state2->dims[0];
- /* remaing dims already match, per test above */
+ /* remaining dims already match, per test above */
Assert(state1->array_type == state2->array_type);
- Assert(state1->element_type = state2->element_type);
+ Assert(state1->element_type == state2->element_type);
MemoryContextSwitchTo(oldContext);
}
@@ -1965,7 +1332,7 @@ array_agg_array_serialize(PG_FUNCTION_ARGS)
if (state->nullbitmap)
{
Assert(state->aitems > 0);
- pq_sendbytes(&buf, (char *) state->nullbitmap, (state->aitems +
7) / 8);
+ pq_sendbytes(&buf, state->nullbitmap, (state->aitems + 7) / 8);
}
/* nitems */
@@ -1974,11 +1341,11 @@ array_agg_array_serialize(PG_FUNCTION_ARGS)
/* ndims */
pq_sendint32(&buf, state->ndims);
- /* dims */
- pq_sendbytes(&buf, (char *) state->dims, state->ndims * sizeof(int));
+ /* dims: XXX should we just send ndims elements? */
+ pq_sendbytes(&buf, state->dims, sizeof(state->dims));
/* lbs */
- pq_sendbytes(&buf, (char *) state->lbs, state->ndims * sizeof(int));
+ pq_sendbytes(&buf, state->lbs, sizeof(state->lbs));
result = pq_endtypsend(&buf);
@@ -2010,13 +1377,13 @@ array_agg_array_deserialize(PG_FUNCTION_ARGS)
VARDATA_ANY(sstate),
VARSIZE_ANY_EXHDR(sstate));
/* element_type */
- element_type = pq_getmsgint(&buf, sizeof(Oid));
+ element_type = pq_getmsgint(&buf, 4);
/* array_type */
- array_type = pq_getmsgint(&buf, sizeof(Oid));
+ array_type = pq_getmsgint(&buf, 4);
/* nbytes */
- nbytes = pq_getmsgint(&buf, sizeof(int));
+ nbytes = pq_getmsgint(&buf, 4);
result = initArrayResultArr(array_type, element_type,
CurrentMemoryContext, false);
@@ -2033,10 +1400,10 @@ array_agg_array_deserialize(PG_FUNCTION_ARGS)
result->nbytes = nbytes;
/* abytes */
- result->abytes = pq_getmsgint(&buf, sizeof(int));
+ result->abytes = pq_getmsgint(&buf, 4);
/* aitems: might be 0 */
- result->aitems = pq_getmsgint(&buf, sizeof(int));
+ result->aitems = pq_getmsgint(&buf, 4);
/* nullbitmap */
if (result->aitems > 0)
@@ -2051,18 +1418,18 @@ array_agg_array_deserialize(PG_FUNCTION_ARGS)
result->nullbitmap = NULL;
/* nitems */
- result->nitems = pq_getmsgint(&buf, sizeof(int));
+ result->nitems = pq_getmsgint(&buf, 4);
/* ndims */
- result->ndims = pq_getmsgint(&buf, sizeof(int));
+ result->ndims = pq_getmsgint(&buf, 4);
/* dims */
- temp = pq_getmsgbytes(&buf, result->ndims * sizeof(int));
- memcpy(result->dims, temp, result->ndims * sizeof(int));
+ temp = pq_getmsgbytes(&buf, sizeof(result->dims));
+ memcpy(result->dims, temp, sizeof(result->dims));
/* lbs */
- temp = pq_getmsgbytes(&buf, result->ndims * sizeof(int));
- memcpy(result->lbs, temp, result->ndims * sizeof(int));
+ temp = pq_getmsgbytes(&buf, sizeof(result->lbs));
+ memcpy(result->lbs, temp, sizeof(result->lbs));
pq_getmsgend(&buf);
pfree(buf.data);
@@ -2070,6 +1437,30 @@ array_agg_array_deserialize(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(result);
}
+Datum
+array_agg_array_finalfn(PG_FUNCTION_ARGS)
+{
+ Datum result;
+ ArrayBuildStateArr *state;
+
+ /* cannot be called directly because of internal-type argument */
+ Assert(AggCheckCallContext(fcinfo, NULL));
+
+ state = PG_ARGISNULL(0) ? NULL : (ArrayBuildStateArr *)
PG_GETARG_POINTER(0);
+
+ if (state == NULL)
+ PG_RETURN_NULL(); /* returns null iff no input
values */
+
+ /*
+ * Make the result. We cannot release the ArrayBuildStateArr because
+ * sometimes aggregate final functions are re-executed. Rather, it is
+ * nodeAgg.c's responsibility to reset the aggcontext when it's safe to
do
+ * so.
+ */
+ result = makeArrayResultArr(state, CurrentMemoryContext, false);
+
+ PG_RETURN_DATUM(result);
+}
/*-----------------------------------------------------------------------------
* array_position, array_position_start :
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index c4a528d0764..851a61aaed7 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -29,14 +29,14 @@
#include "miscadmin.h"
#include "storage/fd.h"
#include "utils/acl.h"
+#include "utils/array.h"
#include "utils/builtins.h"
-#include "utils/int8.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/numeric.h"
#include "utils/rel.h"
#include "utils/relcache.h"
-#include "utils/relfilenodemap.h"
+#include "utils/relfilenumbermap.h"
#include "utils/relmapper.h"
#include "utils/syscache.h"
@@ -490,7 +490,7 @@ pg_tablespace_size_name(PG_FUNCTION_ARGS)
* is no check here or at the call sites for that.
*/
static int64
-calculate_relation_size(RelFileLocator *rfn, BackendId backend, ForkNumber
forknum)
+calculate_relation_size(Relation rel, ForkNumber forknum)
{
int64 totalsize = 0;
char *relationpath;
@@ -507,7 +507,7 @@ calculate_relation_size(RelFileLocator *rfn, BackendId
backend, ForkNumber forkn
if (RelationIsNonblockRelation(rel))
return table_relation_size(rel, forknum);
- relationpath = relpathbackend(rel->rd_node, rel->rd_backend, forknum);
+ relationpath = relpathbackend(rel->rd_locator, rel->rd_backend,
forknum);
/* Ordinary relation, including heap and index.
* They take form of relationpath, or relationpath.%d
@@ -624,8 +624,7 @@ calculate_toast_table_size(Oid toastrelid)
/* toast heap size, including FSM and VM size */
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
- size += calculate_relation_size(&(toastRel->rd_locator),
-
toastRel->rd_backend, forkNum);
+ size += calculate_relation_size(toastRel, forkNum);
/* toast index size, including FSM and VM size */
indexlist = RelationGetIndexList(toastRel);
@@ -638,8 +637,7 @@ calculate_toast_table_size(Oid toastrelid)
toastIdxRel = relation_open(lfirst_oid(lc),
AccessShareLock);
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
- size +=
calculate_relation_size(&(toastIdxRel->rd_locator),
-
toastIdxRel->rd_backend, forkNum);
+ size += calculate_relation_size(toastIdxRel, forkNum);
relation_close(toastIdxRel, AccessShareLock);
}
@@ -673,7 +671,7 @@ calculate_table_size(Relation rel)
if (rel->rd_locator.relNumber != 0)
{
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
- size += calculate_relation_size(rel, rel->rd_backend,
forkNum);
+ size += calculate_relation_size(rel, forkNum);
}
/*
@@ -745,8 +743,7 @@ calculate_indexes_size(Relation rel)
if (RelationIsValid(idxRel))
{
for (forkNum = 0; forkNum <= MAX_FORKNUM;
forkNum++)
- size +=
calculate_relation_size(&(idxRel->rd_locator),
-
idxRel->rd_backend,
+ size += calculate_relation_size(idxRel,
forkNum);
relation_close(idxRel, AccessShareLock);
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c
index 36b94bf121f..e378a9419ad 100644
--- a/src/backend/utils/adt/genfile.c
+++ b/src/backend/utils/adt/genfile.c
@@ -1032,6 +1032,7 @@ pg_logdir_ls_internal(FunctionCallInfo fcinfo)
fsec_t fsec;
int tz = 0;
struct pg_tm date;
+ DateTimeErrorExtra extra;
if (prefix_is_gpdb)
{
@@ -1067,7 +1068,7 @@ pg_logdir_ls_internal(FunctionCallInfo fcinfo)
if (ParseDateTime(timestampbuf, lowstr, MAXDATELEN, field,
ftype, MAXDATEFIELDS, &nf))
continue;
- if (DecodeDateTime(field, ftype, nf, &dtype, &date, &fsec, &tz))
+ if (DecodeDateTime(field, ftype, nf, &dtype, &date, &fsec, &tz,
&extra))
continue;
/* Seems the timestamp is OK; prepare and return tuple */
diff --git a/src/backend/utils/adt/gp_dump_oids.c
b/src/backend/utils/adt/gp_dump_oids.c
index ae4a13311b1..2dd0da6d57c 100644
--- a/src/backend/utils/adt/gp_dump_oids.c
+++ b/src/backend/utils/adt/gp_dump_oids.c
@@ -234,7 +234,7 @@ gp_dump_query_oids(PG_FUNCTION_ARGS)
List *queryTree_sublist;
- Query *query = parse_analyze(parsetree, sqlText, NULL, 0,
NULL);
+ Query *query = parse_analyze_varparams(parsetree, sqlText,
NULL, 0, NULL);
query->expandMatViews = true;
queryTree_sublist = pg_rewrite_query(query);
diff --git a/src/backend/utils/adt/lockfuncs.c
b/src/backend/utils/adt/lockfuncs.c
index 72c770a72c7..3230962ba5f 100644
--- a/src/backend/utils/adt/lockfuncs.c
+++ b/src/backend/utils/adt/lockfuncs.c
@@ -44,7 +44,7 @@ const char *const LockTagTypeNames[] = {
"distributed xid",
"userlock",
"advisory",
- "applytransaction"
+ "applytransaction",
"warehouse"
};
diff --git a/src/backend/utils/adt/mcxtfuncs.c
b/src/backend/utils/adt/mcxtfuncs.c
index a9b734b197d..2b474e6ffd3 100644
--- a/src/backend/utils/adt/mcxtfuncs.c
+++ b/src/backend/utils/adt/mcxtfuncs.c
@@ -286,7 +286,8 @@ gp_log_backend_memory_contexts(PG_FUNCTION_ARGS)
struct pg_result *pgresult =
cdb_pgresults.pg_results[resultno];
if (PQresultStatus(pgresult) == PGRES_TUPLES_OK)
{
- int retValue = pg_atoi(PQgetvalue(pgresult, 0,
0), sizeof(int), 0);
+ char *endp;
+ int retValue = strtol(PQgetvalue(pgresult, 0,
0), &endp, 10);
if (retValue !=
ERROR_DISPATCHING_LOG_MEMORY_CONTEXT)
returnedSegments =
lappend_int(returnedSegments, retValue);
}
@@ -328,7 +329,7 @@ gp_log_backend_memory_contexts(PG_FUNCTION_ARGS)
int logsSignalled = 0;
for (int beid = 1; beid <= tot_backends; beid++)
{
- PgBackendStatus *beentry =
pgstat_fetch_stat_beentry(beid);
+ PgBackendStatus *beentry =
pgstat_get_beentry_by_backend_id(beid);
if (beentry && beentry->st_procpid >0 &&
beentry->st_session_id == targetSessionId)
{
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 699b9a14829..042c910f394 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -379,7 +379,7 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
Datum
get_tablespace_version_directory_name(PG_FUNCTION_ARGS)
{
- PG_RETURN_TEXT_P(CStringGetTextDatum(GP_TABLESPACE_VERSION_DIRECTORY));
+ PG_RETURN_TEXT_P(GP_TABLESPACE_VERSION_DIRECTORY);
}
/*
@@ -1094,7 +1094,7 @@ gp_get_segment_configuration(PG_FUNCTION_ARGS)
{
#ifdef USE_INTERNAL_FTS
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("Should not call this function when using internal fts
module")));
+ errmsg("Should not call this function when using
internal fts module")));
#else
GpSegConfigEntryForUDF * config_for_udf;
@@ -1184,6 +1184,7 @@ gp_get_segment_configuration(PG_FUNCTION_ARGS)
SRF_RETURN_DONE(funcctx);
}
#endif
+}
/*
* Transition function for the ANY_VALUE aggregate
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 172fa780d55..d8ed0a0c0c7 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -40,7 +40,6 @@
#include "utils/builtins.h"
#include "utils/float.h"
#include "utils/guc.h"
-#include "utils/int8.h"
#include "utils/memutils.h"
#include "utils/numeric.h"
#include "utils/pg_lsn.h"
@@ -272,9 +271,8 @@ static void dump_var(const char *str, NumericVar *var);
(weight) <= NUMERIC_SHORT_WEIGHT_MAX && \
(weight) >= NUMERIC_SHORT_WEIGHT_MIN)
-static bool set_var_from_str(const char *str, const char *cp,
- NumericVar *dest,
const char **endptr,
- Node *escontext);
+#define NUMERIC_WEIGHT_MAX PG_INT16_MAX
+
static bool set_var_from_non_decimal_integer_str(const char *str,
const char *cp, int sign,
int base, NumericVar *dest,
@@ -285,7 +283,6 @@ static void numericvar_serialize(StringInfo buf, const
NumericVar *var);
static void numericvar_deserialize(StringInfo buf, NumericVar *var);
static Numeric duplicate_numeric(Numeric num);
-static Numeric make_result(const NumericVar *var);
static Numeric make_result_opt_error(const NumericVar *var, bool *have_error);
static bool apply_typmod(NumericVar *var, int32 typmod, Node *escontext);
@@ -521,7 +518,7 @@ numeric_in(PG_FUNCTION_ARGS)
/* Parse the rest of the number and apply the sign */
if (base == 10)
{
- if (!set_var_from_str(str, cp, &value, &cp, escontext))
+ if (!init_var_from_str(str, cp, &value, &cp, escontext))
PG_RETURN_NULL();
value.sign = sign;
}
@@ -4094,6 +4091,8 @@ Numeric
numeric_li_value(float8 f, Numeric y0, Numeric y1)
{
Numeric y;
+ Node *escontext = NULL;
+ const char *cp;
if ( NUMERIC_IS_NAN(y0) || NUMERIC_IS_NAN(y1) || isnan(f) )
{
@@ -4114,7 +4113,7 @@ numeric_li_value(float8 f, Numeric y0, Numeric y1)
snprintf(buf, sizeof(buf), "%.*g", DBL_DIG, f);
/* Assume we need not worry about leading/trailing spaces */
- (void) init_var_from_str(buf, buf, &vf);
+ (void) init_var_from_str(buf, buf, &vf, &cp, escontext);
mul_var(&vf, &v1, &v1, vf.dscale + v1.dscale);
add_var(&v0, &v1, &v1);
@@ -4597,7 +4596,8 @@ float8_numeric(PG_FUNCTION_ARGS)
Numeric res;
NumericVar result;
char buf[DBL_DIG + 100];
- const char *endptr;
+ Node *escontext = fcinfo->context;
+ const char *cp;
if (isnan(val))
PG_RETURN_NUMERIC(make_numeric_result(&const_nan));
@@ -4613,7 +4613,7 @@ float8_numeric(PG_FUNCTION_ARGS)
snprintf(buf, sizeof(buf), "%.*g", DBL_DIG, val);
/* Assume we need not worry about leading/trailing spaces */
- (void) init_var_from_str(buf, buf, &result);
+ (void) init_var_from_str(buf, buf, &result, &cp, escontext);
res = make_numeric_result(&result);
@@ -4702,7 +4702,8 @@ float4_numeric(PG_FUNCTION_ARGS)
Numeric res;
NumericVar result;
char buf[FLT_DIG + 100];
- const char *endptr;
+ Node *escontext = fcinfo->context;
+ const char *cp;
if (isnan(val))
PG_RETURN_NUMERIC(make_numeric_result(&const_nan));
@@ -4718,7 +4719,7 @@ float4_numeric(PG_FUNCTION_ARGS)
snprintf(buf, sizeof(buf), "%.*g", FLT_DIG, val);
/* Assume we need not worry about leading/trailing spaces */
- (void) init_var_from_str(buf, buf, &result);
+ (void) init_var_from_str(buf, buf, &result, &cp, escontext);
res = make_numeric_result(&result);
@@ -7048,6 +7049,25 @@ zero_numeric_var(NumericVar *var)
}
+/*
+ * zero_var() -
+ *
+ * Set a variable to ZERO.
+ * Note: its dscale is not touched.
+ */
+static void
+zero_var(NumericVar *var)
+{
+ digitbuf_free(var);
+ var->buf = NULL;
+ var->digits = NULL;
+ var->ndigits = 0;
+ var->weight = 0; /* by convention; doesn't
really matter */
+ var->sign = NUMERIC_POS; /* anything but NAN... */
+}
+
+
+
/*
* init_var_from_str()
*
@@ -7063,7 +7083,7 @@ zero_numeric_var(NumericVar *var)
* Returns true on success, false on failure (if escontext points to an
* ErrorSaveContext; otherwise errors are thrown).
*/
-const char *
+const bool
init_var_from_str(const char *str, const char *cp, NumericVar *dest, const
char **endptr,
Node *escontext)
{
@@ -7835,7 +7855,7 @@ numericvar_deserialize(StringInfo buf, NumericVar *var)
len = pq_getmsgint(buf, sizeof(int32));
- alloc_var(var, len); /* sets var->ndigits */
+ init_alloc_var(var, len); /* sets var->ndigits */
var->weight = pq_getmsgint(buf, sizeof(int32));
var->sign = pq_getmsgint(buf, sizeof(int32));
@@ -9795,7 +9815,7 @@ div_var_int(const NumericVar *var, int ival, int
ival_weight,
}
/* Store the quotient in result */
- digitbuf_free(result->buf);
+ digitbuf_free(result);
result->ndigits = res_ndigits;
result->buf = res_buf;
result->digits = res_digits;
@@ -9911,7 +9931,7 @@ div_var_int64(const NumericVar *var, int64 ival, int
ival_weight,
}
/* Store the quotient in result */
- digitbuf_free(result->buf);
+ digitbuf_free(result);
result->ndigits = res_ndigits;
result->buf = res_buf;
result->digits = res_digits;
diff --git a/src/backend/utils/adt/pg_upgrade_support.c
b/src/backend/utils/adt/pg_upgrade_support.c
index 31c63429f4f..d748354e38f 100644
--- a/src/backend/utils/adt/pg_upgrade_support.c
+++ b/src/backend/utils/adt/pg_upgrade_support.c
@@ -23,6 +23,7 @@
#include "catalog/pg_type.h"
#include "cdb/cdbvars.h"
#include "commands/extension.h"
+#include "commands/tablespace.h"
#include "miscadmin.h"
#include "utils/array.h"
#include "utils/builtins.h"
@@ -119,6 +120,7 @@ binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
PG_RETURN_VOID();
}
+extern RelFileNumber binary_upgrade_next_heap_pg_class_relfilenumber;
Datum
binary_upgrade_set_next_heap_relfilenode(PG_FUNCTION_ARGS)
{
@@ -144,6 +146,7 @@ binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
PG_RETURN_VOID();
}
+extern RelFileNumber binary_upgrade_next_index_pg_class_relfilenumber;
Datum
binary_upgrade_set_next_index_relfilenode(PG_FUNCTION_ARGS)
{
@@ -169,6 +172,7 @@ binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
PG_RETURN_VOID();
}
+extern RelFileNumber binary_upgrade_next_toast_pg_class_relfilenumber;
Datum
binary_upgrade_set_next_toast_relfilenode(PG_FUNCTION_ARGS)
{
diff --git a/src/backend/utils/adt/pgstatfuncs.c
b/src/backend/utils/adt/pgstatfuncs.c
index 6c102945c5f..c1814e31259 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -732,7 +732,7 @@ pg_stat_get_backend_session_id(PG_FUNCTION_ARGS)
int32 beid = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
- if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
+ if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
PG_RETURN_NULL();
PG_RETURN_INT32(beentry->st_session_id);
diff --git a/src/backend/utils/adt/rowtypes.c b/src/backend/utils/adt/rowtypes.c
index 7844da6ada3..3250d285e02 100644
--- a/src/backend/utils/adt/rowtypes.c
+++ b/src/backend/utils/adt/rowtypes.c
@@ -188,7 +188,6 @@ record_in(PG_FUNCTION_ARGS)
{
ReleaseTupleDesc(tupdesc);
/* *ptr must be ')' */
- {
errsave(escontext,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed record
literal: \"%s\"", string),
diff --git a/src/backend/utils/adt/ruleutils.c
b/src/backend/utils/adt/ruleutils.c
index 116c01341a6..f2f1effe7e7 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -411,12 +411,12 @@ static void get_query_def(Query *query, StringInfo buf,
List *parentnamespace,
static void get_values_def(List *values_lists, deparse_context *context);
static void get_with_clause(Query *query, deparse_context *context);
static void get_select_query_def(Query *query, deparse_context *context);
-static void get_insert_query_def(Query *query, deparse_context *context);
-static void get_update_query_def(Query *query, deparse_context *context);
+static void get_insert_query_def(Query *query, deparse_context *context, bool
colNamesVisible);
+static void get_update_query_def(Query *query, deparse_context *context, bool
colNamesVisible);
static void get_update_query_targetlist_def(Query *query, List *targetList,
deparse_context *context,
RangeTblEntry *rte);
-static void get_delete_query_def(Query *query, deparse_context *context);
+static void get_delete_query_def(Query *query, deparse_context *context, bool
colNamesVisible);
static void get_merge_query_def(Query *query, deparse_context *context);
static void get_utility_query_def(Query *query, deparse_context *context);
static void get_basic_select_query(Query *query, deparse_context *context);
@@ -2719,7 +2719,7 @@ pg_get_expr_worker(text *expr, Oid relid, int prettyFlags)
*/
if (OidIsValid(relid))
{
- rel = try_relation_open(relid, AccessShareLock);
+ rel = try_relation_open(relid, AccessShareLock, false);
if (rel == NULL)
return NULL;
context = deparse_context_for(RelationGetRelationName(rel),
relid);
@@ -6099,7 +6099,7 @@ get_basic_select_query(Query *query, deparse_context
*context)
appendStringInfoString(buf, ",");
appendStringInfo(buf, " %s AS ",
quote_identifier(wc->name));
- get_rule_windowspec(wc, context->windowTList, context);
+ get_rule_windowspec(wc, context->targetList, context);
}
}
}
@@ -11781,54 +11781,7 @@ get_from_clause_item(Node *jtnode, Query *query,
deparse_context *context)
}
/* Print the relation alias, if needed */
- printalias = false;
- if (rte->alias != NULL)
- {
- /* Always print alias if user provided one */
- printalias = true;
- }
- else if (colinfo->printaliases)
- {
- /* Always print alias if we need to print column
aliases */
- printalias = true;
- }
- else if (rte->rtekind == RTE_RELATION)
- {
- /*
- * No need to print alias if it's same as relation name
(this
- * would normally be the case, but not if
set_rtable_names had to
- * resolve a conflict).
- */
- if (strcmp(refname, get_relation_name(rte->relid)) != 0)
- printalias = true;
- }
- else if (rte->rtekind == RTE_FUNCTION || rte->rtekind ==
RTE_TABLEFUNCTION)
- {
- /*
- * For a function RTE, always print alias. This covers
possible
- * renaming of the function and/or instability of the
- * FigureColname rules for things that aren't simple
functions.
- * Note we'd need to force it anyway for the columndef
list case.
- */
- printalias = true;
- }
- else if (rte->rtekind == RTE_VALUES)
- {
- /* Alias is syntactically required for VALUES */
- printalias = true;
- }
- else if (rte->rtekind == RTE_CTE)
- {
- /*
- * No need to print alias if it's same as CTE name
(this would
- * normally be the case, but not if set_rtable_names
had to
- * resolve a conflict).
- */
- if (strcmp(refname, rte->ctename) != 0)
- printalias = true;
- }
- if (printalias)
- appendStringInfo(buf, " %s", quote_identifier(refname));
+ get_rte_alias(rte, varno, false, context);
/* Print the column definitions or aliases, if needed */
if (rtfunc1 && rtfunc1->funccolnames != NIL)
diff --git a/src/backend/utils/adt/timestamp.c
b/src/backend/utils/adt/timestamp.c
index b33b115b8d3..da9973de37f 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -4451,10 +4451,9 @@ timestamp_age(PG_FUNCTION_ARGS)
Timestamp dt1 = PG_GETARG_TIMESTAMP(0);
Timestamp dt2 = PG_GETARG_TIMESTAMP(1);
Interval *result;
- fsec_t fsec,
- fsec1 = 0,
+ fsec_t fsec1 = 0,
fsec2 = 0;
- struct pg_tm tt,
+ struct pg_itm tt,
*tm = &tt;
struct pg_tm tt1,
*tm1 = &tt1;
@@ -4828,8 +4827,15 @@ timestamp_bin(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("stride must be greater than zero")));
- tm_diff = timestamp - origin;
- tm_delta = tm_diff - tm_diff % stride_usecs;
+ if (unlikely(pg_sub_s64_overflow(timestamp, origin, &tm_diff)))
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("interval out of range")));
+
+ /* These calculations cannot overflow */
+ tm_modulo = tm_diff % stride_usecs;
+ tm_delta = tm_diff - tm_modulo;
+ result = origin + tm_delta;
/*
* We want to round towards -infinity, not 0, when tm_diff is negative
and
@@ -5021,8 +5027,15 @@ timestamptz_bin(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("stride must be greater than zero")));
- tm_diff = timestamp - origin;
- tm_delta = tm_diff - tm_diff % stride_usecs;
+ if (unlikely(pg_sub_s64_overflow(timestamp, origin, &tm_diff)))
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("interval out of range")));
+
+ /* These calculations cannot overflow */
+ tm_modulo = tm_diff % stride_usecs;
+ tm_delta = tm_diff - tm_modulo;
+ result = origin + tm_delta;
/*
* We want to round towards -infinity, not 0, when tm_diff is negative
and
diff --git a/src/backend/utils/adt/xid8funcs.c
b/src/backend/utils/adt/xid8funcs.c
index 62e461bfc90..254803a294c 100644
--- a/src/backend/utils/adt/xid8funcs.c
+++ b/src/backend/utils/adt/xid8funcs.c
@@ -361,7 +361,7 @@ bad_format:
pg_snapshot*
deserialize_snapshot(const char *str)
{
- return parse_snapshot(str);
+ return parse_snapshot(str, NULL);
}
/*
diff --git a/src/include/commands/tablespace.h
b/src/include/commands/tablespace.h
index 27465bec611..8a0cfe4726f 100644
--- a/src/include/commands/tablespace.h
+++ b/src/include/commands/tablespace.h
@@ -21,6 +21,7 @@
#include "storage/dbdirnode.h"
extern PGDLLIMPORT bool allow_in_place_tablespaces;
+extern Oid binary_upgrade_next_pg_tablespace_oid;
/* XLOG stuff */
#define XLOG_TBLSPC_CREATE 0x00
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index c2721530842..cb309ede6ae 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -93,8 +93,8 @@ extern void generate_operator_clause(fmStringInfo buf,
/* varchar.c */
extern int bpchartruelen(char *s, int len);
-extern BpChar *bpchar_input(const char *s, size_t len, int32 atttypmod);
-extern VarChar *varchar_input(const char *s, size_t len, int32 atttypmod);
+extern BpChar *bpchar_input(const char *s, size_t len, int32 atttypmod, Node
*escontext);
+extern VarChar *varchar_input(const char *s, size_t len, int32 atttypmod, Node
*escontext);
/* popular functions from varlena.c */
extern text *cstring_to_text(const char *s);
diff --git a/src/include/utils/numeric.h b/src/include/utils/numeric.h
index 28a222fa6c4..494972d5c6d 100644
--- a/src/include/utils/numeric.h
+++ b/src/include/utils/numeric.h
@@ -316,7 +316,8 @@ extern void free_numeric_var(NumericVar *var);
extern void alloc_numeric_var(NumericVar *var, int ndigits);
extern void zero_numeric_var(NumericVar *var);
-extern const char *init_var_from_str(const char *str, const char *cp,
NumericVar *dest);
+extern const bool init_var_from_str(const char *str, const char *cp,
NumericVar *dest, const char **endptr,
+ Node
*escontext);
extern void init_var_from_var(const NumericVar *value, NumericVar *dest);
extern void init_ro_var_from_var(const NumericVar *value, NumericVar *dest);
extern void set_var_from_num(Numeric value, NumericVar *dest);
diff --git a/src/test/regress/regress_gp.c b/src/test/regress/regress_gp.c
index b8ca83c662c..d1e93409e91 100644
--- a/src/test/regress/regress_gp.c
+++ b/src/test/regress/regress_gp.c
@@ -1130,7 +1130,7 @@ hasBackendsExist(PG_FUNCTION_ARGS)
int tot_backends = pgstat_fetch_stat_numbackends();
for (beid = 1; beid <= tot_backends; beid++)
{
- PgBackendStatus *beentry =
pgstat_fetch_stat_beentry(beid);
+ PgBackendStatus *beentry =
pgstat_get_beentry_by_backend_id(beid);
if (beentry && beentry->st_procpid >0 &&
beentry->st_procpid != pid &&
beentry->st_session_id == gp_session_id)
result++;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]