Skip to content

Commit 9453084

Browse files
authored
Merge pull request #140 from Mytherin/aurorafix
Detect that we are connected with Aurora, and avoid running snapshot code with Aurora in general
2 parents cd6d147 + 66ece59 commit 9453084

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/include/postgres_version.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace duckdb {
1414

15+
enum class PostgresInstanceType { POSTGRES, AURORA };
16+
1517
struct PostgresVersion {
1618
PostgresVersion() {
1719
}
@@ -22,6 +24,7 @@ struct PostgresVersion {
2224
idx_t major_v = 0;
2325
idx_t minor_v = 0;
2426
idx_t patch_v = 0;
27+
PostgresInstanceType type_v = PostgresInstanceType::POSTGRES;
2528

2629
inline bool operator<(const PostgresVersion &rhs) const {
2730
if (major_v < rhs.major_v) {

src/postgres_connection.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ void PostgresConnection::Execute(const string &query) {
8080
}
8181

8282
PostgresVersion PostgresConnection::GetPostgresVersion() {
83-
auto result = Query("SHOW server_version;");
83+
auto result = Query("SELECT CURRENT_SETTING('server_version'), (SELECT COUNT(*) FROM pg_settings WHERE name LIKE 'rds%')");
8484
auto version = PostgresUtils::ExtractPostgresVersion(result->GetString(0, 0));
85+
if (result->GetInt64(0, 1) > 0) {
86+
version.type_v = PostgresInstanceType::AURORA;
87+
}
8588
return version;
8689
}
8790

src/postgres_scanner.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ static void PostgresGetSnapshot(PostgresVersion version, PostgresBindData &bind_
5151
unique_ptr<PostgresResult> result;
5252
// by default disable snapshotting
5353
bind_data.snapshot = string();
54+
if (version.type_v == PostgresInstanceType::AURORA) {
55+
return;
56+
}
5457
// reader threads can use the same snapshot
5558
auto &con = bind_data.connection;
5659
// pg_stat_wal_receiver was introduced in PostgreSQL 9.6
@@ -275,11 +278,12 @@ static unique_ptr<LocalTableFunctionState> GetLocalState(ClientContext &context,
275278
}
276279
local_state->column_ids = input.column_ids;
277280

278-
if (!bind_data.read_only) {
281+
if (bind_data.read_only && bind_data.max_threads > 1) {
282+
local_state->connection = PostgresScanConnect(bind_data.dsn, bind_data.snapshot);
283+
} else {
279284
// if we have made other modifications in this transaction we have to use the main connection
285+
// alternatively, if we are only using a single thread to scan, we use the current connection as well
280286
local_state->connection = PostgresConnection(bind_data.connection.GetConnection());
281-
} else {
282-
local_state->connection = PostgresScanConnect(bind_data.dsn, bind_data.snapshot);
283287
}
284288
local_state->filters = input.filters.get();
285289
if (bind_data.pages_approx == 0 || bind_data.requires_materialization) {

0 commit comments

Comments
 (0)