Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not use external indexing if table does not contain tuples #357

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lantern_hnsw/src/hnsw/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, ldb_

uint32_t estimated_row_count = EstimateRowCount(heap);

if(estimated_row_count < EXTERNAL_INDEX_MIN_TUPLES) {
buildstate->external = false;
}

if(buildstate->external) {
buildstate->external_socket = palloc0(sizeof(external_index_socket_t));
create_external_index_session(ldb_external_index_host,
Expand Down
1 change: 1 addition & 0 deletions lantern_hnsw/src/hnsw/external_index_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "external_index_socket_ssl.h"
#include "usearch.h"

#define EXTERNAL_INDEX_MIN_TUPLES 1
#define EXTERNAL_INDEX_MAGIC_MSG_SIZE 4
#define EXTERNAL_INDEX_INIT_MSG 0x13333337
#define EXTERNAL_INDEX_END_MSG 0x31333337
Expand Down
8 changes: 8 additions & 0 deletions lantern_hnsw/test/expected/hnsw_create.out
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@ CREATE INDEX ON small_world4 USING lantern_hnsw (vector) WITH (M=14, ef=22, ef_c
INFO: done init usearch index
ERROR: Wrong number of dimensions: 3 instead of 4 expected
\set ON_ERROR_STOP on
\set ON_ERROR_STOP off
SET lantern.external_index_port=65535; -- this should fail if it will try to connect
CREATE TABLE empty(v REAL[]);
CREATE INDEX ON empty USING lantern_hnsw (v) WITH (dim=3, external=true); -- should success
INFO: done init usearch index
INFO: inserted 0 elements
INFO: done saving 0 vectors
\set ON_ERROR_STOP on
6 changes: 6 additions & 0 deletions lantern_hnsw/test/sql/hnsw_create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ UPDATE small_world4 SET vector = '{0,0,0}' WHERE id = '001';
\set ON_ERROR_STOP off
CREATE INDEX ON small_world4 USING lantern_hnsw (vector) WITH (M=14, ef=22, ef_construction=2);
\set ON_ERROR_STOP on

\set ON_ERROR_STOP off
SET lantern.external_index_port=65535; -- this should fail if it will try to connect
CREATE TABLE empty(v REAL[]);
CREATE INDEX ON empty USING lantern_hnsw (v) WITH (dim=3, external=true); -- should success
\set ON_ERROR_STOP on
Loading