Skip to content

Commit

Permalink
reserve estimated cardinality up front
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxxen committed Apr 5, 2024
1 parent f03fe75 commit 692913f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/hnsw/hnsw_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class LinkedBlockWriter {
// Constructor
HNSWIndex::HNSWIndex(const string &name, IndexConstraintType index_constraint_type, const vector<column_t> &column_ids,
TableIOManager &table_io_manager, const vector<unique_ptr<Expression>> &unbound_expressions,
AttachedDatabase &db, const case_insensitive_map_t<Value> &options, const IndexStorageInfo &info)
AttachedDatabase &db, const case_insensitive_map_t<Value> &options, const IndexStorageInfo &info,
idx_t estimated_cardinality)
: Index(name, TYPE_NAME, index_constraint_type, column_ids, table_io_manager, unbound_expressions, db) {

if (index_constraint_type != IndexConstraintType::NONE) {
Expand Down Expand Up @@ -173,7 +174,7 @@ HNSWIndex::HNSWIndex(const string &name, IndexConstraintType index_constraint_ty
index.load_from_stream(
[&](void *data, size_t size) { return size == reader.ReadData(static_cast<data_ptr_t>(data), size); });
} else {
index.reserve(32);
index.reserve(MinValue(static_cast<idx_t>(32), estimated_cardinality));
}
index_size = index.size();
}
Expand Down
5 changes: 3 additions & 2 deletions src/hnsw/hnsw_index_physical_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ unique_ptr<GlobalSinkState> PhysicalCreateHNSWIndex::GetGlobalSinkState(ClientCo
auto &constraint_type = info->constraint_type;
auto &db = storage.db;

gstate->global_index = make_uniq<HNSWIndex>(info->index_name, constraint_type, storage_ids, table_manager,
unbound_expressions, db, info->options);
gstate->global_index =
make_uniq<HNSWIndex>(info->index_name, constraint_type, storage_ids, table_manager, unbound_expressions, db,
info->options, IndexStorageInfo(), estimated_cardinality);

return std::move(gstate);
}
Expand Down
2 changes: 1 addition & 1 deletion src/include/hnsw/hnsw_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HNSWIndex : public Index {
HNSWIndex(const string &name, IndexConstraintType index_constraint_type, const vector<column_t> &column_ids,
TableIOManager &table_io_manager, const vector<unique_ptr<Expression>> &unbound_expressions,
AttachedDatabase &db, const case_insensitive_map_t<Value> &options,
const IndexStorageInfo &info = IndexStorageInfo());
const IndexStorageInfo &info = IndexStorageInfo(), idx_t estimated_cardinality = 0);

//! The actual usearch index
unum::usearch::index_dense_t index;
Expand Down

0 comments on commit 692913f

Please sign in to comment.