From e53141cac0b344f77fc63b89b562eb21bb446faf Mon Sep 17 00:00:00 2001 From: Mytherin Date: Sat, 3 May 2025 18:11:57 +0200 Subject: [PATCH 1/6] WIP: bump to main --- duckdb | 2 +- src/include/storage/postgres_catalog.hpp | 24 +++--- src/include/storage/postgres_schema_entry.hpp | 2 +- src/storage/postgres_catalog.cpp | 10 +-- src/storage/postgres_delete.cpp | 11 ++- src/storage/postgres_index.cpp | 4 +- src/storage/postgres_insert.cpp | 82 +++++++++---------- src/storage/postgres_schema_entry.cpp | 8 +- src/storage/postgres_update.cpp | 12 +-- test/sql/scanner/daterange_array.test | 2 +- test/sql/storage/attach_types.test | 4 +- test/sql/storage/attach_types_lists.test | 34 ++++---- test/sql/storage/attach_types_macaddr.test | 2 +- test/sql/storage/attach_types_struct.test | 6 +- 14 files changed, 100 insertions(+), 103 deletions(-) diff --git a/duckdb b/duckdb index 8e52ec43..a35d8b6d 160000 --- a/duckdb +++ b/duckdb @@ -1 +1 @@ -Subproject commit 8e52ec43959ab363643d63cb78ee214577111da4 +Subproject commit a35d8b6d5ba121f2601b917e1a7732207c944ae5 diff --git a/src/include/storage/postgres_catalog.hpp b/src/include/storage/postgres_catalog.hpp index 2935c56c..b7635823 100644 --- a/src/include/storage/postgres_catalog.hpp +++ b/src/include/storage/postgres_catalog.hpp @@ -40,18 +40,18 @@ class PostgresCatalog : public Catalog { void ScanSchemas(ClientContext &context, std::function callback) override; - optional_ptr GetSchema(CatalogTransaction transaction, const string &schema_name, - OnEntryNotFound if_not_found, - QueryErrorContext error_context = QueryErrorContext()) override; - - unique_ptr PlanInsert(ClientContext &context, LogicalInsert &op, - unique_ptr plan) override; - unique_ptr PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op, - unique_ptr plan) override; - unique_ptr PlanDelete(ClientContext &context, LogicalDelete &op, - unique_ptr plan) override; - unique_ptr PlanUpdate(ClientContext &context, LogicalUpdate &op, - unique_ptr plan) override; + optional_ptr LookupSchema(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup, + OnEntryNotFound if_not_found) override; + + PhysicalOperator &PlanCreateTableAs(ClientContext &context, PhysicalPlanGenerator &planner, LogicalCreateTable &op, + PhysicalOperator &plan) override; + PhysicalOperator &PlanInsert(ClientContext &context, PhysicalPlanGenerator &planner, LogicalInsert &op, + optional_ptr plan) override; + PhysicalOperator &PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op, + PhysicalOperator &plan) override; + PhysicalOperator &PlanUpdate(ClientContext &context, PhysicalPlanGenerator &planner, LogicalUpdate &op, + PhysicalOperator &plan) override; + unique_ptr BindCreateIndex(Binder &binder, CreateStatement &stmt, TableCatalogEntry &table, unique_ptr plan) override; diff --git a/src/include/storage/postgres_schema_entry.hpp b/src/include/storage/postgres_schema_entry.hpp index 0615c9d8..75e23643 100644 --- a/src/include/storage/postgres_schema_entry.hpp +++ b/src/include/storage/postgres_schema_entry.hpp @@ -42,7 +42,7 @@ class PostgresSchemaEntry : public SchemaCatalogEntry { void Scan(ClientContext &context, CatalogType type, const std::function &callback) override; void Scan(CatalogType type, const std::function &callback) override; void DropEntry(ClientContext &context, DropInfo &info) override; - optional_ptr GetEntry(CatalogTransaction transaction, CatalogType type, const string &name) override; + optional_ptr LookupEntry(CatalogTransaction transaction, const EntryLookupInfo &lookup_info) override; static bool SchemaIsInternal(const string &name); diff --git a/src/storage/postgres_catalog.cpp b/src/storage/postgres_catalog.cpp index 2e625565..b7e482b1 100644 --- a/src/storage/postgres_catalog.cpp +++ b/src/storage/postgres_catalog.cpp @@ -138,15 +138,15 @@ void PostgresCatalog::ScanSchemas(ClientContext &context, std::function()); }); } -optional_ptr PostgresCatalog::GetSchema(CatalogTransaction transaction, const string &schema_name, - OnEntryNotFound if_not_found, - QueryErrorContext error_context) { +optional_ptr PostgresCatalog::LookupSchema(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup, + OnEntryNotFound if_not_found) { + auto schema_name = schema_lookup.GetEntryName(); if (schema_name == DEFAULT_SCHEMA) { - return GetSchema(transaction, default_schema, if_not_found, error_context); + schema_name = default_schema; } auto &postgres_transaction = PostgresTransaction::Get(transaction.GetContext(), *this); if (schema_name == "pg_temp") { - return GetSchema(transaction, postgres_transaction.GetTemporarySchema(), if_not_found, error_context); + schema_name = postgres_transaction.GetTemporarySchema(); } auto entry = schemas.GetEntry(transaction.GetContext(), schema_name); if (!entry && if_not_found != OnEntryNotFound::RETURN_NULL) { diff --git a/src/storage/postgres_delete.cpp b/src/storage/postgres_delete.cpp index 97c0f8c9..88dec2ce 100644 --- a/src/storage/postgres_delete.cpp +++ b/src/storage/postgres_delete.cpp @@ -119,17 +119,16 @@ InsertionOrderPreservingMap PostgresDelete::ParamsToString() const { //===--------------------------------------------------------------------===// // Plan //===--------------------------------------------------------------------===// -unique_ptr PostgresCatalog::PlanDelete(ClientContext &context, LogicalDelete &op, - unique_ptr plan) { +PhysicalOperator &PostgresCatalog::PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op, PhysicalOperator &plan) { if (op.return_chunk) { throw BinderException("RETURNING clause not yet supported for deletion of a Postgres table"); } auto &bound_ref = op.expressions[0]->Cast(); - PostgresCatalog::MaterializePostgresScans(*plan); + PostgresCatalog::MaterializePostgresScans(plan); - auto insert = make_uniq(op, op.table, bound_ref.index); - insert->children.push_back(std::move(plan)); - return std::move(insert); + auto &delete_op = planner.Make(op, op.table, bound_ref.index); + delete_op.children.push_back(plan); + return delete_op; } } // namespace duckdb diff --git a/src/storage/postgres_index.cpp b/src/storage/postgres_index.cpp index bfbab3fc..5dd54622 100644 --- a/src/storage/postgres_index.cpp +++ b/src/storage/postgres_index.cpp @@ -56,8 +56,8 @@ class LogicalPostgresCreateIndex : public LogicalExtensionOperator { unique_ptr info; TableCatalogEntry &table; - unique_ptr CreatePlan(ClientContext &context, PhysicalPlanGenerator &generator) override { - return make_uniq(std::move(info), table); + PhysicalOperator &CreatePlan(ClientContext &context, PhysicalPlanGenerator &planner) override { + return planner.Make(std::move(info), table); } void Serialize(Serializer &serializer) const override { diff --git a/src/storage/postgres_insert.cpp b/src/storage/postgres_insert.cpp index f6d5193e..dd616df3 100644 --- a/src/storage/postgres_insert.cpp +++ b/src/storage/postgres_insert.cpp @@ -153,10 +153,10 @@ InsertionOrderPreservingMap PostgresInsert::ParamsToString() const { //===--------------------------------------------------------------------===// // Plan //===--------------------------------------------------------------------===// -unique_ptr AddCastToPostgresTypes(ClientContext &context, unique_ptr plan) { +PhysicalOperator &AddCastToPostgresTypes(ClientContext &context, PhysicalPlanGenerator &planner, PhysicalOperator &plan) { // check if we need to cast anything bool require_cast = false; - auto &child_types = plan->GetTypes(); + auto &child_types = plan.GetTypes(); for (auto &type : child_types) { auto postgres_type = PostgresUtils::ToPostgresType(type); if (postgres_type != type) { @@ -164,30 +164,30 @@ unique_ptr AddCastToPostgresTypes(ClientContext &context, uniq break; } } - if (require_cast) { - vector postgres_types; - vector> select_list; - for (idx_t i = 0; i < child_types.size(); i++) { - auto &type = child_types[i]; - unique_ptr expr; - expr = make_uniq(type, i); - - auto postgres_type = PostgresUtils::ToPostgresType(type); - if (postgres_type != type) { - // add a cast - expr = BoundCastExpression::AddCastToType(context, std::move(expr), postgres_type); - } - postgres_types.push_back(std::move(postgres_type)); - select_list.push_back(std::move(expr)); - } - // we need to cast: add casts - auto proj = make_uniq(std::move(postgres_types), std::move(select_list), - plan->estimated_cardinality); - proj->children.push_back(std::move(plan)); - plan = std::move(proj); - } - - return plan; + if (!require_cast) { + return plan; + } + + vector postgres_types; + vector> select_list; + for (idx_t i = 0; i < child_types.size(); i++) { + auto &type = child_types[i]; + unique_ptr expr; + expr = make_uniq(type, i); + + auto postgres_type = PostgresUtils::ToPostgresType(type); + if (postgres_type != type) { + // add a cast + expr = BoundCastExpression::AddCastToType(context, std::move(expr), postgres_type); + } + postgres_types.push_back(std::move(postgres_type)); + select_list.push_back(std::move(expr)); + } + + // we need to cast: add casts + auto &proj = planner.Make(std::move(postgres_types), std::move(select_list), plan.estimated_cardinality); + proj.children.push_back(plan); + return proj; } bool PostgresCatalog::IsPostgresScan(const string &name) { @@ -206,36 +206,34 @@ void PostgresCatalog::MaterializePostgresScans(PhysicalOperator &op) { } } for (auto &child : op.children) { - MaterializePostgresScans(*child); + MaterializePostgresScans(child); } } -unique_ptr PostgresCatalog::PlanInsert(ClientContext &context, LogicalInsert &op, - unique_ptr plan) { +PhysicalOperator &PostgresCatalog::PlanInsert(ClientContext &context, PhysicalPlanGenerator &planner, LogicalInsert &op, optional_ptr plan) { if (op.return_chunk) { throw BinderException("RETURNING clause not yet supported for insertion into Postgres table"); } if (op.action_type != OnConflictAction::THROW) { throw BinderException("ON CONFLICT clause not yet supported for insertion into Postgres table"); } - MaterializePostgresScans(*plan); - plan = AddCastToPostgresTypes(context, std::move(plan)); + D_ASSERT(plan); + MaterializePostgresScans(*plan); + auto &inner_plan = AddCastToPostgresTypes(context, planner, *plan); - auto insert = make_uniq(op, op.table, op.column_index_map); - insert->children.push_back(std::move(plan)); - return std::move(insert); + auto &insert = planner.Make(op, op.table, op.column_index_map); + insert.children.push_back(inner_plan); + return insert; } -unique_ptr PostgresCatalog::PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op, - unique_ptr plan) { - plan = AddCastToPostgresTypes(context, std::move(plan)); - - MaterializePostgresScans(*plan); +PhysicalOperator &PostgresCatalog::PlanCreateTableAs(ClientContext &context, PhysicalPlanGenerator &planner, LogicalCreateTable &op, PhysicalOperator &plan) { + auto &inner_plan = AddCastToPostgresTypes(context, planner, plan); + MaterializePostgresScans(inner_plan); - auto insert = make_uniq(op, op.schema, std::move(op.info)); - insert->children.push_back(std::move(plan)); - return std::move(insert); + auto &insert = planner.Make(op, op.schema, std::move(op.info)); + insert.children.push_back(inner_plan); + return insert; } } // namespace duckdb diff --git a/src/storage/postgres_schema_entry.cpp b/src/storage/postgres_schema_entry.cpp index 32e2f90c..c1b34918 100644 --- a/src/storage/postgres_schema_entry.cpp +++ b/src/storage/postgres_schema_entry.cpp @@ -183,12 +183,12 @@ void PostgresSchemaEntry::DropEntry(ClientContext &context, DropInfo &info) { GetCatalogSet(info.type).DropEntry(context, info); } -optional_ptr PostgresSchemaEntry::GetEntry(CatalogTransaction transaction, CatalogType type, - const string &name) { - if (!CatalogTypeIsSupported(type)) { +optional_ptr PostgresSchemaEntry::LookupEntry(CatalogTransaction transaction, const EntryLookupInfo &lookup_info) { + auto catalog_type = lookup_info.GetCatalogType(); + if (!CatalogTypeIsSupported(catalog_type)) { return nullptr; } - return GetCatalogSet(type).GetEntry(transaction.GetContext(), name); + return GetCatalogSet(catalog_type).GetEntry(transaction.GetContext(), lookup_info.GetEntryName()); } PostgresCatalogSet &PostgresSchemaEntry::GetCatalogSet(CatalogType type) { diff --git a/src/storage/postgres_update.cpp b/src/storage/postgres_update.cpp index 4f0aefa9..8fa4d690 100644 --- a/src/storage/postgres_update.cpp +++ b/src/storage/postgres_update.cpp @@ -180,8 +180,7 @@ InsertionOrderPreservingMap PostgresUpdate::ParamsToString() const { //===--------------------------------------------------------------------===// // Plan //===--------------------------------------------------------------------===// -unique_ptr PostgresCatalog::PlanUpdate(ClientContext &context, LogicalUpdate &op, - unique_ptr plan) { +PhysicalOperator &PostgresCatalog::PlanUpdate(ClientContext &context, PhysicalPlanGenerator &planner, LogicalUpdate &op, PhysicalOperator &plan) { if (op.return_chunk) { throw BinderException("RETURNING clause not yet supported for updates of a Postgres table"); } @@ -190,10 +189,11 @@ unique_ptr PostgresCatalog::PlanUpdate(ClientContext &context, throw BinderException("SET DEFAULT is not yet supported for updates of a Postgres table"); } } - PostgresCatalog::MaterializePostgresScans(*plan); - auto insert = make_uniq(op, op.table, std::move(op.columns)); - insert->children.push_back(std::move(plan)); - return std::move(insert); + + PostgresCatalog::MaterializePostgresScans(plan); + auto &update = planner.Make(op, op.table, std::move(op.columns)); + update.children.push_back(plan); + return update; } } // namespace duckdb diff --git a/test/sql/scanner/daterange_array.test b/test/sql/scanner/daterange_array.test index bddb4271..c0620bc2 100644 --- a/test/sql/scanner/daterange_array.test +++ b/test/sql/scanner/daterange_array.test @@ -20,7 +20,7 @@ loop i 0 2 query II SELECT * from daterange_array; ---- -1108 [["2010-01-01 14:30:00","2010-01-01 15:30:00")] +1108 ['["2010-01-01 14:30:00","2010-01-01 15:30:00")'] statement ok USE memory diff --git a/test/sql/storage/attach_types.test b/test/sql/storage/attach_types.test index 610ce67a..7819c04f 100644 --- a/test/sql/storage/attach_types.test +++ b/test/sql/storage/attach_types.test @@ -60,14 +60,14 @@ query IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII SELECT COLUMNS(*)::VARCHAR FROM all_types_tbl ---- false -128 -32768 -2147483648 -9223372036854775808 0 0 0 2000-01-01 00:00:00 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 00:00:00+15:00 2000-01-01 01:02:03 -999.9 -99999.9999 -999999999999.999999 -9999999999999999999999999999.9999999999 00000000-0000-0000-0000-000000000000 00:00:00 🦆🦆🦆🦆🦆🦆 thisisalongblob\x00withnullbytes 0010001001011100010101011010111 DUCK_DUCK_ENUM enum_0 enum_0 [] [] [] [] [] [🦆🦆🦆🦆🦆🦆, goose, NULL] -true 127 32767 2147483647 9223372036854775807 255 65535 4294967295 2000-01-01 24:00:00 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 00:00:00+15:00 2000-01-01 01:02:03 999.9 99999.9999 999999999999.999999 9999999999999999999999999999.9999999999 ffffffff-ffff-ffff-ffff-ffffffffffff 83 years 3 months 999 days 00:16:39.999999 goo se \x00\x00\x00a 10101 GOOSE enum_299 enum_69999 [42, 999, NULL, NULL, -42] [42.0, nan, inf, -inf, NULL, -42.0] [1970-01-01, infinity, -infinity, NULL, 2022-05-12] [1970-01-01 00:00:00, infinity, -infinity, NULL, 2022-05-12 16:23:45] [1970-01-01 00:00:00+00, infinity, -infinity, NULL, 2022-05-12 23:23:45+00] [🦆🦆🦆🦆🦆🦆, goose, NULL] +true 127 32767 2147483647 9223372036854775807 255 65535 4294967295 2000-01-01 24:00:00 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 00:00:00+15:00 2000-01-01 01:02:03 999.9 99999.9999 999999999999.999999 9999999999999999999999999999.9999999999 ffffffff-ffff-ffff-ffff-ffffffffffff 83 years 3 months 999 days 00:16:39.999999 goo se \x00\x00\x00a 10101 GOOSE enum_299 enum_69999 [42, 999, NULL, NULL, -42] [42.0, nan, inf, -inf, NULL, -42.0] [1970-01-01, infinity, -infinity, NULL, 2022-05-12] ['1970-01-01 00:00:00', infinity, -infinity, NULL, '2022-05-12 16:23:45'] ['1970-01-01 00:00:00+00', infinity, -infinity, NULL, '2022-05-12 23:23:45+00'] [🦆🦆🦆🦆🦆🦆, goose, NULL] NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL query IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII SELECT COLUMNS(*)::VARCHAR FROM s.all_types ---- false -128 -32768 -2147483648 -9223372036854775808 0 0 0 2000-01-01 00:00:00 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 00:00:00+15:00 2000-01-01 01:02:03 -999.9 -99999.9999 -999999999999.999999 -9999999999999999999999999999.9999999999 00000000-0000-0000-0000-000000000000 00:00:00 🦆🦆🦆🦆🦆🦆 thisisalongblob\x00withnullbytes 0010001001011100010101011010111 DUCK_DUCK_ENUM enum_0 enum_0 [] [] [] [] [] [🦆🦆🦆🦆🦆🦆, goose, NULL] -true 127 32767 2147483647 9223372036854775807 255 65535 4294967295 2000-01-01 24:00:00 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 00:00:00+15:00 2000-01-01 01:02:03 999.9 99999.9999 999999999999.999999 9999999999999999999999999999.9999999999 ffffffff-ffff-ffff-ffff-ffffffffffff 83 years 3 months 999 days 00:16:39.999999 goo se \x00\x00\x00a 10101 GOOSE enum_299 enum_69999 [42, 999, NULL, NULL, -42] [42.0, nan, inf, -inf, NULL, -42.0] [1970-01-01, infinity, -infinity, NULL, 2022-05-12] [1970-01-01 00:00:00, infinity, -infinity, NULL, 2022-05-12 16:23:45] [1970-01-01 00:00:00+00, infinity, -infinity, NULL, 2022-05-12 23:23:45+00] [🦆🦆🦆🦆🦆🦆, goose, NULL] +true 127 32767 2147483647 9223372036854775807 255 65535 4294967295 2000-01-01 24:00:00 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 00:00:00+15:00 2000-01-01 01:02:03 999.9 99999.9999 999999999999.999999 9999999999999999999999999999.9999999999 ffffffff-ffff-ffff-ffff-ffffffffffff 83 years 3 months 999 days 00:16:39.999999 goo se \x00\x00\x00a 10101 GOOSE enum_299 enum_69999 [42, 999, NULL, NULL, -42] [42.0, nan, inf, -inf, NULL, -42.0] [1970-01-01, infinity, -infinity, NULL, 2022-05-12] ['1970-01-01 00:00:00', infinity, -infinity, NULL, '2022-05-12 16:23:45'] ['1970-01-01 00:00:00+00', infinity, -infinity, NULL, '2022-05-12 23:23:45+00'] [🦆🦆🦆🦆🦆🦆, goose, NULL] NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL # filter pushdown diff --git a/test/sql/storage/attach_types_lists.test b/test/sql/storage/attach_types_lists.test index d32320b4..7c177bcf 100644 --- a/test/sql/storage/attach_types_lists.test +++ b/test/sql/storage/attach_types_lists.test @@ -139,21 +139,21 @@ SELECT * FROM lists [] NULL [NULL, string 123, s] -[] -[ 0 ] -[, ] -[a, ] -[a, , b] -[a, }, b] -[a, ", b] -[a, '{}[]()";,\n\\, b] -[[]] -[[, ]] -[[a, ]] -[[a, , b]] -[[a, }, b]] -[[a, ", b]] -[[a, '{}[]()";,\n\\, b], [a, '{}[]()";,\n\\, b]] +[''] +[' 0 '] +['', ''] +[a, ''] +[a, ' ', b] +[a, '}', b] +[a, '"', b] +[a, '\'{}[]()";,\\n\\\\', b] +['[\'\']'] +['[\'\', \'\']'] +['[a, \'\']'] +['[a, \' \', b]'] +['[a, \'}\', b]'] +['[a, \'"\', b]'] +['[a, \'\\\'{}[]()";,\\\\n\\\\\\\\\', b]', '[a, \'\\\'{}[]()";,\\\\n\\\\\\\\\', b]'] # timestamp list foreach type TIMESTAMP TIMESTAMP_MS TIMESTAMP_NS TIMESTAMP_S @@ -176,9 +176,9 @@ INSERT INTO lists VALUES ([NULL, TIMESTAMP '1900-01-01 00:00:00']); query I SELECT * FROM lists ---- -[2010-01-01 01:23:45, infinity, -infinity] +['2010-01-01 01:23:45', infinity, -infinity] [] NULL -[NULL, 1900-01-01 00:00:00] +[NULL, '1900-01-01 00:00:00'] endloop diff --git a/test/sql/storage/attach_types_macaddr.test b/test/sql/storage/attach_types_macaddr.test index fda92627..c2859aa4 100644 --- a/test/sql/storage/attach_types_macaddr.test +++ b/test/sql/storage/attach_types_macaddr.test @@ -45,7 +45,7 @@ query IIIII SELECT * FROM pg_complex_types_mix ---- 0 -[08:00:2b:01:02:03] +['08:00:2b:01:02:03'] hello world [string, list, NULL] \x00\xFF diff --git a/test/sql/storage/attach_types_struct.test b/test/sql/storage/attach_types_struct.test index d1e05fed..4a65d9a9 100644 --- a/test/sql/storage/attach_types_struct.test +++ b/test/sql/storage/attach_types_struct.test @@ -46,7 +46,7 @@ query I SELECT * FROM my_composite_tbl ---- {'id': 42, 'name': test 123} -{'id': 43, 'name': )} +{'id': 43, 'name': ')'} {'id': 100, 'name': xxx} query II @@ -148,5 +148,5 @@ query I SELECT * FROM my_composite_tbl ---- {'id': 42, 'children': [{'id': 43, 'names': [a, b]}]} -{'id': 10, 'children': [{'id': 20, 'names': [a, , '{}[]()";,\n\\, b]}, {'id': 30, 'names': [(, """""""""""", )]}]} -{'id': 10, 'children': [{'id': 20, 'names': [a, b]}, {'id': 30, 'names': NULL}, {'id': 40, 'names': [}, ", NULL]}, {'id': 50, 'names': [, a, )]}, {'id': NULL, 'names': NULL}]} +{'id': 10, 'children': [{'id': 20, 'names': [a, '', '\'{}[]()";,\\n\\\\', b]}, {'id': 30, 'names': ['(', '""""""""""""', ')']}]} +{'id': 10, 'children': [{'id': 20, 'names': [a, b]}, {'id': 30, 'names': NULL}, {'id': 40, 'names': ['}', '"', NULL]}, {'id': 50, 'names': ['', a, ')']}, {'id': NULL, 'names': NULL}]} From cbac54f7d8200b13512a565502f428ff7b5a8112 Mon Sep 17 00:00:00 2001 From: Mytherin Date: Sat, 3 May 2025 18:18:58 +0200 Subject: [PATCH 2/6] set -e --- create-postgres-tables.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/create-postgres-tables.sh b/create-postgres-tables.sh index 408f292f..ae773711 100755 --- a/create-postgres-tables.sh +++ b/create-postgres-tables.sh @@ -1,4 +1,6 @@ #!/bin/bash +set -e + echo " CREATE SCHEMA tpch; CREATE SCHEMA tpcds; From 93a062d28042b6ed85783cfa1b54efe4fdef1234 Mon Sep 17 00:00:00 2001 From: Mytherin Date: Sat, 3 May 2025 18:38:45 +0200 Subject: [PATCH 3/6] Fix for copy from database --- .github/workflows/MainDistributionPipeline.yml | 4 ++-- src/storage/postgres_index.cpp | 8 ++++++-- test/sql/scanner/arrays.test | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/MainDistributionPipeline.yml b/.github/workflows/MainDistributionPipeline.yml index 6da920f2..9fbf6de8 100644 --- a/.github/workflows/MainDistributionPipeline.yml +++ b/.github/workflows/MainDistributionPipeline.yml @@ -16,7 +16,7 @@ jobs: name: Build extension binaries uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main with: - duckdb_version: v1.2.1 + duckdb_version: main ci_tools_version: main extension_name: postgres_scanner exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_mingw' @@ -27,7 +27,7 @@ jobs: uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@main secrets: inherit with: - duckdb_version: v1.2.1 + duckdb_version: main ci_tools_version: main extension_name: postgres_scanner exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_mingw' diff --git a/src/storage/postgres_index.cpp b/src/storage/postgres_index.cpp index 5dd54622..0b734301 100644 --- a/src/storage/postgres_index.cpp +++ b/src/storage/postgres_index.cpp @@ -4,6 +4,7 @@ #include "duckdb/planner/operator/logical_extension_operator.hpp" #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp" #include "duckdb/parser/parsed_data/drop_info.hpp" +#include "duckdb/planner/operator/logical_create_index.hpp" namespace duckdb { @@ -72,8 +73,11 @@ class LogicalPostgresCreateIndex : public LogicalExtensionOperator { unique_ptr PostgresCatalog::BindCreateIndex(Binder &binder, CreateStatement &stmt, TableCatalogEntry &table, unique_ptr plan) { - return make_uniq(unique_ptr_cast(std::move(stmt.info)), - table); + // FIXME: this is a work-around for the CreateIndexInfo we are getting here not being fully bound + // this needs to be fixed upstream (eventually) + auto result = Catalog::BindCreateIndex(binder, stmt, table, std::move(plan)); + auto &index_create = result->Cast(); + return make_uniq(std::move(index_create.info), table); } } // namespace duckdb diff --git a/test/sql/scanner/arrays.test b/test/sql/scanner/arrays.test index 45621bfb..657a481c 100644 --- a/test/sql/scanner/arrays.test +++ b/test/sql/scanner/arrays.test @@ -33,13 +33,13 @@ SELECT UNNEST(float_col), ROUND(UNNEST(double_col), 1) FROM pg_numarraytypes query IIIIIIII select * from pg_bytearraytypes; ---- -[a, Z, NULL] [a, Z, NULL] [aaaa, ZZZZ, NULL] [aaaa, ZZZZ, NULL] [aaaa, ZZZZ, NULL] [x00, xff, NULL] [{"a":42}, NULL] [a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11, NULL] +[a, Z, NULL] [a, Z, NULL] [aaaa, ZZZZ, NULL] [aaaa, ZZZZ, NULL] [aaaa, ZZZZ, NULL] [x00, xff, NULL] ['{"a":42}', NULL] [a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11, NULL] NULL NULL NULL NULL NULL NULL NULL NULL query IIIII select * from pg_datearraytypes; ---- -[2019-11-26, 2021-03-01, NULL] [14:42:43, 12:45:01, NULL] [14:42:43+05:45, 12:45:01+05:45, NULL] [2019-11-26 12:45:01, 2021-03-01 12:45:01, NULL] [2019-11-26 07:00:01+00, 2021-03-01 07:00:01+00, NULL] +[2019-11-26, 2021-03-01, NULL] ['14:42:43', '12:45:01', NULL] ['14:42:43+05:45', '12:45:01+05:45', NULL] ['2019-11-26 12:45:01', '2021-03-01 12:45:01', NULL] ['2019-11-26 07:00:01+00', '2021-03-01 07:00:01+00', NULL] NULL NULL NULL NULL NULL statement ok From 902e6c81dd8444400059f673eaa39ffc6699b5d0 Mon Sep 17 00:00:00 2001 From: Mytherin Date: Sun, 4 May 2025 13:22:15 +0200 Subject: [PATCH 4/6] reldebug it is --- .github/workflows/Linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Linux.yml b/.github/workflows/Linux.yml index c625e869..707e6cc1 100644 --- a/.github/workflows/Linux.yml +++ b/.github/workflows/Linux.yml @@ -75,7 +75,7 @@ jobs: GEN: ninja STATIC_LIBCPP: 1 run: | - make release + make reldebug - name: Test extension env: @@ -84,4 +84,4 @@ jobs: run: | psql -c "SELECT 43" source ./create-postgres-tables.sh - make test_release \ No newline at end of file + make test_reldebug \ No newline at end of file From d6b09b92d76905ebe12ba4306650a177114fea58 Mon Sep 17 00:00:00 2001 From: Mytherin Date: Sun, 4 May 2025 14:08:03 +0200 Subject: [PATCH 5/6] Find any duckdb --- create-postgres-tables.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/create-postgres-tables.sh b/create-postgres-tables.sh index ae773711..7b5bde2b 100755 --- a/create-postgres-tables.sh +++ b/create-postgres-tables.sh @@ -1,6 +1,15 @@ #!/bin/bash set -e +DUCKDB_PATH=duckdb +if test -f build/release/duckdb; then + DUCKDB_PATH=build/release/duckdb +elif test -f build/reldebug/duckdb; then + DUCKDB_PATH=build/reldebug/duckdb +elif test -f build/debug/duckdb; then + DUCKDB_PATH=build/debug/duckdb +fi + echo " CREATE SCHEMA tpch; CREATE SCHEMA tpcds; @@ -8,7 +17,7 @@ CALL dbgen(sf=0.01, schema='tpch'); CALL dsdgen(sf=0.01, schema='tpcds'); EXPORT DATABASE '/tmp/postgresscannertmp'; " | \ -./build/release/duckdb +$DUCKDB_PATH dropdb --if-exists postgresscanner createdb postgresscanner From 2343dd7436318d27c7a88a4dae5c08c8a9850f45 Mon Sep 17 00:00:00 2001 From: Mytherin Date: Mon, 5 May 2025 22:57:51 +0200 Subject: [PATCH 6/6] Copy over relevant IndexBinder part --- src/storage/postgres_index.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/storage/postgres_index.cpp b/src/storage/postgres_index.cpp index 0b734301..5ce5b366 100644 --- a/src/storage/postgres_index.cpp +++ b/src/storage/postgres_index.cpp @@ -5,6 +5,9 @@ #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp" #include "duckdb/parser/parsed_data/drop_info.hpp" #include "duckdb/planner/operator/logical_create_index.hpp" +#include "duckdb/parser/parsed_data/create_index_info.hpp" +#include "duckdb/planner/expression_binder/index_binder.hpp" +#include "duckdb/planner/operator/logical_get.hpp" namespace duckdb { @@ -75,9 +78,19 @@ unique_ptr PostgresCatalog::BindCreateIndex(Binder &binder, Cre unique_ptr plan) { // FIXME: this is a work-around for the CreateIndexInfo we are getting here not being fully bound // this needs to be fixed upstream (eventually) - auto result = Catalog::BindCreateIndex(binder, stmt, table, std::move(plan)); - auto &index_create = result->Cast(); - return make_uniq(std::move(index_create.info), table); + auto create_index_info = unique_ptr_cast(std::move(stmt.info)); + IndexBinder index_binder(binder, binder.context); + + // Bind the index expressions. + vector> expressions; + for (auto &expr : create_index_info->expressions) { + expressions.push_back(index_binder.Bind(expr)); + } + + auto &get = plan->Cast(); + index_binder.InitCreateIndexInfo(get, *create_index_info, table.schema.name); + + return make_uniq(std::move(create_index_info), table); } } // namespace duckdb