Skip to content

Commit b26d61e

Browse files
committed
Add initial PG19 support
1 parent 75df0a6 commit b26d61e

26 files changed

Lines changed: 117 additions & 61 deletions

.github/workflows/build_and_test.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ jobs:
5454
type: ReleaseStatic
5555
- version: REL_18_STABLE
5656
type: Debug
57+
- version: master
58+
type: Release
5759

5860
runs-on: ubuntu-24.04
5961

@@ -131,7 +133,7 @@ jobs:
131133
- name: Build pg_duckdb extension
132134
id: build
133135
working-directory: duckdb
134-
run: ERROR_ON_WARNING=1 make -j8 install DUCKDB_BUILD=${{ matrix.type }}
136+
run: ERROR_ON_WARNING=1 make -j8 install DUCKDB_BUILD=${{ matrix.type }} PG_MAX_VER=19
135137

136138
- name: Run make installcheck
137139
id: installcheck

include/pgduckdb/pg/declarations.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ typedef struct ParamListInfoData *ParamListInfo;
5050

5151
struct PlannedStmt;
5252

53-
typedef char *Pointer;
54-
typedef Pointer Page;
53+
typedef char PageData;
54+
typedef PageData *Page;
5555

5656
struct Query;
5757

include/pgduckdb/pg/transactions.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
extern "C" {
66
extern bool IsSubTransaction(void);
77

8-
#define FirstCommandId ((CommandId)0)
9-
108
/*
119
* These enum definitions are vendored in so we can implement a postgres
1210
* XactCallback in C++. It's not expected that these will ever change.
11+
*
12+
* They are guarded by XACT_H to avoid redefinition errors when access/xact.h
13+
* has already been included.
1314
*/
15+
#ifndef XACT_H
1416
typedef enum {
1517
XACT_EVENT_COMMIT,
1618
XACT_EVENT_PARALLEL_COMMIT,
@@ -32,6 +34,10 @@ typedef enum {
3234
} SubXactEvent;
3335

3436
typedef void (*SubXactCallback)(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg);
37+
38+
/* Similarly guarded to avoid redefinition errors */
39+
#define FirstCommandId ((CommandId)0)
40+
#endif
3541
}
3642

3743
namespace pgduckdb::pg {

src/pg/memory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "pgduckdb/pgduckdb_utils.hpp"
2+
#include "pgduckdb/pg/memory.hpp"
23

34
extern "C" {
45
#include "postgres.h"

src/pg/permissions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "pgduckdb/pg/permissions.hpp"
2+
13
extern "C" {
24
#include "postgres.h"
35
#include "miscadmin.h" // GetUserId

src/pg/pgduckdb_subscript.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace pgduckdb {
1616

1717
namespace pg {
1818

19-
Node *
19+
static Node *
2020
CoerceSubscriptToText(struct ParseState *pstate, A_Indices *subscript, const char *type_name) {
2121
if (!subscript->uidx) {
2222
elog(ERROR, "Creating a slice out of %s is not supported", type_name);
@@ -69,7 +69,7 @@ CoerceSubscriptToText(struct ParseState *pstate, A_Indices *subscript, const cha
6969
*
7070
* See also comments on SubscriptingRef in nodes/subscripting.h
7171
*/
72-
void
72+
static void
7373
AddSubscriptExpressions(SubscriptingRef *sbsref, struct ParseState *pstate, A_Indices *subscript, bool is_slice) {
7474
Assert(is_slice || subscript->uidx);
7575

@@ -95,7 +95,7 @@ AddSubscriptExpressions(SubscriptingRef *sbsref, struct ParseState *pstate, A_In
9595
* expressions. All this does is parse those expressions and make sure the
9696
* subscript returns an an duckdb.unresolved_type again.
9797
*/
98-
void
98+
static void
9999
DuckdbSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate, bool is_slice,
100100
bool is_assignment, const char *type_name) {
101101
/*
@@ -135,7 +135,7 @@ DuckdbSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct Pars
135135
*
136136
* Currently this is used for duckdb.row and duckdb.struct types.
137137
*/
138-
void
138+
static void
139139
DuckdbTextSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate, bool is_slice,
140140
bool is_assignment, const char *type_name) {
141141
/*
@@ -217,7 +217,7 @@ DuckdbSubscriptFetchOld(ExprState * /*state*/, ExprEvalStep *op, ExprContext * /
217217
* shouldn't force usage of DuckDB execution when duckdb types are present in
218218
* the query. So these methods are just stubs that throw an error when called.
219219
*/
220-
void
220+
static void
221221
DuckdbSubscriptExecSetup(const SubscriptingRef * /*sbsref*/, SubscriptingRefState *sbsrefstate,
222222
SubscriptExecSteps *methods, const char *type_name) {
223223

@@ -228,13 +228,13 @@ DuckdbSubscriptExecSetup(const SubscriptingRef * /*sbsref*/, SubscriptingRefStat
228228
methods->sbs_fetch_old = DuckdbSubscriptFetchOld;
229229
}
230230

231-
void
231+
static void
232232
DuckdbRowSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate, bool is_slice,
233233
bool is_assignment) {
234234
DuckdbTextSubscriptTransform(sbsref, indirection, pstate, is_slice, is_assignment, "duckdb.row");
235235
}
236236

237-
void
237+
static void
238238
DuckdbRowSubscriptExecSetup(const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate,
239239
SubscriptExecSteps *methods) {
240240
DuckdbSubscriptExecSetup(sbsref, sbsrefstate, methods, "duckdb.row");
@@ -248,13 +248,13 @@ static SubscriptRoutines duckdb_row_subscript_routines = {
248248
.store_leakproof = true,
249249
};
250250

251-
void
251+
static void
252252
DuckdbUnresolvedTypeSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate,
253253
bool is_slice, bool is_assignment) {
254254
DuckdbSubscriptTransform(sbsref, indirection, pstate, is_slice, is_assignment, "duckdb.unresolved_type");
255255
}
256256

257-
void
257+
static void
258258
DuckdbUnresolvedTypeSubscriptExecSetup(const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate,
259259
SubscriptExecSteps *methods) {
260260
DuckdbSubscriptExecSetup(sbsref, sbsrefstate, methods, "duckdb.unresolved_type");
@@ -268,13 +268,13 @@ static SubscriptRoutines duckdb_unresolved_type_subscript_routines = {
268268
.store_leakproof = true,
269269
};
270270

271-
void
271+
static void
272272
DuckdbStructSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate, bool is_slice,
273273
bool is_assignment) {
274274
DuckdbTextSubscriptTransform(sbsref, indirection, pstate, is_slice, is_assignment, "duckdb.struct");
275275
}
276276

277-
void
277+
static void
278278
DuckdbStructSubscriptExecSetup(const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate,
279279
SubscriptExecSteps *methods) {
280280
DuckdbSubscriptExecSetup(sbsref, sbsrefstate, methods, "duckdb.struct");
@@ -288,13 +288,13 @@ static SubscriptRoutines duckdb_struct_subscript_routines = {
288288
.store_leakproof = true,
289289
};
290290

291-
void
291+
static void
292292
DuckdbMapSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate, bool is_slice,
293293
bool is_assignment) {
294294
DuckdbSubscriptTransform(sbsref, indirection, pstate, is_slice, is_assignment, "duckdb.map");
295295
}
296296

297-
void
297+
static void
298298
DuckdbMapSubscriptExecSetup(const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate,
299299
SubscriptExecSteps *methods) {
300300
DuckdbSubscriptExecSetup(sbsref, sbsrefstate, methods, "duckdb.map");

src/pg/relations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ EstimateRelSize(Relation rel) {
129129
return cardinality;
130130
}
131131

132-
Oid
132+
static Oid
133133
PGGetRelidFromSchemaAndTable(const char *schema_name, const char *entry_name) {
134134
List *name_list = NIL;
135135
name_list = lappend(name_list, makeString(pstrdup(schema_name)));

src/pg/transactions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ extern "C" {
66
#include "access/xlog.h" // XactLastRecEnd
77
}
88

9+
#include "pgduckdb/pg/transactions.hpp"
10+
911
namespace pgduckdb::pg {
1012

1113
CommandId
12-
GetCurrentCommandId(bool used = false) {
14+
GetCurrentCommandId(bool used) {
1315
return PostgresFunctionGuard(::GetCurrentCommandId, used);
1416
}
1517

src/pgduckdb_background_worker.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ extern "C" {
5252
#include "utils/acl.h"
5353
#include "utils/builtins.h"
5454
#include "utils/guc.h"
55+
#include "utils/lsyscache.h"
5556
#include "utils/memutils.h"
5657
#include "utils/palloc.h"
5758
#include "utils/snapmgr.h"
@@ -118,14 +119,14 @@ static BackgroundWorkerShmemStruct *BgwShmemStruct;
118119
MUST be called under a lock
119120
Get the BGW state for the current database (MyDatabaseId)
120121
*/
121-
BgwStatePerDB *
122+
static BgwStatePerDB *
122123
FindState() {
123124
bool found = false;
124125
auto state = (BgwStatePerDB *)hash_search(BgwShmemStruct->statePerDB, &MyDatabaseId, HASH_FIND, &found);
125126
return found ? state : nullptr;
126127
}
127128

128-
BgwStatePerDB *
129+
static BgwStatePerDB *
129130
GetState() {
130131
Assert(is_background_worker);
131132
auto state = FindState();
@@ -157,7 +158,7 @@ BackgroundWorkerCheck(duckdb::Connection &connection, int64_t &last_activity_cou
157158

158159
bool CanTakeBgwLockForDatabase(Oid database_oid);
159160

160-
bool
161+
static bool
161162
RunOneCheck(int64_t &last_activity_count) {
162163
// No need to run if MD is not enabled.
163164
if (!IsMotherDuckEnabled()) {
@@ -182,15 +183,15 @@ RunOneCheck(int64_t &last_activity_count) {
182183
return false;
183184
}
184185

185-
void
186+
static void
186187
SetBackgroundWorkerState(Oid database_oid) {
187188
auto state = (BgwStatePerDB *)hash_search(BgwShmemStruct->statePerDB, &database_oid, HASH_ENTER, NULL);
188189
state->latch = MyLatch;
189190
state->activity_count = 0;
190191
state->bgw_session_hint_is_reused = false;
191192
}
192193

193-
void
194+
static void
194195
BgwMainLoop() {
195196
elog(LOG, "pg_duckdb background worker: starting");
196197

@@ -244,6 +245,8 @@ BgwMainLoop() {
244245

245246
extern "C" {
246247

248+
PGDLLEXPORT void pgduckdb_background_worker_main(Datum main_arg);
249+
247250
PGDLLEXPORT void
248251
pgduckdb_background_worker_main(Datum main_arg) {
249252
Oid database_oid = DatumGetObjectId(main_arg);
@@ -368,7 +371,7 @@ ShmemStartup(void) {
368371

369372
constexpr const char *PGDUCKDB_SYNC_WORKER_NAME = "pg_duckdb sync worker";
370373

371-
bool
374+
static bool
372375
HasBgwRunningForMyDatabase() {
373376
const auto num_backends = pgstat_fetch_stat_numbackends();
374377
for (int backend_idx = 1; backend_idx <= num_backends; ++backend_idx) {
@@ -544,7 +547,7 @@ PossiblyReuseBgwSessionHint(void) {
544547
bool doing_motherduck_sync;
545548
char *current_motherduck_catalog_version;
546549

547-
std::string
550+
static std::string
548551
PgSchemaName(const std::string &db_name, const std::string &schema_name, bool is_default_db) {
549552
if (is_default_db) {
550553
/*
@@ -563,7 +566,7 @@ PgSchemaName(const std::string &db_name, const std::string &schema_name, bool is
563566
return oss.str();
564567
}
565568

566-
std::string
569+
static std::string
567570
DropPgRelationString(const char *postgres_schema_name, const char *relation_name, char relation_kind,
568571
bool with_cascade) {
569572
std::ostringstream oss;
@@ -583,7 +586,7 @@ DropPgRelationString(const char *postgres_schema_name, const char *relation_name
583586
return oss.str();
584587
}
585588

586-
std::string
589+
static std::string
587590
CreatePgViewString(duckdb::CreateViewInfo &info, bool is_default_db) {
588591
std::ostringstream oss;
589592

@@ -633,7 +636,7 @@ CreatePgViewString(duckdb::CreateViewInfo &info, bool is_default_db) {
633636
return oss.str();
634637
}
635638

636-
std::string
639+
static std::string
637640
CreatePgTableString(duckdb::CreateTableInfo &info, bool is_default_db) {
638641
std::ostringstream oss;
639642

@@ -695,7 +698,7 @@ CreatePgSchemaString(std::string postgres_schema_name) {
695698
* See the following thread for details:
696699
* https://www.postgresql.org/message-id/flat/CAFcNs%2Bp%2BfD5HEXEiZMZC1COnXkJCMnUK0%3Dr4agmZP%3D9Hi%2BYcJA%40mail.gmail.com
697700
*/
698-
void
701+
static void
699702
SPI_commit_that_works_in_bgworker() {
700703
if (is_background_worker) {
701704
SPI_finish();

src/pgduckdb_ddl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ DuckdbTruncateTable(Oid relation_oid) {
11751175
* ONCOMMIT_DROP, but this will also handle any new ON COMMIT clauses that
11761176
* might be added to Postgres in future releases.
11771177
*/
1178-
void
1178+
static void
11791179
CheckOnCommitSupport(OnCommitAction on_commit) {
11801180
switch (on_commit) {
11811181
case ONCOMMIT_NOOP:

0 commit comments

Comments
 (0)