-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multi-statement transactions
Only supports multi-statement transactions for non-DDL queries.
- Loading branch information
Showing
25 changed files
with
888 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include "pgduckdb/pg/declarations.hpp" | ||
|
||
extern "C" { | ||
extern bool IsSubTransaction(void); | ||
|
||
/* | ||
* These enum definitions are vendored in so we can implement a postgres | ||
* XactCallback in C++. It's not expected that these will ever change. | ||
*/ | ||
typedef enum { | ||
XACT_EVENT_COMMIT, | ||
XACT_EVENT_PARALLEL_COMMIT, | ||
XACT_EVENT_ABORT, | ||
XACT_EVENT_PARALLEL_ABORT, | ||
XACT_EVENT_PREPARE, | ||
XACT_EVENT_PRE_COMMIT, | ||
XACT_EVENT_PARALLEL_PRE_COMMIT, | ||
XACT_EVENT_PRE_PREPARE, | ||
} XactEvent; | ||
|
||
typedef void (*XactCallback)(XactEvent event, void *arg); | ||
|
||
typedef enum { | ||
SUBXACT_EVENT_START_SUB, | ||
SUBXACT_EVENT_COMMIT_SUB, | ||
SUBXACT_EVENT_ABORT_SUB, | ||
SUBXACT_EVENT_PRE_COMMIT_SUB, | ||
} SubXactEvent; | ||
|
||
typedef void (*SubXactCallback)(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg); | ||
} | ||
|
||
namespace pgduckdb { | ||
bool PostgresDidWalWrites(); | ||
CommandId GetCurrentCommandId(bool used = false); | ||
bool IsInTransactionBlock(bool top_level); | ||
void PreventInTransactionBlock(bool is_top_level, const char *statement_type); | ||
void RegisterXactCallback(XactCallback callback, void *arg); | ||
void UnregisterXactCallback(XactCallback callback, void *arg); | ||
void RegisterSubXactCallback(SubXactCallback callback, void *arg); | ||
void UnregisterSubXactCallback(SubXactCallback callback, void *arg); | ||
} // namespace pgduckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
namespace pgduckdb { | ||
void ClaimCurrentCommandId(); | ||
void RegisterDuckdbXactCallback(); | ||
} | ||
void UnregisterDuckdbXactCallback(); | ||
void AutocommitSingleStatementQueries(); | ||
void MarkStatementNotTopLevel(); | ||
bool IsInTransactionBlock(); | ||
void PreventInTransactionBlock(const char *statement_type); | ||
} // namespace pgduckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "pgduckdb/pgduckdb_utils.hpp" | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
#include "access/xact.h" // RegisterXactCallback, XactEvent, SubXactEvent, SubTransactionId | ||
#include "access/xlog.h" // XactLastRecEnd | ||
} | ||
|
||
namespace pgduckdb { | ||
|
||
bool | ||
PostgresDidWalWrites() { | ||
return XactLastRecEnd != InvalidXLogRecPtr; | ||
} | ||
|
||
CommandId | ||
GetCurrentCommandId(bool used = false) { | ||
return PostgresFunctionGuard(::GetCurrentCommandId, used); | ||
} | ||
|
||
bool | ||
IsInTransactionBlock(bool is_top_level) { | ||
return PostgresFunctionGuard(::IsInTransactionBlock, is_top_level); | ||
} | ||
|
||
void | ||
PreventInTransactionBlock(bool is_top_level, const char *statement_type) { | ||
return PostgresFunctionGuard(::PreventInTransactionBlock, is_top_level, statement_type); | ||
} | ||
|
||
void | ||
RegisterXactCallback(XactCallback callback, void *arg) { | ||
return PostgresFunctionGuard(::RegisterXactCallback, callback, arg); | ||
} | ||
|
||
void | ||
UnregisterXactCallback(XactCallback callback, void *arg) { | ||
return PostgresFunctionGuard(::UnregisterXactCallback, callback, arg); | ||
} | ||
|
||
void | ||
RegisterSubXactCallback(SubXactCallback callback, void *arg) { | ||
return PostgresFunctionGuard(::RegisterSubXactCallback, callback, arg); | ||
} | ||
|
||
void | ||
UnregisterSubXactCallback(SubXactCallback callback, void *arg) { | ||
return PostgresFunctionGuard(::UnregisterSubXactCallback, callback, arg); | ||
} | ||
|
||
} // namespace pgduckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.