Skip to content

Commit 0b17d40

Browse files
Initial compatibility fixes for PostgreSQL 19
1 parent f126d7d commit 0b17d40

9 files changed

Lines changed: 108 additions & 35 deletions

src/RvSample.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern "C" {
2424
#include "funcapi.h"
2525
#include "miscadmin.h"
2626
#include "utils/builtins.h"
27+
#include "utils/tuplestore.h"
2728
#include "utils/uuid.h"
2829
#include "provsql_utils.h"
2930
#include "provsql_error.h"

src/compatibility.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@
1919
* - **list_make5() (13)**: existed pre-13, dropped by the PG13 list
2020
* rewrite, re-added in PG14; backported for the PG13 gap as a macro
2121
* over @c list_make4() + @c lappend().
22+
* - **FuncnameGetCandidates() / OpernameGetCandidates() (14, 19)**:
23+
* PostgreSQL 14 added an @p include_out_arguments parameter to the
24+
* former; PostgreSQL 19 added a mandatory @p fgc_flags out-parameter
25+
* to both. The @c *Compat wrappers take the PG 14-style argument
26+
* list and drop / dummy-fill the extra arguments as needed.
2227
*/
2328
#ifndef COMPATIBILITY_H
2429
#define COMPATIBILITY_H
2530

2631
#include "postgres.h"
2732
#include "nodes/pg_list.h"
33+
#include "catalog/namespace.h"
2834

2935
/**
3036
* @brief Version-agnostic wrapper around @c list_delete_cell().
@@ -66,6 +72,53 @@ static inline ListCell *my_lnext(const List *l, const ListCell *c)
6672
#endif
6773
}
6874

75+
/**
76+
* @brief Version-agnostic wrapper around @c FuncnameGetCandidates().
77+
*
78+
* Takes the PostgreSQL 14+ argument list. On PG < 14 the
79+
* @p include_out_arguments parameter (added in 14) is dropped; on
80+
* PG >= 19 the @p fgc_flags out-parameter (added in 19, must not be
81+
* @c NULL) receives a discarded local, as no caller inspects the
82+
* lookup-failure flags.
83+
*/
84+
static inline FuncCandidateList
85+
FuncnameGetCandidatesCompat(List *names, int nargs, List *argnames,
86+
bool expand_variadic, bool expand_defaults,
87+
bool include_out_arguments, bool missing_ok)
88+
{
89+
#if PG_VERSION_NUM >= 190000
90+
int fgc_flags;
91+
return FuncnameGetCandidates(names, nargs, argnames, expand_variadic,
92+
expand_defaults, include_out_arguments,
93+
missing_ok, &fgc_flags);
94+
#elif PG_VERSION_NUM >= 140000
95+
return FuncnameGetCandidates(names, nargs, argnames, expand_variadic,
96+
expand_defaults, include_out_arguments,
97+
missing_ok);
98+
#else
99+
return FuncnameGetCandidates(names, nargs, argnames, expand_variadic,
100+
expand_defaults, missing_ok);
101+
#endif
102+
}
103+
104+
/**
105+
* @brief Version-agnostic wrapper around @c OpernameGetCandidates().
106+
*
107+
* PostgreSQL 19 added an @p fgc_flags out-parameter (must not be
108+
* @c NULL); it receives a discarded local, as no caller inspects the
109+
* lookup-failure flags.
110+
*/
111+
static inline FuncCandidateList
112+
OpernameGetCandidatesCompat(List *names, char oprkind, bool missing_schema_ok)
113+
{
114+
#if PG_VERSION_NUM >= 190000
115+
int fgc_flags;
116+
return OpernameGetCandidates(names, oprkind, missing_schema_ok, &fgc_flags);
117+
#else
118+
return OpernameGetCandidates(names, oprkind, missing_schema_ok);
119+
#endif
120+
}
121+
69122
#if PG_VERSION_NUM < 130000
70123
/**
71124
* @brief Insert @p datum at position @p pos in @p list (PG < 13 backport).

src/provsql.c

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4820,13 +4820,10 @@ rewrite_probability_events(const constants_t *constants, Query *q)
48204820
static Expr *build_joint_width_provenance_expr(const constants_t *constants,
48214821
const char *desc, Expr *fallback)
48224822
{
4823-
FuncCandidateList fcl = FuncnameGetCandidates(
4823+
FuncCandidateList fcl = FuncnameGetCandidatesCompat(
48244824
list_make2(makeString("provsql"), makeString("ucq_joint_provenance")),
48254825
2, NIL, false, false,
4826-
#if PG_VERSION_NUM >= 140000
4827-
false,
4828-
#endif
4829-
false);
4826+
false, false);
48304827
FuncExpr *fe;
48314828
Const *c;
48324829
Datum jb;
@@ -4866,13 +4863,10 @@ static Expr *build_joint_width_provenance_expr(const constants_t *constants,
48664863
static Expr *build_mobius_provenance_expr(const constants_t *constants,
48674864
const char *desc, Expr *fallback)
48684865
{
4869-
FuncCandidateList fcl = FuncnameGetCandidates(
4866+
FuncCandidateList fcl = FuncnameGetCandidatesCompat(
48704867
list_make2(makeString("provsql"), makeString("ucq_mobius_provenance")),
48714868
2, NIL, false, false,
4872-
#if PG_VERSION_NUM >= 140000
4873-
false,
4874-
#endif
4875-
false);
4869+
false, false);
48764870
FuncExpr *fe;
48774871
Const *c;
48784872
Datum jb;
@@ -4909,13 +4903,10 @@ static Expr *build_joint_width_answer_expr(const constants_t *constants,
49094903
const char *desc, List *head_var_idx,
49104904
List *head_exprs, Expr *fallback)
49114905
{
4912-
FuncCandidateList fcl = FuncnameGetCandidates(
4906+
FuncCandidateList fcl = FuncnameGetCandidatesCompat(
49134907
list_make2(makeString("provsql"), makeString("ucq_joint_provenance_answer")),
49144908
4, NIL, false, false,
4915-
#if PG_VERSION_NUM >= 140000
4916-
false,
4917-
#endif
4918-
false);
4909+
false, false);
49194910
FuncExpr *fe;
49204911
Const *desc_c, *hv_c;
49214912
ArrayExpr *vals;
@@ -4982,13 +4973,10 @@ static Expr *build_mobius_answer_expr(const constants_t *constants,
49824973
const char *desc, List *head_var_idx,
49834974
List *head_exprs, Expr *fallback)
49844975
{
4985-
FuncCandidateList fcl = FuncnameGetCandidates(
4976+
FuncCandidateList fcl = FuncnameGetCandidatesCompat(
49864977
list_make2(makeString("provsql"), makeString("ucq_mobius_provenance_answer")),
49874978
4, NIL, false, false,
4988-
#if PG_VERSION_NUM >= 140000
4989-
false,
4990-
#endif
4991-
false);
4979+
false, false);
49924980
FuncExpr *fe;
49934981
Const *desc_c, *hv_c;
49944982
ArrayExpr *vals;
@@ -5046,13 +5034,10 @@ static Expr *build_mobius_answer_expr(const constants_t *constants,
50465034
*/
50475035
static Expr *wrap_mobius_or_null(const constants_t *constants, Expr *mobius_call)
50485036
{
5049-
FuncCandidateList fcl = FuncnameGetCandidates(
5037+
FuncCandidateList fcl = FuncnameGetCandidatesCompat(
50505038
list_make2(makeString("provsql"), makeString("mobius_or_null")),
50515039
1, NIL, false, false,
5052-
#if PG_VERSION_NUM >= 140000
5053-
false,
5054-
#endif
5055-
false);
5040+
false, false);
50565041
FuncExpr *fe;
50575042

50585043
if (fcl == NULL)
@@ -14788,7 +14773,11 @@ static PlannedStmt *provsql_planner(Query *q,
1478814773
const char *query_string,
1478914774
#endif
1479014775
int cursorOptions,
14791-
ParamListInfo boundParams) {
14776+
ParamListInfo boundParams
14777+
#if PG_VERSION_NUM >= 190000
14778+
, ExplainState *es
14779+
#endif
14780+
) {
1479214781
/* Scope the inert-fetch record to this rewrite (re-entrant: nested
1479314782
* planner invocations save and restore their own). */
1479414783
List *saved_inert_subselects = provsql_inert_subselects;
@@ -14890,13 +14879,21 @@ static PlannedStmt *provsql_planner(Query *q,
1489014879
#if PG_VERSION_NUM >= 130000
1489114880
query_string,
1489214881
#endif
14893-
cursorOptions, boundParams);
14882+
cursorOptions, boundParams
14883+
#if PG_VERSION_NUM >= 190000
14884+
, es
14885+
#endif
14886+
);
1489414887
else
1489514888
return standard_planner(q,
1489614889
#if PG_VERSION_NUM >= 130000
1489714890
query_string,
1489814891
#endif
14899-
cursorOptions, boundParams);
14892+
cursorOptions, boundParams
14893+
#if PG_VERSION_NUM >= 190000
14894+
, es
14895+
#endif
14896+
);
1490014897
}
1490114898

1490214899
/* -------------------------------------------------------------------------

src/provsql_mmap.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,29 @@ bool provsql_read_all(int fd, void *dst, size_t n)
8686
return true;
8787
}
8888

89+
#if PG_VERSION_NUM >= 190000
90+
/* PostgreSQL 19 changed the default background-worker SIGTERM handler
91+
* from bgworker_die() (immediate FATAL from the signal handler) to the
92+
* flag-based die(), which only acts at the next CHECK_FOR_INTERRUPTS().
93+
* This worker blocks in read() on the IPC pipe (restarted by
94+
* SA_RESTART), so it would never observe the flag and a fast shutdown
95+
* would hang on it. Restore the pre-19 semantics: the worker holds no
96+
* transaction state and the mmap store is crash-safe, so exiting
97+
* mid-read is fine. */
98+
static void provsql_worker_die(SIGNAL_ARGS)
99+
{
100+
ereport(FATAL,
101+
(errcode(ERRCODE_ADMIN_SHUTDOWN),
102+
errmsg("terminating background worker \"%s\" due to administrator command",
103+
MyBgworkerEntry->bgw_type)));
104+
}
105+
#endif
106+
89107
PGDLLEXPORT void provsql_mmap_worker(Datum ignored)
90108
{
109+
#if PG_VERSION_NUM >= 190000
110+
pqsignal(SIGTERM, provsql_worker_die);
111+
#endif
91112
BackgroundWorkerUnblockSignals();
92113
initialize_provsql_mmap();
93114
close(provsql_shared_state->pipebmw);

src/provsql_utils.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "catalog/pg_namespace.h"
4040
#include "catalog/pg_operator.h"
4141
#include "catalog/pg_type.h"
42+
#include "compatibility.h"
4243
#include "fmgr.h"
4344
#include "nodes/value.h"
4445
#include "parser/parse_func.h"
@@ -144,7 +145,7 @@ Oid find_equality_operator(Oid ltypeId, Oid rtypeId)
144145
if(result!=InvalidOid)
145146
return result;
146147

147-
clist = OpernameGetCandidates(equals, 'b', false);
148+
clist = OpernameGetCandidatesCompat(equals, 'b', false);
148149

149150
ncandidates = func_match_argtypes(2, inputOids,
150151
clist, &clist);
@@ -173,15 +174,13 @@ Oid find_equality_operator(Oid ltypeId, Oid rtypeId)
173174
*/
174175
static Oid get_func_oid(char *s)
175176
{
176-
FuncCandidateList fcl=FuncnameGetCandidates(
177+
FuncCandidateList fcl=FuncnameGetCandidatesCompat(
177178
list_make1(makeString(s)),
178179
-1,
179180
NIL,
180181
false,
181182
false,
182-
#if PG_VERSION_NUM >= 140000
183183
false,
184-
#endif
185184
false);
186185
if(fcl)
187186
return fcl->oid;
@@ -199,15 +198,13 @@ static Oid get_func_oid(char *s)
199198
*/
200199
static Oid get_provsql_func_oid(char *s)
201200
{
202-
FuncCandidateList fcl=FuncnameGetCandidates(
201+
FuncCandidateList fcl=FuncnameGetCandidatesCompat(
203202
list_make2(makeString("provsql"),makeString(s)),
204203
-1,
205204
NIL,
206205
false,
207206
false,
208-
#if PG_VERSION_NUM >= 140000
209207
false,
210-
#endif
211208
false);
212209
if(fcl)
213210
return fcl->oid;

src/reachability_evaluate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C" {
3030
#include "catalog/pg_type.h"
3131
#include "utils/array.h"
3232
#include "utils/builtins.h"
33+
#include "utils/tuplestore.h"
3334
#include "utils/uuid.h"
3435

3536
#include "provsql_utils.h"

src/rv_families.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern "C" {
1818
#include "catalog/pg_type.h"
1919
#include "utils/array.h"
2020
#include "utils/builtins.h"
21+
#include "utils/tuplestore.h"
2122

2223
#include "compatibility.h" /* TYPALIGN_INT fallback for PG < 11 */
2324

src/shapley.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525
#include "postgres.h"
2626
#include "fmgr.h"
2727
#include "catalog/pg_type.h"
28+
#include "utils/tuplestore.h"
2829
#include "utils/uuid.h"
2930
#include "executor/spi.h"
3031
#include "provsql_shmem.h"

src/tool_registry_sql.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extern "C" {
3636
#include "catalog/pg_type.h"
3737
#include "utils/array.h"
3838
#include "utils/builtins.h"
39+
#include "utils/tuplestore.h"
3940
#if PG_VERSION_NUM >= 160000
4041
#include "varatt.h"
4142
#endif

0 commit comments

Comments
 (0)