-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:Leo-XM-Zeng/pg_duckdb into pg_duckd…
…b_15
- Loading branch information
Showing
40 changed files
with
1,472 additions
and
225 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
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,55 @@ | ||
#pragma once | ||
|
||
#include "duckdb/storage/storage_extension.hpp" | ||
#include "duckdb/catalog/catalog.hpp" | ||
#include "pgduckdb/catalog/pgduckdb_schema.hpp" | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
#include "miscadmin.h" | ||
#include "utils/snapshot.h" | ||
} | ||
|
||
namespace duckdb { | ||
|
||
class PostgresCatalog : public Catalog { | ||
public: | ||
PostgresCatalog(AttachedDatabase &db, const string &connection_string, AccessMode access_mode); | ||
|
||
public: | ||
static unique_ptr<Catalog> Attach(StorageExtensionInfo *storage_info, ClientContext &context, AttachedDatabase &db, | ||
const string &name, AttachInfo &info, AccessMode access_mode); | ||
|
||
public: | ||
string path; | ||
AccessMode access_mode; | ||
|
||
public: | ||
// -- Catalog API -- | ||
void Initialize(bool load_builtin) override; | ||
string GetCatalogType() override; | ||
optional_ptr<CatalogEntry> CreateSchema(CatalogTransaction transaction, CreateSchemaInfo &info) override; | ||
optional_ptr<SchemaCatalogEntry> GetSchema(CatalogTransaction transaction, const string &schema_name, | ||
OnEntryNotFound if_not_found, | ||
QueryErrorContext error_context = QueryErrorContext()) override; | ||
void ScanSchemas(ClientContext &context, std::function<void(SchemaCatalogEntry &)> callback) override; | ||
unique_ptr<PhysicalOperator> PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op, | ||
unique_ptr<PhysicalOperator> plan) override; | ||
unique_ptr<PhysicalOperator> PlanInsert(ClientContext &context, LogicalInsert &op, | ||
unique_ptr<PhysicalOperator> plan) override; | ||
unique_ptr<PhysicalOperator> PlanDelete(ClientContext &context, LogicalDelete &op, | ||
unique_ptr<PhysicalOperator> plan) override; | ||
unique_ptr<PhysicalOperator> PlanUpdate(ClientContext &context, LogicalUpdate &op, | ||
unique_ptr<PhysicalOperator> plan) override; | ||
unique_ptr<LogicalOperator> BindCreateIndex(Binder &binder, CreateStatement &stmt, TableCatalogEntry &table, | ||
unique_ptr<LogicalOperator> plan) override; | ||
DatabaseSize GetDatabaseSize(ClientContext &context) override; | ||
bool InMemory() override; | ||
string GetDBPath() override; | ||
void DropSchema(ClientContext &context, DropInfo &info) override; | ||
|
||
private: | ||
case_insensitive_map_t<unique_ptr<PostgresSchema>> schemas; | ||
}; | ||
|
||
} // namespace duckdb |
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,46 @@ | ||
#pragma once | ||
|
||
#include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp" | ||
#include "pgduckdb/catalog/pgduckdb_table.hpp" | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
#include "miscadmin.h" | ||
#include "utils/snapshot.h" | ||
#include "nodes/pathnodes.h" | ||
} | ||
|
||
namespace duckdb { | ||
|
||
class PostgresSchema : public SchemaCatalogEntry { | ||
public: | ||
PostgresSchema(Catalog &catalog, CreateSchemaInfo &info, Snapshot snapshot); | ||
|
||
public: | ||
// -- Schema API -- | ||
void Scan(ClientContext &context, CatalogType type, const std::function<void(CatalogEntry &)> &callback) override; | ||
void Scan(CatalogType type, const std::function<void(CatalogEntry &)> &callback) override; | ||
optional_ptr<CatalogEntry> CreateIndex(CatalogTransaction transaction, CreateIndexInfo &info, | ||
TableCatalogEntry &table) override; | ||
optional_ptr<CatalogEntry> CreateFunction(CatalogTransaction transaction, CreateFunctionInfo &info) override; | ||
optional_ptr<CatalogEntry> CreateTable(CatalogTransaction transaction, BoundCreateTableInfo &info) override; | ||
optional_ptr<CatalogEntry> CreateView(CatalogTransaction transaction, CreateViewInfo &info) override; | ||
optional_ptr<CatalogEntry> CreateSequence(CatalogTransaction transaction, CreateSequenceInfo &info) override; | ||
optional_ptr<CatalogEntry> CreateTableFunction(CatalogTransaction transaction, | ||
CreateTableFunctionInfo &info) override; | ||
optional_ptr<CatalogEntry> CreateCopyFunction(CatalogTransaction transaction, | ||
CreateCopyFunctionInfo &info) override; | ||
optional_ptr<CatalogEntry> CreatePragmaFunction(CatalogTransaction transaction, | ||
CreatePragmaFunctionInfo &info) override; | ||
optional_ptr<CatalogEntry> CreateCollation(CatalogTransaction transaction, CreateCollationInfo &info) override; | ||
optional_ptr<CatalogEntry> CreateType(CatalogTransaction transaction, CreateTypeInfo &info) override; | ||
optional_ptr<CatalogEntry> GetEntry(CatalogTransaction transaction, CatalogType type, const string &name) override; | ||
void DropEntry(ClientContext &context, DropInfo &info) override; | ||
void Alter(CatalogTransaction transaction, AlterInfo &info) override; | ||
|
||
public: | ||
Snapshot snapshot; | ||
Catalog &catalog; | ||
}; | ||
|
||
} // namespace duckdb |
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,27 @@ | ||
#pragma once | ||
|
||
#include "duckdb/storage/storage_extension.hpp" | ||
extern "C" { | ||
#include "postgres.h" | ||
#include "miscadmin.h" | ||
#include "utils/snapshot.h" | ||
#include "nodes/pathnodes.h" | ||
} | ||
|
||
namespace duckdb { | ||
|
||
class PostgresStorageExtensionInfo : public StorageExtensionInfo { | ||
public: | ||
PostgresStorageExtensionInfo(Snapshot snapshot) : snapshot(snapshot) { | ||
} | ||
|
||
public: | ||
Snapshot snapshot; | ||
}; | ||
|
||
class PostgresStorageExtension : public StorageExtension { | ||
public: | ||
PostgresStorageExtension(Snapshot snapshot); | ||
}; | ||
|
||
} // namespace duckdb |
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,71 @@ | ||
#pragma once | ||
|
||
#include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp" | ||
#include "duckdb/storage/table_storage_info.hpp" | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
#include "utils/snapshot.h" | ||
#include "postgres.h" | ||
#include "catalog/namespace.h" | ||
#include "catalog/pg_class.h" | ||
#include "optimizer/planmain.h" | ||
#include "optimizer/planner.h" | ||
#include "utils/builtins.h" | ||
#include "utils/regproc.h" | ||
#include "utils/snapmgr.h" | ||
#include "utils/syscache.h" | ||
#include "access/htup_details.h" | ||
} | ||
|
||
namespace duckdb { | ||
|
||
class PostgresTable : public TableCatalogEntry { | ||
public: | ||
virtual ~PostgresTable() { | ||
} | ||
|
||
public: | ||
static bool PopulateColumns(CreateTableInfo &info, Oid relid, Snapshot snapshot); | ||
|
||
protected: | ||
PostgresTable(Catalog &catalog, SchemaCatalogEntry &schema, CreateTableInfo &info, Cardinality cardinality, | ||
Snapshot snapshot); | ||
|
||
protected: | ||
Cardinality cardinality; | ||
Snapshot snapshot; | ||
}; | ||
|
||
class PostgresHeapTable : public PostgresTable { | ||
public: | ||
PostgresHeapTable(Catalog &catalog, SchemaCatalogEntry &schema, CreateTableInfo &info, Cardinality cardinality, | ||
Snapshot snapshot, Oid oid); | ||
|
||
public: | ||
// -- Table API -- | ||
unique_ptr<BaseStatistics> GetStatistics(ClientContext &context, column_t column_id) override; | ||
TableFunction GetScanFunction(ClientContext &context, unique_ptr<FunctionData> &bind_data) override; | ||
TableStorageInfo GetStorageInfo(ClientContext &context) override; | ||
|
||
private: | ||
Oid oid; | ||
}; | ||
|
||
class PostgresIndexTable : public PostgresTable { | ||
public: | ||
PostgresIndexTable(Catalog &catalog, SchemaCatalogEntry &schema, CreateTableInfo &info, Cardinality cardinality, | ||
Snapshot snapshot, Path *path, PlannerInfo *planner_info); | ||
|
||
public: | ||
// -- Table API -- | ||
unique_ptr<BaseStatistics> GetStatistics(ClientContext &context, column_t column_id) override; | ||
TableFunction GetScanFunction(ClientContext &context, unique_ptr<FunctionData> &bind_data) override; | ||
TableStorageInfo GetStorageInfo(ClientContext &context) override; | ||
|
||
private: | ||
Path *path; | ||
PlannerInfo *planner_info; | ||
}; | ||
|
||
} // namespace duckdb |
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,43 @@ | ||
#pragma once | ||
|
||
#include "duckdb/transaction/transaction.hpp" | ||
#include "pgduckdb/catalog/pgduckdb_table.hpp" | ||
#include "pgduckdb/catalog/pgduckdb_schema.hpp" | ||
|
||
namespace duckdb { | ||
|
||
class PostgresCatalog; | ||
|
||
class SchemaItems { | ||
public: | ||
SchemaItems(unique_ptr<PostgresSchema> &&schema, const string &name) : name(name), schema(std::move(schema)) { | ||
} | ||
|
||
public: | ||
optional_ptr<CatalogEntry> GetTable(const string &name, PlannerInfo *planner_info); | ||
|
||
public: | ||
string name; | ||
unique_ptr<PostgresSchema> schema; | ||
case_insensitive_map_t<unique_ptr<PostgresTable>> tables; | ||
}; | ||
|
||
class PostgresTransaction : public Transaction { | ||
public: | ||
PostgresTransaction(TransactionManager &manager, ClientContext &context, PostgresCatalog &catalog, | ||
Snapshot snapshot); | ||
~PostgresTransaction() override; | ||
|
||
public: | ||
optional_ptr<CatalogEntry> GetCatalogEntry(CatalogType type, const string &schema, const string &name); | ||
|
||
private: | ||
optional_ptr<CatalogEntry> GetSchema(const string &name); | ||
|
||
private: | ||
case_insensitive_map_t<SchemaItems> schemas; | ||
PostgresCatalog &catalog; | ||
Snapshot snapshot; | ||
}; | ||
|
||
} // namespace duckdb |
Oops, something went wrong.