Skip to content

Commit

Permalink
format, update duckdb
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxxen committed Nov 1, 2024
1 parent 530feaf commit f46c34c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion duckdb
Submodule duckdb updated 300 files
7 changes: 6 additions & 1 deletion src/hnsw/hnsw_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const case_insensitive_map_t<unum::usearch::metric_kind_t> HNSWIndex::METRIC_KIN

const unordered_map<uint8_t, unum::usearch::scalar_kind_t> HNSWIndex::SCALAR_KIND_MAP = {
{static_cast<uint8_t>(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<uint8_t>(LogicalTypeId::DOUBLE), unum::usearch::scalar_kind_t::f64_k},
{static_cast<uint8_t>(LogicalTypeId::TINYINT), unum::usearch::scalar_kind_t::i8_k},
{static_cast<uint8_t>(LogicalTypeId::SMALLINT), unum::usearch::scalar_kind_t::i16_k},
Expand Down Expand Up @@ -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",
Expand Down
31 changes: 11 additions & 20 deletions src/hnsw/hnsw_index_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "hnsw/hnsw_index.hpp"
#include "hnsw/hnsw_index_physical_create.hpp"


namespace duckdb {

unique_ptr<PhysicalOperator> HNSWIndex::CreatePlan(PlanIndexInput &input) {
Expand Down Expand Up @@ -103,14 +102,16 @@ unique_ptr<PhysicalOperator> HNSWIndex::CreatePlan(PlanIndexInput &input) {

vector<LogicalType> new_column_types;
vector<unique_ptr<Expression>> 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<BoundReferenceExpression>(LogicalType::ROW_TYPE, create_index.info->scan_types.size() - 1));
select_list.push_back(
make_uniq<BoundReferenceExpression>(LogicalType::ROW_TYPE, create_index.info->scan_types.size() - 1));

auto projection = make_uniq<PhysicalProjection>(new_column_types, std::move(select_list), create_index.estimated_cardinality);
auto projection =
make_uniq<PhysicalProjection>(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
Expand All @@ -120,34 +121,24 @@ unique_ptr<PhysicalOperator> 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<BoundOperatorExpression>(ExpressionType::OPERATOR_IS_NOT_NULL, LogicalType::BOOLEAN);
make_uniq<BoundOperatorExpression>(ExpressionType::OPERATOR_IS_NOT_NULL, LogicalType::BOOLEAN);
auto bound_ref = make_uniq<BoundReferenceExpression>(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<PhysicalFilter>(std::move(filter_types), std::move(filter_select_list), create_index.estimated_cardinality);
auto null_filter = make_uniq<PhysicalFilter>(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<PhysicalCreateHNSWIndex>(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<PhysicalCreateHNSWIndex>(
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
2 changes: 0 additions & 2 deletions src/include/hnsw/hnsw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ struct HNSWModule {
RegisterIndex(db);
RegisterIndexScan(db);
RegisterIndexPragmas(db);
RegisterPlanIndexCreate(db);
RegisterMacros(db);

// Optimizers
Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/include/hnsw/hnsw_index_physical_create.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class PhysicalCreateHNSWIndex : public PhysicalOperator {
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::EXTENSION;

public:
PhysicalCreateHNSWIndex(const vector<LogicalType> &types_p, TableCatalogEntry &table, const vector<column_t> &column_ids,
unique_ptr<CreateIndexInfo> info, vector<unique_ptr<Expression>> unbound_expressions,
idx_t estimated_cardinality);
PhysicalCreateHNSWIndex(const vector<LogicalType> &types_p, TableCatalogEntry &table,
const vector<column_t> &column_ids, unique_ptr<CreateIndexInfo> info,
vector<unique_ptr<Expression>> unbound_expressions, idx_t estimated_cardinality);

//! The table to create the index for
DuckTableEntry &table;
Expand Down

0 comments on commit f46c34c

Please sign in to comment.