@@ -59,6 +59,12 @@ PG_MODULE_MAGIC;
5959#error VOPS requires 64-bit version of Postgres
6060#endif
6161
62+ #if PG_VERSION_NUM >=150000
63+ #define FUNC_CALL_CTX COERCE_EXPLICIT_CALL, -1
64+ #else
65+ #define FUNC_CALL_CTX -1
66+ #endif
67+
6268/* pg module functions */
6369void _PG_init (void );
6470void _PG_fini (void );
@@ -1151,13 +1157,24 @@ UserTableUpdateOpenIndexes()
11511157if (HeapTupleIsHeapOnly (tuple ))
11521158return ;
11531159
1160+ #if PG_VERSION_NUM >=150000
1161+ if (estate -> es_result_relations [0 ]-> ri_NumIndices > 0 )
1162+ {
1163+ recheckIndexes = ExecInsertIndexTuples (estate -> es_result_relations [0 ],
1164+ #else
11541165if (estate -> es_result_relation_info -> ri_NumIndices > 0 )
11551166{
1156- recheckIndexes = ExecInsertIndexTuples (slot ,
1167+ recheckIndexes = ExecInsertIndexTuples (
1168+ #endif
1169+ slot ,
11571170#if PG_VERSION_NUM < 120000
11581171& tuple -> t_self ,
11591172#endif
1160- estate , false,NULL ,NIL );
1173+ estate ,
1174+ #if PG_VERSION_NUM >=150000
1175+ true ,
1176+ #endif
1177+ false,NULL ,NIL );
11611178if (recheckIndexes != NIL )
11621179ereport (ERROR ,
11631180(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -1181,10 +1198,15 @@ static void begin_batch_insert(Oid oid)
11811198resultRelInfo -> ri_RelationDesc = rel ;
11821199resultRelInfo -> ri_TrigInstrument = NULL ;
11831200
1201+ #if PG_VERSION_NUM >=150000
1202+ estate -> es_result_relations = (ResultRelInfo * * )palloc (sizeof (ResultRelInfo * ));
1203+ estate -> es_result_relations [0 ]= resultRelInfo ;
1204+ #else
11841205estate -> es_result_relations = resultRelInfo ;
11851206estate -> es_num_result_relations = 1 ;
11861207estate -> es_result_relation_info = resultRelInfo ;
1187- ExecOpenIndices (estate -> es_result_relation_info , false);
1208+ #endif
1209+ ExecOpenIndices (resultRelInfo , false);
11881210#if PG_VERSION_NUM >=120000
11891211slot = ExecInitExtraTupleSlot (estate ,RelationGetDescr (rel ),& TTSOpsHeapTuple );
11901212#elif PG_VERSION_NUM >=110000
@@ -1210,7 +1232,11 @@ static void insert_tuple(Datum* values, bool* nulls)
12101232
12111233static void end_batch_insert ()
12121234{
1235+ #if PG_VERSION_NUM >=150000
1236+ ExecCloseIndices (estate -> es_result_relations [0 ]);
1237+ #else
12131238ExecCloseIndices (estate -> es_result_relation_info );
1239+ #endif
12141240if (ActiveSnapshotSet ()) {
12151241PopActiveSnapshot ();
12161242}
@@ -4149,7 +4175,7 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
41494175if (* op == '<' || * op == '>' ) {
41504176A_Expr * bound = makeNode (A_Expr );
41514177FuncCall * call = makeFuncCall (list_make1 (makeString (* op == '<' ?"first" :"last" )),
4152- list_make1 (expr -> lexpr ),-1 );
4178+ list_make1 (expr -> lexpr ),FUNC_CALL_CTX );
41534179bound -> kind = expr -> kind ;
41544180bound -> name = expr -> name ;
41554181bound -> lexpr = (Node * )call ;
@@ -4159,7 +4185,7 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
41594185}else if (expr -> kind == AEXPR_BETWEEN ) {
41604186A_Expr * bound = makeNode (A_Expr );
41614187FuncCall * call = makeFuncCall (list_make1 (makeString ("last" )),
4162- list_make1 (expr -> lexpr ),-1 );
4188+ list_make1 (expr -> lexpr ),FUNC_CALL_CTX );
41634189bound -> kind = AEXPR_OP ;
41644190bound -> name = list_make1 (makeString (">=" ));
41654191bound -> lexpr = (Node * )call ;
@@ -4169,7 +4195,7 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
41694195
41704196bound = makeNode (A_Expr );
41714197call = makeFuncCall (list_make1 (makeString ("first" )),
4172- list_make1 (expr -> lexpr ),-1 );
4198+ list_make1 (expr -> lexpr ),FUNC_CALL_CTX );
41734199bound -> kind = AEXPR_OP ;
41744200bound -> name = list_make1 (makeString ("<=" ));
41754201bound -> lexpr = (Node * )call ;
@@ -4179,7 +4205,7 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
41794205}else if (* op == '=' ) {
41804206A_Expr * bound = makeNode (A_Expr );
41814207FuncCall * call = makeFuncCall (list_make1 (makeString ("last" )),
4182- list_make1 (expr -> lexpr ),-1 );
4208+ list_make1 (expr -> lexpr ),FUNC_CALL_CTX );
41834209bound -> kind = expr -> kind ;
41844210bound -> name = list_make1 (makeString (">=" ));
41854211bound -> lexpr = (Node * )call ;
@@ -4189,7 +4215,7 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
41894215
41904216bound = makeNode (A_Expr );
41914217call = makeFuncCall (list_make1 (makeString ("first" )),
4192- list_make1 (expr -> lexpr ),-1 );
4218+ list_make1 (expr -> lexpr ),FUNC_CALL_CTX );
41934219bound -> kind = expr -> kind ;
41944220bound -> name = list_make1 (makeString ("<=" ));
41954221bound -> lexpr = (Node * )call ;
@@ -4554,13 +4580,21 @@ vops_resolve_functions(void)
45544580}
45554581}
45564582
4583+ #if PG_VERSION_NUM >=150000
4584+ static void vops_post_parse_analysis_hook (ParseState * pstate ,Query * query ,JumbleState * jstate )
4585+ #else
45574586static void vops_post_parse_analysis_hook (ParseState * pstate ,Query * query )
4587+ #endif
45584588{
45594589vops_var var ;
45604590/* Invoke original hook if needed */
45614591if (post_parse_analyze_hook_next )
45624592{
4593+ #if PG_VERSION_NUM >=150000
4594+ post_parse_analyze_hook_next (pstate ,query ,jstate );
4595+ #else
45634596post_parse_analyze_hook_next (pstate ,query );
4597+ #endif
45644598}
45654599vops_resolve_functions ();
45664600