From f46c34cdf5c697d67b8b22c48128c9ac1da58c32 Mon Sep 17 00:00:00 2001 From: Max Gabrielsson Date: Fri, 1 Nov 2024 10:47:13 +0100 Subject: [PATCH] format, update duckdb --- duckdb | 2 +- src/hnsw/hnsw_index.cpp | 7 ++++- src/hnsw/hnsw_index_plan.cpp | 31 +++++++------------ src/include/hnsw/hnsw.hpp | 2 -- .../hnsw/hnsw_index_physical_create.hpp | 6 ++-- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/duckdb b/duckdb index f680b7d..c3ca360 160000 --- a/duckdb +++ b/duckdb @@ -1 +1 @@ -Subproject commit f680b7d08f56183391b581077d4baf589e1cc8bd +Subproject commit c3ca3607c221d315f38227b8bf58e68746c59083 diff --git a/src/hnsw/hnsw_index.cpp b/src/hnsw/hnsw_index.cpp index 711e527..b8bfd1f 100644 --- a/src/hnsw/hnsw_index.cpp +++ b/src/hnsw/hnsw_index.cpp @@ -246,7 +246,7 @@ const case_insensitive_map_t HNSWIndex::METRIC_KIN const unordered_map HNSWIndex::SCALAR_KIND_MAP = { {static_cast(LogicalTypeId::FLOAT), unum::usearch::scalar_kind_t::f32_k}, - /* TODO: Add the rest of these later + /* TODO: Add the rest of these later {static_cast(LogicalTypeId::DOUBLE), unum::usearch::scalar_kind_t::f64_k}, {static_cast(LogicalTypeId::TINYINT), unum::usearch::scalar_kind_t::i8_k}, {static_cast(LogicalTypeId::SMALLINT), unum::usearch::scalar_kind_t::i16_k}, @@ -676,6 +676,11 @@ void HNSWModule::RegisterIndex(DatabaseInstance &db) { }; index_type.create_plan = HNSWIndex::CreatePlan; + // Register persistence option + db.config.AddExtensionOption("hnsw_enable_experimental_persistence", + "experimental: enable creating HNSW indexes in persistent databases", + LogicalType::BOOLEAN, Value::BOOLEAN(false)); + // Register scan option db.config.AddExtensionOption("hnsw_ef_search", "experimental: override the ef_search parameter when scanning HNSW indexes", diff --git a/src/hnsw/hnsw_index_plan.cpp b/src/hnsw/hnsw_index_plan.cpp index 7160fd0..2505a1f 100644 --- a/src/hnsw/hnsw_index_plan.cpp +++ b/src/hnsw/hnsw_index_plan.cpp @@ -12,7 +12,6 @@ #include "hnsw/hnsw_index.hpp" #include "hnsw/hnsw_index_physical_create.hpp" - namespace duckdb { unique_ptr HNSWIndex::CreatePlan(PlanIndexInput &input) { @@ -103,14 +102,16 @@ unique_ptr HNSWIndex::CreatePlan(PlanIndexInput &input) { vector new_column_types; vector> select_list; - for (auto & expression : create_index.expressions) { + for (auto &expression : create_index.expressions) { new_column_types.push_back(expression->return_type); select_list.push_back(std::move(expression)); } new_column_types.emplace_back(LogicalType::ROW_TYPE); - select_list.push_back(make_uniq(LogicalType::ROW_TYPE, create_index.info->scan_types.size() - 1)); + select_list.push_back( + make_uniq(LogicalType::ROW_TYPE, create_index.info->scan_types.size() - 1)); - auto projection = make_uniq(new_column_types, std::move(select_list), create_index.estimated_cardinality); + auto projection = + make_uniq(new_column_types, std::move(select_list), create_index.estimated_cardinality); projection->children.push_back(std::move(input.table_scan)); // filter operator for IS_NOT_NULL on each key column @@ -120,34 +121,24 @@ unique_ptr HNSWIndex::CreatePlan(PlanIndexInput &input) { for (idx_t i = 0; i < new_column_types.size() - 1; i++) { filter_types.push_back(new_column_types[i]); auto is_not_null_expr = - make_uniq(ExpressionType::OPERATOR_IS_NOT_NULL, LogicalType::BOOLEAN); + make_uniq(ExpressionType::OPERATOR_IS_NOT_NULL, LogicalType::BOOLEAN); auto bound_ref = make_uniq(new_column_types[i], i); is_not_null_expr->children.push_back(std::move(bound_ref)); filter_select_list.push_back(std::move(is_not_null_expr)); } - auto null_filter = - make_uniq(std::move(filter_types), std::move(filter_select_list), create_index.estimated_cardinality); + auto null_filter = make_uniq(std::move(filter_types), std::move(filter_select_list), + create_index.estimated_cardinality); null_filter->types.emplace_back(LogicalType::ROW_TYPE); null_filter->children.push_back(std::move(projection)); - auto physical_create_index = - make_uniq(create_index.types, create_index.table, create_index.info->column_ids, std::move(create_index.info), - std::move(create_index.unbound_expressions), create_index.estimated_cardinality); + auto physical_create_index = make_uniq( + create_index.types, create_index.table, create_index.info->column_ids, std::move(create_index.info), + std::move(create_index.unbound_expressions), create_index.estimated_cardinality); physical_create_index->children.push_back(std::move(null_filter)); return std::move(physical_create_index); } -//------------------------------------------------------------- -// Register -//------------------------------------------------------------- -void HNSWModule::RegisterPlanIndexCreate(DatabaseInstance &db) { - // Register the optimizer extension - db.config.AddExtensionOption("hnsw_enable_experimental_persistence", - "experimental: enable creating HNSW indexes in persistent databases", - LogicalType::BOOLEAN, Value::BOOLEAN(false)); -} - } // namespace duckdb \ No newline at end of file diff --git a/src/include/hnsw/hnsw.hpp b/src/include/hnsw/hnsw.hpp index 3d69562..5f0b55e 100644 --- a/src/include/hnsw/hnsw.hpp +++ b/src/include/hnsw/hnsw.hpp @@ -10,7 +10,6 @@ struct HNSWModule { RegisterIndex(db); RegisterIndexScan(db); RegisterIndexPragmas(db); - RegisterPlanIndexCreate(db); RegisterMacros(db); // Optimizers @@ -25,7 +24,6 @@ struct HNSWModule { static void RegisterIndexScan(DatabaseInstance &db); static void RegisterMultiScan(DatabaseInstance &db); static void RegisterIndexPragmas(DatabaseInstance &db); - static void RegisterPlanIndexCreate(DatabaseInstance &db); static void RegisterMacros(DatabaseInstance &db); static void RegisterTopKOptimizer(DatabaseInstance &db); diff --git a/src/include/hnsw/hnsw_index_physical_create.hpp b/src/include/hnsw/hnsw_index_physical_create.hpp index b8b8156..b620831 100644 --- a/src/include/hnsw/hnsw_index_physical_create.hpp +++ b/src/include/hnsw/hnsw_index_physical_create.hpp @@ -11,9 +11,9 @@ class PhysicalCreateHNSWIndex : public PhysicalOperator { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::EXTENSION; public: - PhysicalCreateHNSWIndex(const vector &types_p, TableCatalogEntry &table, const vector &column_ids, - unique_ptr info, vector> unbound_expressions, - idx_t estimated_cardinality); + PhysicalCreateHNSWIndex(const vector &types_p, TableCatalogEntry &table, + const vector &column_ids, unique_ptr info, + vector> unbound_expressions, idx_t estimated_cardinality); //! The table to create the index for DuckTableEntry &table;