Add FIELDNO_* macro designating offset into structs required for JIT.
authorAndres Freund <andres@anarazel.de>
Wed, 24 Jan 2018 07:20:02 +0000 (23:20 -0800)
committerAndres Freund <andres@anarazel.de>
Thu, 22 Mar 2018 21:45:59 +0000 (14:45 -0700)
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
src/include/access/htup_details.h
src/include/executor/nodeAgg.h
src/include/executor/tuptable.h
src/include/fmgr.h
src/include/nodes/execnodes.h

index e78d804756a301f3a5e34d06a5910264f7236c7a..5a4e5b05f50e88eb60eae7207bb5c2de5806e3cf 100644 (file)
@@ -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;
 
index 2ab1815390c3c3f38e3b2dc02aadf6f7a271d52c..3616a17b6fa65ba1bf87071fc2940de57fbc46d9 100644 (file)
@@ -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 */
index aa6ebaaf97d20e79b06a25ae4253ed6cef1e7e5b..4650dc2c7e939cd5e9511032a85c24600fe7c5ef 100644 (file)
@@ -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 */
 
    /*
index a5779b15eab6d5e03b8f0f1019d7785e48d1a6f1..3c1cf67d8f94d8323f5c66e803d78d75f8395961 100644 (file)
@@ -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;
index 69786bfca85914dc166fe0635f232c19888c1855..59e73d4e45cc30b567757c1d5a13f48c282afd73 100644 (file)
@@ -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;
 
index 7b752560c60fdbad4fabdda6eed3593387d9f1d8..bf2616a95ed11a66c000a0832e047eb875637fa0 100644 (file)
@@ -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 */