From 7ced1d1247286399df53823eb76cacaf6d7fdb22 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Tue, 23 Jan 2018 23:20:02 -0800 Subject: [PATCH] Add FIELDNO_* macro designating offset into structs required for JIT. For any interesting JIT target, fields inside structs need to be accessed. b96d550e contains infrastructure for syncing the definition of types between postgres C code and runtime code generation with LLVM. But that doesn't sync the number or names of fields inside structs, just the types (including padding etc). One option would be to hardcode the offset numbers in the JIT code, but that'd be hard to keep in sync. Instead add macros indicating the field offset to the fields that need to be accessed. Not pretty, but manageable. Author: Andres Freund Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de --- src/include/access/htup.h | 1 + src/include/access/htup_details.h | 4 ++++ src/include/executor/nodeAgg.h | 3 +++ src/include/executor/tuptable.h | 7 +++++++ src/include/fmgr.h | 3 +++ src/include/nodes/execnodes.h | 16 ++++++++++++++++ 6 files changed, 34 insertions(+) diff --git a/src/include/access/htup.h b/src/include/access/htup.h index e78d804756a..5a4e5b05f50 100644 --- a/src/include/access/htup.h +++ b/src/include/access/htup.h @@ -64,6 +64,7 @@ typedef struct HeapTupleData uint32 t_len; /* length of *t_data */ ItemPointerData t_self; /* SelfItemPointer */ Oid t_tableOid; /* table the tuple came from */ +#define FIELDNO_HEAPTUPLEDATA_DATA 3 HeapTupleHeader t_data; /* -> tuple header and data */ } HeapTupleData; diff --git a/src/include/access/htup_details.h b/src/include/access/htup_details.h index 2ab1815390c..3616a17b6fa 100644 --- a/src/include/access/htup_details.h +++ b/src/include/access/htup_details.h @@ -157,14 +157,18 @@ struct HeapTupleHeaderData /* Fields below here must match MinimalTupleData! */ +#define FIELDNO_HEAPTUPLEHEADERDATA_INFOMASK2 2 uint16 t_infomask2; /* number of attributes + various flags */ +#define FIELDNO_HEAPTUPLEHEADERDATA_INFOMASK 3 uint16 t_infomask; /* various flag bits, see below */ +#define FIELDNO_HEAPTUPLEHEADERDATA_HOFF 4 uint8 t_hoff; /* sizeof header incl. bitmap, padding */ /* ^ - 23 bytes - ^ */ +#define FIELDNO_HEAPTUPLEHEADERDATA_BITS 5 bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]; /* bitmap of NULLs */ /* MORE DATA FOLLOWS AT END OF STRUCT */ diff --git a/src/include/executor/nodeAgg.h b/src/include/executor/nodeAgg.h index aa6ebaaf97d..4650dc2c7e9 100644 --- a/src/include/executor/nodeAgg.h +++ b/src/include/executor/nodeAgg.h @@ -240,9 +240,12 @@ typedef struct AggStatePerAggData */ typedef struct AggStatePerGroupData { +#define FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUE 0 Datum transValue; /* current transition value */ +#define FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUEISNULL 1 bool transValueIsNull; +#define FIELDNO_AGGSTATEPERGROUPDATA_NOTRANSVALUE 2 bool noTransValue; /* true if transValue not set yet */ /* diff --git a/src/include/executor/tuptable.h b/src/include/executor/tuptable.h index a5779b15eab..3c1cf67d8f9 100644 --- a/src/include/executor/tuptable.h +++ b/src/include/executor/tuptable.h @@ -116,16 +116,23 @@ typedef struct TupleTableSlot bool tts_isempty; /* true = slot is empty */ bool tts_shouldFree; /* should pfree tts_tuple? */ bool tts_shouldFreeMin; /* should pfree tts_mintuple? */ +#define FIELDNO_TUPLETABLESLOT_SLOW 4 bool tts_slow; /* saved state for slot_deform_tuple */ +#define FIELDNO_TUPLETABLESLOT_TUPLE 5 HeapTuple tts_tuple; /* physical tuple, or NULL if virtual */ +#define FIELDNO_TUPLETABLESLOT_TUPLEDESCRIPTOR 6 TupleDesc tts_tupleDescriptor; /* slot's tuple descriptor */ MemoryContext tts_mcxt; /* slot itself is in this context */ Buffer tts_buffer; /* tuple's buffer, or InvalidBuffer */ +#define FIELDNO_TUPLETABLESLOT_NVALID 9 int tts_nvalid; /* # of valid values in tts_values */ +#define FIELDNO_TUPLETABLESLOT_VALUES 10 Datum *tts_values; /* current per-attribute values */ +#define FIELDNO_TUPLETABLESLOT_ISNULL 11 bool *tts_isnull; /* current per-attribute isnull flags */ MinimalTuple tts_mintuple; /* minimal tuple, or NULL if none */ HeapTupleData tts_minhdr; /* workspace for minimal-tuple-only case */ +#define FIELDNO_TUPLETABLESLOT_OFF 14 uint32 tts_off; /* saved state for slot_deform_tuple */ bool tts_fixedTupleDescriptor; /* descriptor can't be changed */ } TupleTableSlot; diff --git a/src/include/fmgr.h b/src/include/fmgr.h index 69786bfca85..59e73d4e45c 100644 --- a/src/include/fmgr.h +++ b/src/include/fmgr.h @@ -80,9 +80,12 @@ typedef struct FunctionCallInfoData fmNodePtr context; /* pass info about context of call */ fmNodePtr resultinfo; /* pass or return extra info about result */ Oid fncollation; /* collation for function to use */ +#define FIELDNO_FUNCTIONCALLINFODATA_ISNULL 4 bool isnull; /* function must set true if result is NULL */ short nargs; /* # arguments actually passed */ +#define FIELDNO_FUNCTIONCALLINFODATA_ARG 6 Datum arg[FUNC_MAX_ARGS]; /* Arguments passed to function */ +#define FIELDNO_FUNCTIONCALLINFODATA_ARGNULL 7 bool argnull[FUNC_MAX_ARGS]; /* T if arg[i] is actually NULL */ } FunctionCallInfoData; diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 7b752560c60..bf2616a95ed 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -64,12 +64,15 @@ typedef struct ExprState * Storage for result value of a scalar expression, or for individual * column results within expressions built by ExecBuildProjectionInfo(). */ +#define FIELDNO_EXPRSTATE_RESNULL 2 bool resnull; +#define FIELDNO_EXPRSTATE_RESVALUE 3 Datum resvalue; /* * If projecting a tuple result, this slot holds the result; else NULL. */ +#define FIELDNO_EXPRSTATE_RESULTSLOT 4 TupleTableSlot *resultslot; /* @@ -208,8 +211,11 @@ typedef struct ExprContext NodeTag type; /* Tuples that Var nodes in expression may refer to */ +#define FIELDNO_EXPRCONTEXT_SCANTUPLE 1 TupleTableSlot *ecxt_scantuple; +#define FIELDNO_EXPRCONTEXT_INNERTUPLE 2 TupleTableSlot *ecxt_innertuple; +#define FIELDNO_EXPRCONTEXT_OUTERTUPLE 3 TupleTableSlot *ecxt_outertuple; /* Memory contexts for expression evaluation --- see notes above */ @@ -224,15 +230,21 @@ typedef struct ExprContext * Values to substitute for Aggref nodes in the expressions of an Agg * node, or for WindowFunc nodes within a WindowAgg node. */ +#define FIELDNO_EXPRCONTEXT_AGGVALUES 8 Datum *ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */ +#define FIELDNO_EXPRCONTEXT_AGGNULLS 9 bool *ecxt_aggnulls; /* null flags for aggs/windowfuncs */ /* Value to substitute for CaseTestExpr nodes in expression */ +#define FIELDNO_EXPRCONTEXT_CASEDATUM 10 Datum caseValue_datum; +#define FIELDNO_EXPRCONTEXT_CASENULL 11 bool caseValue_isNull; /* Value to substitute for CoerceToDomainValue nodes in expression */ +#define FIELDNO_EXPRCONTEXT_DOMAINDATUM 12 Datum domainValue_datum; +#define FIELDNO_EXPRCONTEXT_DOMAINNULL 13 bool domainValue_isNull; /* Link to containing EState (NULL if a standalone ExprContext) */ @@ -1847,12 +1859,15 @@ typedef struct AggState ExprContext *hashcontext; /* econtexts for long-lived data (hashtable) */ ExprContext **aggcontexts; /* econtexts for long-lived data (per GS) */ ExprContext *tmpcontext; /* econtext for input expressions */ +#define FIELDNO_AGGSTATE_CURAGGCONTEXT 14 ExprContext *curaggcontext; /* currently active aggcontext */ AggStatePerAgg curperagg; /* currently active aggregate, if any */ +#define FIELDNO_AGGSTATE_CURPERTRANS 16 AggStatePerTrans curpertrans; /* currently active trans state, if any */ bool input_done; /* indicates end of input */ bool agg_done; /* indicates completion of Agg scan */ int projected_set; /* The last projected grouping set */ +#define FIELDNO_AGGSTATE_CURRENT_SET 20 int current_set; /* The current grouping set being evaluated */ Bitmapset *grouped_cols; /* grouped cols in current projection */ List *all_grouped_cols; /* list of all grouped cols in DESC order */ @@ -1874,6 +1889,7 @@ typedef struct AggState * per-group pointers */ /* support for evaluation of agg input expressions: */ +#define FIELDNO_AGGSTATE_ALL_PERGROUPS 34 AggStatePerGroup *all_pergroups; /* array of first ->pergroups, than * ->hash_pergroup */ ProjectionInfo *combinedproj; /* projection machinery */ -- 2.39.5