Fix compiling against pg12

fix_120_custom_aggregates_distribute_multiarg
Philip Dubé 2019-08-29 01:45:35 +00:00
parent 17ed25e09a
commit 22c6dc7f84
2 changed files with 47 additions and 60 deletions

View File

@ -4,10 +4,12 @@
#include "catalog/pg_aggregate.h" #include "catalog/pg_aggregate.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "distributed/version_compat.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "fmgr.h" #include "fmgr.h"
#include "pg_config_manual.h"
PG_FUNCTION_INFO_V1(citus_stype_serialize); PG_FUNCTION_INFO_V1(citus_stype_serialize);
PG_FUNCTION_INFO_V1(citus_stype_deserialize); PG_FUNCTION_INFO_V1(citus_stype_deserialize);
@ -105,8 +107,7 @@ InitializeStypeBox(StypeBox *box, HeapTuple aggTuple, Oid transtype)
Datum Datum
citus_stype_serialize(PG_FUNCTION_ARGS) citus_stype_serialize(PG_FUNCTION_ARGS)
{ {
FunctionCallInfoData inner_fcinfodata; LOCAL_FCINFO(inner_fcinfo, 1);
FunctionCallInfo inner_fcinfo = &inner_fcinfodata;
FmgrInfo infodata; FmgrInfo infodata;
FmgrInfo *info = &infodata; FmgrInfo *info = &infodata;
StypeBox *box = (StypeBox *) PG_GETARG_POINTER(0); StypeBox *box = (StypeBox *) PG_GETARG_POINTER(0);
@ -150,8 +151,7 @@ citus_stype_serialize(PG_FUNCTION_ARGS)
{ {
InitFunctionCallInfoData(*inner_fcinfo, info, 1, fcinfo->fncollation, InitFunctionCallInfoData(*inner_fcinfo, info, 1, fcinfo->fncollation,
fcinfo->context, fcinfo->resultinfo); fcinfo->context, fcinfo->resultinfo);
inner_fcinfo->arg[0] = box->value; fcSetArgExt(inner_fcinfo, 0, box->value, box->value_null);
inner_fcinfo->argnull[0] = box->value_null;
result = FunctionCallInvoke(inner_fcinfo); result = FunctionCallInvoke(inner_fcinfo);
if (inner_fcinfo->isnull) if (inner_fcinfo->isnull)
{ {
@ -229,21 +229,19 @@ citus_stype_deserialize(PG_FUNCTION_ARGS)
if (deserial != InvalidOid) if (deserial != InvalidOid)
{ {
FmgrInfo fdeserialinfo; FmgrInfo fdeserialinfo;
FunctionCallInfoData fdeserial_callinfodata; LOCAL_FCINFO(fdeserial_callinfo, 2);
inner_bytes = PG_GETARG_BYTEA_P_SLICE(0, sizeof(Oid), VARSIZE(bytes) - inner_bytes = PG_GETARG_BYTEA_P_SLICE(0, sizeof(Oid), VARSIZE(bytes) -
sizeof(Oid)); sizeof(Oid));
elog(WARNING, "deserial %d", VARSIZE(inner_bytes)); elog(WARNING, "deserial %d", VARSIZE(inner_bytes));
fmgr_info(deserial, &fdeserialinfo); fmgr_info(deserial, &fdeserialinfo);
InitFunctionCallInfoData(fdeserial_callinfodata, &fdeserialinfo, 2, InitFunctionCallInfoData(*fdeserial_callinfo, &fdeserialinfo, 2,
fcinfo->fncollation, fcinfo->context, fcinfo->fncollation, fcinfo->context,
fcinfo->resultinfo); fcinfo->resultinfo);
fdeserial_callinfodata.arg[0] = PointerGetDatum(inner_bytes); fcSetArg(fdeserial_callinfo, 0, PointerGetDatum(inner_bytes));
fdeserial_callinfodata.argnull[0] = false; fcSetArg(fdeserial_callinfo, 1, PG_GETARG_DATUM(1));
fdeserial_callinfodata.arg[1] = PG_GETARG_DATUM(1); box->value = FunctionCallInvoke(fdeserial_callinfo);
fdeserial_callinfodata.argnull[1] = false; box->value_null = fdeserial_callinfo->isnull;
box->value = FunctionCallInvoke(&fdeserial_callinfodata);
box->value_null = fdeserial_callinfodata.isnull;
} }
/* TODO Correct null handling */ /* TODO Correct null handling */
@ -281,8 +279,7 @@ citus_stype_combine(PG_FUNCTION_ARGS)
{ {
StypeBox *box1 = NULL; StypeBox *box1 = NULL;
StypeBox *box2 = NULL; StypeBox *box2 = NULL;
FunctionCallInfoData inner_fcinfodata; LOCAL_FCINFO(inner_fcinfo, 2);
FunctionCallInfo inner_fcinfo = &inner_fcinfodata;
FmgrInfo info; FmgrInfo info;
Oid combine; Oid combine;
HeapTuple aggtuple; HeapTuple aggtuple;
@ -336,10 +333,8 @@ citus_stype_combine(PG_FUNCTION_ARGS)
InitFunctionCallInfoData(*inner_fcinfo, &info, 2, fcinfo->fncollation, InitFunctionCallInfoData(*inner_fcinfo, &info, 2, fcinfo->fncollation,
fcinfo->context, fcinfo->resultinfo); fcinfo->context, fcinfo->resultinfo);
inner_fcinfo->arg[0] = box1->value; fcSetArgExt(inner_fcinfo, 0, box1->value, box1->value_null);
inner_fcinfo->argnull[0] = box1->value_null; fcSetArgExt(inner_fcinfo, 1, box2->value, box2->value_null);
inner_fcinfo->arg[1] = box2->value;
inner_fcinfo->argnull[1] = box2->value_null;
/* TODO Deal with memory management juggling (see executor/nodeAgg) */ /* TODO Deal with memory management juggling (see executor/nodeAgg) */
box1->value = FunctionCallInvoke(inner_fcinfo); box1->value = FunctionCallInvoke(inner_fcinfo);
@ -362,8 +357,7 @@ worker_partial_agg_sfunc(PG_FUNCTION_ARGS)
Form_pg_aggregate aggform; Form_pg_aggregate aggform;
HeapTuple aggtuple; HeapTuple aggtuple;
Oid aggsfunc; Oid aggsfunc;
FunctionCallInfoData inner_fcinfodata; LOCAL_FCINFO(inner_fcinfo, FUNC_MAX_ARGS);
FunctionCallInfo inner_fcinfo = &inner_fcinfodata;
FmgrInfo info; FmgrInfo info;
int i; int i;
bool is_initial_call = PG_ARGISNULL(0); bool is_initial_call = PG_ARGISNULL(0);
@ -411,13 +405,13 @@ worker_partial_agg_sfunc(PG_FUNCTION_ARGS)
} }
} }
/* Deal with memory management juggling (see executor/nodeAgg) */ /* TODO Deal with memory management juggling (see executor/nodeAgg) */
inner_fcinfo->arg[0] = box->value; fcSetArgExt(inner_fcinfo, 0, box->value, box->value_null);
inner_fcinfo->argnull[0] = box->value_null; for (i = 1; i < inner_fcinfo->nargs; i++)
memcpy(&inner_fcinfo->arg[1], &fcinfo->arg[2], sizeof(Datum) * (inner_fcinfo->nargs - {
1)); fcSetArgExt(inner_fcinfo, i, fcGetArgValue(fcinfo, i + 1), fcGetArgNull(fcinfo,
memcpy(&inner_fcinfo->argnull[1], &fcinfo->argnull[2], sizeof(bool) * i + 1));
(inner_fcinfo->nargs - 1)); }
box->value = FunctionCallInvoke(inner_fcinfo); box->value = FunctionCallInvoke(inner_fcinfo);
box->value_null = inner_fcinfo->isnull; box->value_null = inner_fcinfo->isnull;
@ -434,8 +428,7 @@ worker_partial_agg_sfunc(PG_FUNCTION_ARGS)
Datum Datum
worker_partial_agg_ffunc(PG_FUNCTION_ARGS) worker_partial_agg_ffunc(PG_FUNCTION_ARGS)
{ {
FunctionCallInfoData inner_fcinfodata; LOCAL_FCINFO(inner_fcinfo, 1);
FunctionCallInfo inner_fcinfo = &inner_fcinfodata;
FmgrInfo info; FmgrInfo info;
StypeBox *box = (StypeBox *) PG_GETARG_POINTER(0); StypeBox *box = (StypeBox *) PG_GETARG_POINTER(0);
HeapTuple aggtuple; HeapTuple aggtuple;
@ -477,8 +470,7 @@ worker_partial_agg_ffunc(PG_FUNCTION_ARGS)
} }
InitFunctionCallInfoData(*inner_fcinfo, &info, 1, fcinfo->fncollation, InitFunctionCallInfoData(*inner_fcinfo, &info, 1, fcinfo->fncollation,
fcinfo->context, fcinfo->resultinfo); fcinfo->context, fcinfo->resultinfo);
inner_fcinfo->arg[0] = box->value; fcSetArgExt(inner_fcinfo, 0, box->value, box->value_null);
inner_fcinfo->argnull[0] = box->value_null;
result = FunctionCallInvoke(inner_fcinfo); result = FunctionCallInvoke(inner_fcinfo);
elog(WARNING, "& done %d", VARSIZE(DatumGetByteaPP(result))); elog(WARNING, "& done %d", VARSIZE(DatumGetByteaPP(result)));
if (inner_fcinfo->isnull) if (inner_fcinfo->isnull)
@ -498,8 +490,7 @@ worker_partial_agg_ffunc(PG_FUNCTION_ARGS)
Datum Datum
coord_combine_agg_sfunc(PG_FUNCTION_ARGS) coord_combine_agg_sfunc(PG_FUNCTION_ARGS)
{ {
FunctionCallInfoData inner_fcinfodata; LOCAL_FCINFO(inner_fcinfo, 3);
FunctionCallInfo inner_fcinfo = &inner_fcinfodata;
FmgrInfo info; FmgrInfo info;
HeapTuple aggtuple; HeapTuple aggtuple;
HeapTuple transtypetuple; HeapTuple transtypetuple;
@ -544,10 +535,9 @@ coord_combine_agg_sfunc(PG_FUNCTION_ARGS)
{ {
InitFunctionCallInfoData(*inner_fcinfo, &info, 2, fcinfo->fncollation, InitFunctionCallInfoData(*inner_fcinfo, &info, 2, fcinfo->fncollation,
fcinfo->context, fcinfo->resultinfo); fcinfo->context, fcinfo->resultinfo);
inner_fcinfo->arg[0] = value_null ? (Datum) 0 : PG_GETARG_DATUM(2); fcSetArgExt(inner_fcinfo, 0, value_null ? (Datum) 0 : PG_GETARG_DATUM(2),
inner_fcinfo->arg[1] = (Datum) 0; value_null);
inner_fcinfo->argnull[0] = value_null; fcSetArgNull(inner_fcinfo, 1);
inner_fcinfo->argnull[1] = true;
value = FunctionCallInvoke(inner_fcinfo); value = FunctionCallInvoke(inner_fcinfo);
value_null = inner_fcinfo->isnull; value_null = inner_fcinfo->isnull;
} }
@ -579,12 +569,10 @@ coord_combine_agg_sfunc(PG_FUNCTION_ARGS)
InitFunctionCallInfoData(*inner_fcinfo, &info, 3, fcinfo->fncollation, InitFunctionCallInfoData(*inner_fcinfo, &info, 3, fcinfo->fncollation,
fcinfo->context, fcinfo->resultinfo); fcinfo->context, fcinfo->resultinfo);
inner_fcinfo->arg[0] = PointerGetDatum(value_null ? NULL : &buf); fcSetArgExt(inner_fcinfo, 0, PointerGetDatum(value_null ? NULL : &buf),
inner_fcinfo->arg[1] = ObjectIdGetDatum(ioparam); value_null);
inner_fcinfo->arg[2] = Int32GetDatum(-1); /* typmod */ fcSetArg(inner_fcinfo, 1, ObjectIdGetDatum(ioparam));
inner_fcinfo->argnull[0] = value_null; fcSetArg(inner_fcinfo, 2, Int32GetDatum(-1)); /* typmod */
inner_fcinfo->argnull[1] = false;
inner_fcinfo->argnull[2] = false;
value = FunctionCallInvoke(inner_fcinfo); value = FunctionCallInvoke(inner_fcinfo);
value_null = inner_fcinfo->isnull; value_null = inner_fcinfo->isnull;
@ -620,10 +608,8 @@ coord_combine_agg_sfunc(PG_FUNCTION_ARGS)
elog(WARNING, "\tcombine %u", box->agg); elog(WARNING, "\tcombine %u", box->agg);
InitFunctionCallInfoData(*inner_fcinfo, &info, 2, fcinfo->fncollation, InitFunctionCallInfoData(*inner_fcinfo, &info, 2, fcinfo->fncollation,
fcinfo->context, fcinfo->resultinfo); fcinfo->context, fcinfo->resultinfo);
inner_fcinfo->arg[0] = box->value; fcSetArgExt(inner_fcinfo, 0, box->value, box->value_null);
inner_fcinfo->argnull[0] = box->value_null; fcSetArgExt(inner_fcinfo, 1, value, value_null);
inner_fcinfo->arg[1] = value;
inner_fcinfo->argnull[1] = value_null;
box->value = FunctionCallInvoke(inner_fcinfo); box->value = FunctionCallInvoke(inner_fcinfo);
box->value_null = inner_fcinfo->isnull; box->value_null = inner_fcinfo->isnull;
@ -640,8 +626,7 @@ coord_combine_agg_ffunc(PG_FUNCTION_ARGS)
{ {
Datum ret; Datum ret;
StypeBox *box = (StypeBox *) PG_GETARG_POINTER(0); StypeBox *box = (StypeBox *) PG_GETARG_POINTER(0);
FunctionCallInfoData inner_fcinfodata; LOCAL_FCINFO(inner_fcinfo, FUNC_MAX_ARGS);
FunctionCallInfo inner_fcinfo = &inner_fcinfodata;
FmgrInfo info; FmgrInfo info;
int inner_nargs; int inner_nargs;
HeapTuple aggtuple; HeapTuple aggtuple;
@ -695,11 +680,10 @@ coord_combine_agg_ffunc(PG_FUNCTION_ARGS)
fmgr_info(ffunc, &info); fmgr_info(ffunc, &info);
InitFunctionCallInfoData(*inner_fcinfo, &info, inner_nargs, fcinfo->fncollation, InitFunctionCallInfoData(*inner_fcinfo, &info, inner_nargs, fcinfo->fncollation,
fcinfo->context, fcinfo->resultinfo); fcinfo->context, fcinfo->resultinfo);
inner_fcinfo->arg[0] = box->value; fcSetArgExt(inner_fcinfo, 0, box->value, box->value_null);
inner_fcinfo->argnull[0] = box->value_null;
for (i = 1; i < inner_nargs; i++) for (i = 1; i < inner_nargs; i++)
{ {
inner_fcinfo->argnull[i] = true; fcSetArgNull(inner_fcinfo, i);
} }
ret = FunctionCallInvoke(inner_fcinfo); ret = FunctionCallInvoke(inner_fcinfo);
fcinfo->isnull = inner_fcinfo->isnull; fcinfo->isnull = inner_fcinfo->isnull;

View File

@ -33,10 +33,10 @@
#define GetSysCacheOid3Compat GetSysCacheOid3 #define GetSysCacheOid3Compat GetSysCacheOid3
#define GetSysCacheOid4Compat GetSysCacheOid4 #define GetSysCacheOid4Compat GetSysCacheOid4
#define fcSetArg(fc, n, argval) \ #define fcGetArgValue(fc, n) ((fc)->args[n].value)
(((fc)->args[n].isnull = false), ((fc)->args[n].value = (argval))) #define fcGetArgNull(fc, n) ((fc)->args[n].isnull)
#define fcSetArgNull(fc, n) \ #define fcSetArgExt(fc, n, val, is_null) \
(((fc)->args[n].isnull = true), ((fc)->args[n].value = (Datum) 0)) (((fc)->args[n].isnull = (is_null)), ((fc)->args[n].value = (val)))
typedef struct typedef struct
{ {
@ -104,10 +104,10 @@ FileCompatFromFileStart(File fileDesc)
FunctionCallInfoData name ## data; \ FunctionCallInfoData name ## data; \
FunctionCallInfoData *name = &name ## data FunctionCallInfoData *name = &name ## data
#define fcSetArg(fc, n, value) \ #define fcGetArgValue(fc, n) ((fc)->arg[n])
(((fc)->argnull[n] = false), ((fc)->arg[n] = (value))) #define fcGetArgNull(fc, n) ((fc)->argnull[n])
#define fcSetArgNull(fc, n) \ #define fcSetArgExt(fc, n, val, is_null) \
(((fc)->argnull[n] = true), ((fc)->arg[n] = (Datum) 0)) (((fc)->argnull[n] = (is_null)), ((fc)->arg[n] = (val)))
typedef struct typedef struct
{ {
@ -141,4 +141,7 @@ FileCompatFromFileStart(File fileDesc)
#endif /* PG12 */ #endif /* PG12 */
#define fcSetArg(fc, n, value) fcSetArgExt(fc, n, value, false)
#define fcSetArgNull(fc, n) fcSetArgExt(fc, n, (Datum) 0, true)
#endif /* VERSION_COMPAT_H */ #endif /* VERSION_COMPAT_H */