Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ jobs:
type: ReleaseStatic
- version: REL_18_STABLE
type: Debug
- version: master
type: Release

runs-on: ubuntu-24.04

env:
PG_MAX_VER: "19"

steps:
- name: Test details
run: echo Build and test pg_duckdb with PostgreSQL ${{ matrix.version }} branch
Expand Down
4 changes: 2 additions & 2 deletions include/pgduckdb/pg/declarations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ typedef struct ParamListInfoData *ParamListInfo;

struct PlannedStmt;

typedef char *Pointer;
typedef Pointer Page;
typedef char PageData;
typedef PageData *Page;

struct Query;

Expand Down
10 changes: 8 additions & 2 deletions include/pgduckdb/pg/transactions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
extern "C" {
extern bool IsSubTransaction(void);

#define FirstCommandId ((CommandId)0)

/*
* These enum definitions are vendored in so we can implement a postgres
* XactCallback in C++. It's not expected that these will ever change.
*
* They are guarded by XACT_H to avoid redefinition errors when access/xact.h
* has already been included.
*/
#ifndef XACT_H
typedef enum {
XACT_EVENT_COMMIT,
XACT_EVENT_PARALLEL_COMMIT,
Expand All @@ -32,6 +34,10 @@ typedef enum {
} SubXactEvent;

typedef void (*SubXactCallback)(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg);

/* Similarly guarded to avoid redefinition errors */
#define FirstCommandId ((CommandId)0)
#endif
}

namespace pgduckdb::pg {
Expand Down
1 change: 1 addition & 0 deletions src/pg/memory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pgduckdb/pgduckdb_utils.hpp"
#include "pgduckdb/pg/memory.hpp"

extern "C" {
#include "postgres.h"
Expand Down
2 changes: 2 additions & 0 deletions src/pg/permissions.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "pgduckdb/pg/permissions.hpp"

extern "C" {
#include "postgres.h"
#include "miscadmin.h" // GetUserId
Expand Down
26 changes: 13 additions & 13 deletions src/pg/pgduckdb_subscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace pgduckdb {

namespace pg {

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

Expand All @@ -95,7 +95,7 @@ AddSubscriptExpressions(SubscriptingRef *sbsref, struct ParseState *pstate, A_In
* expressions. All this does is parse those expressions and make sure the
* subscript returns an an duckdb.unresolved_type again.
*/
void
static void
DuckdbSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate, bool is_slice,
bool is_assignment, const char *type_name) {
/*
Expand Down Expand Up @@ -135,7 +135,7 @@ DuckdbSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct Pars
*
* Currently this is used for duckdb.row and duckdb.struct types.
*/
void
static void
DuckdbTextSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate, bool is_slice,
bool is_assignment, const char *type_name) {
/*
Expand Down Expand Up @@ -217,7 +217,7 @@ DuckdbSubscriptFetchOld(ExprState * /*state*/, ExprEvalStep *op, ExprContext * /
* shouldn't force usage of DuckDB execution when duckdb types are present in
* the query. So these methods are just stubs that throw an error when called.
*/
void
static void
DuckdbSubscriptExecSetup(const SubscriptingRef * /*sbsref*/, SubscriptingRefState *sbsrefstate,
SubscriptExecSteps *methods, const char *type_name) {

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

void
static void
DuckdbRowSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate, bool is_slice,
bool is_assignment) {
DuckdbTextSubscriptTransform(sbsref, indirection, pstate, is_slice, is_assignment, "duckdb.row");
}

void
static void
DuckdbRowSubscriptExecSetup(const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate,
SubscriptExecSteps *methods) {
DuckdbSubscriptExecSetup(sbsref, sbsrefstate, methods, "duckdb.row");
Expand All @@ -248,13 +248,13 @@ static SubscriptRoutines duckdb_row_subscript_routines = {
.store_leakproof = true,
};

void
static void
DuckdbUnresolvedTypeSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate,
bool is_slice, bool is_assignment) {
DuckdbSubscriptTransform(sbsref, indirection, pstate, is_slice, is_assignment, "duckdb.unresolved_type");
}

void
static void
DuckdbUnresolvedTypeSubscriptExecSetup(const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate,
SubscriptExecSteps *methods) {
DuckdbSubscriptExecSetup(sbsref, sbsrefstate, methods, "duckdb.unresolved_type");
Expand All @@ -268,13 +268,13 @@ static SubscriptRoutines duckdb_unresolved_type_subscript_routines = {
.store_leakproof = true,
};

void
static void
DuckdbStructSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate, bool is_slice,
bool is_assignment) {
DuckdbTextSubscriptTransform(sbsref, indirection, pstate, is_slice, is_assignment, "duckdb.struct");
}

void
static void
DuckdbStructSubscriptExecSetup(const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate,
SubscriptExecSteps *methods) {
DuckdbSubscriptExecSetup(sbsref, sbsrefstate, methods, "duckdb.struct");
Expand All @@ -288,13 +288,13 @@ static SubscriptRoutines duckdb_struct_subscript_routines = {
.store_leakproof = true,
};

void
static void
DuckdbMapSubscriptTransform(SubscriptingRef *sbsref, List *indirection, struct ParseState *pstate, bool is_slice,
bool is_assignment) {
DuckdbSubscriptTransform(sbsref, indirection, pstate, is_slice, is_assignment, "duckdb.map");
}

void
static void
DuckdbMapSubscriptExecSetup(const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate,
SubscriptExecSteps *methods) {
DuckdbSubscriptExecSetup(sbsref, sbsrefstate, methods, "duckdb.map");
Expand Down
2 changes: 1 addition & 1 deletion src/pg/relations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ EstimateRelSize(Relation rel) {
return cardinality;
}

Oid
static Oid
PGGetRelidFromSchemaAndTable(const char *schema_name, const char *entry_name) {
List *name_list = NIL;
name_list = lappend(name_list, makeString(pstrdup(schema_name)));
Expand Down
4 changes: 3 additions & 1 deletion src/pg/transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ extern "C" {
#include "access/xlog.h" // XactLastRecEnd
}

#include "pgduckdb/pg/transactions.hpp"

namespace pgduckdb::pg {

CommandId
GetCurrentCommandId(bool used = false) {
GetCurrentCommandId(bool used) {
return PostgresFunctionGuard(::GetCurrentCommandId, used);
}

Expand Down
25 changes: 14 additions & 11 deletions src/pgduckdb_background_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern "C" {
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/palloc.h"
#include "utils/snapmgr.h"
Expand Down Expand Up @@ -119,14 +120,14 @@ static BackgroundWorkerShmemStruct *BgwShmemStruct;
MUST be called under a lock
Get the BGW state for the current database (MyDatabaseId)
*/
BgwStatePerDB *
static BgwStatePerDB *
FindState() {
bool found = false;
auto state = (BgwStatePerDB *)hash_search(BgwShmemStruct->statePerDB, &MyDatabaseId, HASH_FIND, &found);
return found ? state : nullptr;
}

BgwStatePerDB *
static BgwStatePerDB *
GetState() {
Assert(is_background_worker);
auto state = FindState();
Expand Down Expand Up @@ -158,7 +159,7 @@ BackgroundWorkerCheck(duckdb::Connection &connection, int64_t &last_activity_cou

bool CanTakeBgwLockForDatabase(Oid database_oid);

bool
static bool
RunOneCheck(int64_t &last_activity_count) {
// No need to run if MD is not enabled.
if (!IsMotherDuckEnabled()) {
Expand All @@ -183,15 +184,15 @@ RunOneCheck(int64_t &last_activity_count) {
return false;
}

void
static void
SetBackgroundWorkerState(Oid database_oid) {
auto state = (BgwStatePerDB *)hash_search(BgwShmemStruct->statePerDB, &database_oid, HASH_ENTER, NULL);
state->latch = MyLatch;
state->activity_count = 0;
state->bgw_session_hint_is_reused = false;
}

void
static void
BgwMainLoop() {
elog(LOG, "pg_duckdb background worker: starting");

Expand Down Expand Up @@ -245,6 +246,8 @@ BgwMainLoop() {

extern "C" {

PGDLLEXPORT void pgduckdb_background_worker_main(Datum main_arg);

PGDLLEXPORT void
pgduckdb_background_worker_main(Datum main_arg) {
Oid database_oid = DatumGetObjectId(main_arg);
Expand Down Expand Up @@ -369,7 +372,7 @@ ShmemStartup(void) {

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

bool
static bool
HasBgwRunningForMyDatabase() {
const auto num_backends = pgstat_fetch_stat_numbackends();
for (int backend_idx = 1; backend_idx <= num_backends; ++backend_idx) {
Expand Down Expand Up @@ -545,7 +548,7 @@ PossiblyReuseBgwSessionHint(void) {
bool doing_motherduck_sync;
char *current_motherduck_catalog_version;

std::string
static std::string
PgSchemaName(const std::string &db_name, const std::string &schema_name, bool is_default_db) {
if (is_default_db) {
/*
Expand All @@ -564,7 +567,7 @@ PgSchemaName(const std::string &db_name, const std::string &schema_name, bool is
return oss.str();
}

std::string
static std::string
DropPgRelationString(const char *postgres_schema_name, const char *relation_name, char relation_kind,
bool with_cascade) {
std::ostringstream oss;
Expand All @@ -584,7 +587,7 @@ DropPgRelationString(const char *postgres_schema_name, const char *relation_name
return oss.str();
}

std::string
static std::string
CreatePgViewString(duckdb::CreateViewInfo &info, bool is_default_db) {
std::ostringstream oss;

Expand Down Expand Up @@ -640,7 +643,7 @@ CreatePgViewString(duckdb::CreateViewInfo &info, bool is_default_db) {
return oss.str();
}

std::string
static std::string
CreatePgTableString(duckdb::CreateTableInfo &info, bool is_default_db) {
std::ostringstream oss;

Expand Down Expand Up @@ -702,7 +705,7 @@ CreatePgSchemaString(std::string postgres_schema_name) {
* See the following thread for details:
* https://www.postgresql.org/message-id/flat/CAFcNs%2Bp%2BfD5HEXEiZMZC1COnXkJCMnUK0%3Dr4agmZP%3D9Hi%2BYcJA%40mail.gmail.com
*/
void
static void
SPI_commit_that_works_in_bgworker() {
if (is_background_worker) {
SPI_finish();
Expand Down
2 changes: 1 addition & 1 deletion src/pgduckdb_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ DuckdbTruncateTable(Oid relation_oid) {
* ONCOMMIT_DROP, but this will also handle any new ON COMMIT clauses that
* might be added to Postgres in future releases.
*/
void
static void
CheckOnCommitSupport(OnCommitAction on_commit) {
switch (on_commit) {
case ONCOMMIT_NOOP:
Expand Down
6 changes: 3 additions & 3 deletions src/pgduckdb_detoast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C" {

namespace pgduckdb {

struct varlena *
static struct varlena *
PglzDecompressDatum(const struct varlena *value) {
struct varlena *result = (struct varlena *)duckdb_malloc(VARDATA_COMPRESSED_GET_EXTSIZE(value) + VARHDRSZ);

Expand All @@ -49,7 +49,7 @@ PglzDecompressDatum(const struct varlena *value) {
return result;
}

struct varlena *
static struct varlena *
Lz4DecompresDatum(const struct varlena *value) {
#ifndef USE_LZ4
(void)value; /* keep compiler quiet */
Expand Down Expand Up @@ -84,7 +84,7 @@ ToastDecompressDatum(struct varlena *attr) {
}
}

bool
static bool
table_relation_fetch_toast_slice(const struct varatt_external &toast_pointer, int32 attrsize, struct varlena *result) {
Relation toast_rel = try_table_open(toast_pointer.va_toastrelid, AccessShareLock);

Expand Down
4 changes: 2 additions & 2 deletions src/pgduckdb_duckdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {

namespace pgduckdb {

const char *
static const char *
GetSessionHint() {
if (!IsEmptyString(duckdb_motherduck_session_hint)) {
return duckdb_motherduck_session_hint;
Expand Down Expand Up @@ -231,7 +231,7 @@ DuckDBManager::Reset() {
UnclaimBgwSessionHint();
}

int64
static int64
GetSeqLastValue(const char *seq_name) {
Oid duckdb_namespace = get_namespace_oid("duckdb", false);
Oid table_seq_oid = get_relname_relid(seq_name, duckdb_namespace);
Expand Down
Loading