44#include " duckdb/planner/operator/logical_extension_operator.hpp"
55#include " duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
66#include " duckdb/parser/parsed_data/drop_info.hpp"
7+ #include " duckdb/planner/operator/logical_create_index.hpp"
8+ #include " duckdb/parser/parsed_data/create_index_info.hpp"
9+ #include " duckdb/planner/expression_binder/index_binder.hpp"
10+ #include " duckdb/planner/operator/logical_get.hpp"
711
812namespace duckdb {
913
@@ -56,8 +60,8 @@ class LogicalPostgresCreateIndex : public LogicalExtensionOperator {
5660 unique_ptr<CreateIndexInfo> info;
5761 TableCatalogEntry &table;
5862
59- unique_ptr< PhysicalOperator> CreatePlan (ClientContext &context, PhysicalPlanGenerator &generator ) override {
60- return make_uniq <PostgresCreateIndex>(std::move (info), table);
63+ PhysicalOperator & CreatePlan (ClientContext &context, PhysicalPlanGenerator &planner ) override {
64+ return planner. Make <PostgresCreateIndex>(std::move (info), table);
6165 }
6266
6367 void Serialize (Serializer &serializer) const override {
@@ -72,8 +76,21 @@ class LogicalPostgresCreateIndex : public LogicalExtensionOperator {
7276unique_ptr<LogicalOperator> PostgresCatalog::BindCreateIndex (Binder &binder, CreateStatement &stmt,
7377 TableCatalogEntry &table,
7478 unique_ptr<LogicalOperator> plan) {
75- return make_uniq<LogicalPostgresCreateIndex>(unique_ptr_cast<CreateInfo, CreateIndexInfo>(std::move (stmt.info )),
76- table);
79+ // FIXME: this is a work-around for the CreateIndexInfo we are getting here not being fully bound
80+ // this needs to be fixed upstream (eventually)
81+ auto create_index_info = unique_ptr_cast<CreateInfo, CreateIndexInfo>(std::move (stmt.info ));
82+ IndexBinder index_binder (binder, binder.context );
83+
84+ // Bind the index expressions.
85+ vector<unique_ptr<Expression>> expressions;
86+ for (auto &expr : create_index_info->expressions ) {
87+ expressions.push_back (index_binder.Bind (expr));
88+ }
89+
90+ auto &get = plan->Cast <LogicalGet>();
91+ index_binder.InitCreateIndexInfo (get, *create_index_info, table.schema .name );
92+
93+ return make_uniq<LogicalPostgresCreateIndex>(std::move (create_index_info), table);
7794}
7895
7996} // namespace duckdb
0 commit comments