Skip to content
Merged
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: 3 additions & 2 deletions .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Setup vcpkg
uses: lukka/run-vcpkg@v11.1
with:
vcpkgGitCommitId: a42af01b72c28a8e1d7b48107b33e4f286a55ef6
vcpkgGitCommitId: 84bab45d415d22042bd0b9081aea57f362da3f35

- name: Build extension
env:
Expand All @@ -92,8 +92,9 @@ jobs:
- name: Test extension
env:
POSTGRES_TEST_DATABASE_AVAILABLE: 1
LOCAL_EXTENSION_REPO: 'build/reldebug/repository'
PGSERVICE: postgres
run: |
psql -c "SELECT 43"
source ./create-postgres-tables.sh
make test_reldebug
./build/reldebug/test/unittest --autoloading available
12 changes: 6 additions & 6 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ concurrency:
jobs:
duckdb-stable-build:
name: Build extension binaries
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.4.2
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
with:
duckdb_version: v1.4.2
ci_tools_version: v1.4.2
duckdb_version: 2323327f4
ci_tools_version: main
extension_name: postgres_scanner
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_mingw'

duckdb-stable-deploy:
name: Deploy extension binaries
needs: duckdb-stable-build
uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@v1.4.2
uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@main
secrets: inherit
with:
duckdb_version: v1.4.2
ci_tools_version: v1.4.2
duckdb_version: 2323327f4
ci_tools_version: main
extension_name: postgres_scanner
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_mingw'
deploy_latest: ${{ startsWith(github.ref, 'refs/heads/v') || github.ref == 'refs/heads/main' }}
2 changes: 1 addition & 1 deletion duckdb
Submodule duckdb updated 3556 files
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ add_library(
postgres_scanner.cpp
postgres_storage.cpp
postgres_text_reader.cpp
postgres_utils.cpp)
postgres_utils.cpp
postgres_logging.cpp)
set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:postgres_ext_library>
PARENT_SCOPE)
2 changes: 1 addition & 1 deletion src/include/postgres_binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
~PostgresBinaryReader() override;

public:
void BeginCopy(const string &sql) override;
void BeginCopy(ClientContext &context, const string &sql) override;
PostgresReadResult Read(DataChunk &result) override;

protected:
Expand All @@ -41,7 +41,7 @@
} else if (sizeof(T) == sizeof(uint32_t)) {
val = ntohl(val);
} else if (sizeof(T) == sizeof(uint64_t)) {
val = ntohll(val);

Check warning on line 44 in src/include/postgres_binary_reader.hpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / Windows (windows_amd64, windows-latest, x64-windows-static-release, x64-windows-static-release, t...

'>>': shift count negative or too big, undefined behavior

Check warning on line 44 in src/include/postgres_binary_reader.hpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / Windows (windows_amd64, windows-latest, x64-windows-static-release, x64-windows-static-release, t...

'>>': shift count negative or too big, undefined behavior

Check warning on line 44 in src/include/postgres_binary_reader.hpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / Windows (windows_amd64, windows-latest, x64-windows-static-release, x64-windows-static-release, t...

'>>': shift count negative or too big, undefined behavior
} else {
D_ASSERT(0);
}
Expand Down
14 changes: 7 additions & 7 deletions src/include/postgres_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class PostgresConnection {

public:
static PostgresConnection Open(const string &dsn, const string &attach_path);
void Execute(const string &query);
unique_ptr<PostgresResult> TryQuery(const string &query, optional_ptr<string> error_message = nullptr);
unique_ptr<PostgresResult> Query(const string &query);
void Execute(optional_ptr<ClientContext> context, const string &query);
unique_ptr<PostgresResult> TryQuery(optional_ptr<ClientContext> context, const string &query, optional_ptr<string> error_message = nullptr);
unique_ptr<PostgresResult> Query(optional_ptr<ClientContext> context, const string &query);

//! Submits a set of queries to be executed in the connection.
vector<unique_ptr<PostgresResult>> ExecuteQueries(const string &queries);
vector<unique_ptr<PostgresResult>> ExecuteQueries(ClientContext &context, const string &queries);

PostgresVersion GetPostgresVersion();
PostgresVersion GetPostgresVersion(ClientContext &context);

vector<IndexInfo> GetIndexInfo(const string &table_name);

Expand All @@ -64,7 +64,7 @@ class PostgresConnection {
void CopyChunk(ClientContext &context, PostgresCopyState &state, DataChunk &chunk, DataChunk &varchar_chunk);
void FinishCopyTo(PostgresCopyState &state);

void BeginCopyFrom(const string &query, ExecStatusType expected_result);
void BeginCopyFrom(ClientContext &context, const string &query, ExecStatusType expected_result);

bool IsOpen();
void Close();
Expand All @@ -87,7 +87,7 @@ class PostgresConnection {
static bool DebugPrintQueries();

private:
PGresult *PQExecute(const string &query);
PGresult *PQExecute(optional_ptr<ClientContext> context, const string &query);

shared_ptr<OwnedPostgresConnection> connection;
string dsn;
Expand Down
20 changes: 20 additions & 0 deletions src/include/postgres_logging.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#pragma once

#include "duckdb/logging/logging.hpp"
#include "duckdb/common/string_util.hpp"

namespace duckdb {

class PostgresQueryLogType : public LogType {
public:
static constexpr const char *NAME = "PostgresQueryLog";
static constexpr LogLevel LEVEL = LogLevel::LOG_DEBUG;

PostgresQueryLogType() : LogType(NAME, LEVEL, GetLogType()) {};

static string ConstructLogMessage(const string &str, int64_t duration);
static LogicalType GetLogType();
};

} // namespace
2 changes: 1 addition & 1 deletion src/include/postgres_result_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct PostgresResultReader {
}

public:
virtual void BeginCopy(const string &sql) = 0;
virtual void BeginCopy(ClientContext &context, const string &sql) = 0;
virtual PostgresReadResult Read(DataChunk &result) = 0;

protected:
Expand Down
2 changes: 1 addition & 1 deletion src/include/postgres_text_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct PostgresTextReader : public PostgresResultReader {
~PostgresTextReader() override;

public:
void BeginCopy(const string &sql) override;
void BeginCopy(ClientContext &context, const string &sql) override;
PostgresReadResult Read(DataChunk &result) override;

private:
Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/postgres_catalog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PostgresSchemaEntry;
class PostgresCatalog : public Catalog {
public:
explicit PostgresCatalog(AttachedDatabase &db_p, string connection_string, string attach_path,
AccessMode access_mode, string schema_to_load, PostgresIsolationLevel isolation_level);
AccessMode access_mode, string schema_to_load, PostgresIsolationLevel isolation_level, ClientContext &context);
~PostgresCatalog();

string connection_string;
Expand Down
8 changes: 4 additions & 4 deletions src/include/storage/postgres_catalog_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class PostgresCatalogSet {
public:
PostgresCatalogSet(Catalog &catalog, bool is_loaded);

optional_ptr<CatalogEntry> GetEntry(PostgresTransaction &transaction, const string &name);
optional_ptr<CatalogEntry> GetEntry(ClientContext &context, PostgresTransaction &transaction, const string &name);
void DropEntry(PostgresTransaction &transaction, DropInfo &info);
void Scan(PostgresTransaction &transaction, const std::function<void(CatalogEntry &)> &callback);
void Scan(ClientContext& context, PostgresTransaction &transaction, const std::function<void(CatalogEntry &)> &callback);
virtual optional_ptr<CatalogEntry> CreateEntry(PostgresTransaction &transaction, shared_ptr<CatalogEntry> entry);
void ClearEntries();
virtual bool SupportReload() const {
Expand All @@ -34,13 +34,13 @@ class PostgresCatalogSet {
virtual optional_ptr<CatalogEntry> ReloadEntry(PostgresTransaction &transaction, const string &name);

protected:
virtual void LoadEntries(PostgresTransaction &transaction) = 0;
virtual void LoadEntries(ClientContext &context, PostgresTransaction &transaction) = 0;
//! Whether or not the catalog set contains dependencies to itself that have
//! to be resolved WHILE loading
virtual bool HasInternalDependencies() const {
return false;
}
void TryLoadEntries(PostgresTransaction &transaction);
void TryLoadEntries(ClientContext &context, PostgresTransaction &transaction);

protected:
Catalog &catalog;
Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/postgres_delete.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PostgresDelete : public PhysicalOperator {

public:
// Source interface
SourceResultType GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override;
SourceResultType GetDataInternal(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override;

bool IsSource() const override {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/postgres_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PostgresCreateIndex : public PhysicalOperator {

public:
// Source interface
SourceResultType GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override;
SourceResultType GetDataInternal(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override;

bool IsSource() const override {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/postgres_index_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PostgresIndexSet : public PostgresInSchemaSet {
TableCatalogEntry &table);

protected:
void LoadEntries(PostgresTransaction &transaction) override;
void LoadEntries(ClientContext &context, PostgresTransaction &transaction) override;

protected:
unique_ptr<PostgresResultSlice> index_result;
Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/postgres_insert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PostgresInsert : public PhysicalOperator {

public:
// Source interface
SourceResultType GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override;
SourceResultType GetDataInternal(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override;

bool IsSource() const override {
return true;
Expand Down
1 change: 1 addition & 0 deletions src/include/storage/postgres_optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "duckdb/main/config.hpp"
#include "duckdb/optimizer/optimizer_extension.hpp"

namespace duckdb {

Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/postgres_schema_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PostgresSchemaSet : public PostgresCatalogSet {
static string GetInitializeQuery(const string &schema = string());

protected:
void LoadEntries(PostgresTransaction &transaction) override;
void LoadEntries(ClientContext &context, PostgresTransaction &transaction) override;

protected:
//! Schema to load - if empty loads all schemas (default behavior)
Expand Down
16 changes: 8 additions & 8 deletions src/include/storage/postgres_table_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ class PostgresTableSet : public PostgresInSchemaSet {

static unique_ptr<PostgresTableInfo> GetTableInfo(PostgresTransaction &transaction, PostgresSchemaEntry &schema,
const string &table_name);
static unique_ptr<PostgresTableInfo> GetTableInfo(PostgresConnection &connection, const string &schema_name,
static unique_ptr<PostgresTableInfo> GetTableInfo(ClientContext &context, PostgresConnection &connection, const string &schema_name,
const string &table_name);
optional_ptr<CatalogEntry> ReloadEntry(PostgresTransaction &transaction, const string &table_name) override;

void AlterTable(PostgresTransaction &transaction, AlterTableInfo &info);
void AlterTable(ClientContext &context, PostgresTransaction &transaction, AlterTableInfo &info);

static string GetInitializeQuery(const string &schema = string(), const string &table = string());

protected:
void LoadEntries(PostgresTransaction &transaction) override;
void LoadEntries(ClientContext &context, PostgresTransaction &transaction) override;
bool SupportReload() const override {
return true;
}

void AlterTable(PostgresTransaction &transaction, RenameTableInfo &info);
void AlterTable(PostgresTransaction &transaction, RenameColumnInfo &info);
void AlterTable(PostgresTransaction &transaction, AddColumnInfo &info);
void AlterTable(PostgresTransaction &transaction, RemoveColumnInfo &info);
void AlterTable(ClientContext &context, PostgresTransaction &transaction, RenameTableInfo &info);
void AlterTable(ClientContext &context, PostgresTransaction &transaction, RenameColumnInfo &info);
void AlterTable(ClientContext &context, PostgresTransaction &transaction, AddColumnInfo &info);
void AlterTable(ClientContext &context, PostgresTransaction &transaction, RemoveColumnInfo &info);

static void AddColumn(optional_ptr<PostgresTransaction> transaction, optional_ptr<PostgresSchemaEntry> schema,
PostgresResult &result, idx_t row, PostgresTableInfo &table_info);
Expand All @@ -55,7 +55,7 @@ class PostgresTableSet : public PostgresInSchemaSet {
void CreateEntries(PostgresTransaction &transaction, PostgresResult &result, idx_t start, idx_t end);

private:
string GetAlterTablePrefix(PostgresTransaction &transaction, const string &name);
string GetAlterTablePrefix(ClientContext &context, PostgresTransaction &transaction, const string &name);
string GetAlterTablePrefix(const string &name, optional_ptr<CatalogEntry> entry);
string GetAlterTableColumnName(const string &name, optional_ptr<CatalogEntry> entry);

Expand Down
4 changes: 2 additions & 2 deletions src/include/storage/postgres_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class PostgresTransaction : public Transaction {

PostgresConnection &GetConnectionWithoutTransaction();
PostgresConnection &GetConnection();
ClientContext &GetContext();
optional_ptr<ClientContext> GetContext();

string GetDSN();
unique_ptr<PostgresResult> Query(const string &query);
unique_ptr<PostgresResult> QueryWithoutTransaction(const string &query);
vector<unique_ptr<PostgresResult>> ExecuteQueries(const string &queries);
vector<unique_ptr<PostgresResult>> ExecuteQueries(ClientContext &context, const string &queries);
static PostgresTransaction &Get(ClientContext &context, Catalog &catalog);

optional_ptr<CatalogEntry> ReferenceEntry(shared_ptr<CatalogEntry> &entry);
Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/postgres_type_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PostgresTypeSet : public PostgresInSchemaSet {
// composite types can refer to other types
return true;
}
void LoadEntries(PostgresTransaction &transaction) override;
void LoadEntries(ClientContext &context, PostgresTransaction &transaction) override;

void CreateEnum(PostgresTransaction &transaction, PostgresResult &result, idx_t start_row, idx_t end_row);
void CreateCompositeType(PostgresTransaction &transaction, PostgresResult &result, idx_t start_row, idx_t end_row);
Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/postgres_update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PostgresUpdate : public PhysicalOperator {

public:
// Source interface
SourceResultType GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override;
SourceResultType GetDataInternal(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override;

bool IsSource() const override {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/postgres_attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GROUP BY relname
ORDER BY relname;
)",
KeywordHelper::WriteQuoted(data.source_schema));
auto res = conn.Query(fetch_table_query);
auto res = conn.Query(context, fetch_table_query);
for (idx_t row = 0; row < PQntuples(res->res); row++) {
auto table_name = res->GetString(row, 0);
string query;
Expand Down
4 changes: 2 additions & 2 deletions src/postgres_binary_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ PostgresBinaryReader::~PostgresBinaryReader() {
Reset();
}

void PostgresBinaryReader::BeginCopy(const string &sql) {
con.BeginCopyFrom(sql, PGRES_COPY_OUT);
void PostgresBinaryReader::BeginCopy(ClientContext &context, const string &sql) {
con.BeginCopyFrom(context, sql, PGRES_COPY_OUT);
if (!Next()) {
throw IOException("Failed to fetch header for COPY \"%s\"", sql);
}
Expand Down
Loading
Loading