Skip to content

Commit

Permalink
Make sure memory-exceeded warnings are triggered in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngalstyan4 committed Oct 15, 2023
1 parent 67aa982 commit ae27f6f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/hnsw/external_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void *ldb_wal_index_node_retriever(void *ctxp, int id)
NULL,
NULL,
0,
"Pinned more tuples during node retrieval than will fir in work_mem, cosider increasing work_mem");
"pinned more tuples during node retrieval than will fit in work_mem, cosider increasing work_mem");
#endif
fa_cache_insert(&ctx->fa_cache, id, nodepage->node);

Expand Down
8 changes: 8 additions & 0 deletions test/expected/hnsw_create.out
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ CREATE TABLE IF NOT EXISTS sift_base1k (
v REAL[]
);
COPY sift_base1k (v) FROM '/tmp/lantern/vector_datasets/sift_base1k_arrays.csv' WITH csv;
-- limit work_mem to trigger codepaths for exceeding work_mem
set work_mem = '64kB';
set client_min_messages = 'ERROR';
-- Validate that creating a secondary index works
CREATE INDEX ON sift_base1k USING hnsw (v) WITH (dim=128, M=4);
INFO: done init usearch index
INFO: inserted 1000 elements
INFO: done saving 1000 vectors
-- We do not actually print the warnings generated for exceeding work_mem because the work_mem
-- check does not work for postgres 13 and lower.So, if we printed the warnings, we would get a regression
-- failure in older postgres versions. We still reduce workmem to exercise relevant codepaths for coverage
set client_min_messages = 'WARNING';
set work_mem = '10MB';
SELECT * FROM ldb_get_indexes('sift_base1k');
indexname | size | indexdef | total_index_size
-------------------+--------+---------------------------------------------------------------------------------------------+------------------
Expand Down
10 changes: 9 additions & 1 deletion test/expected/hnsw_insert.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
---------------------------------------------------------------------
-- Test HNSW index inserts on empty table
---------------------------------------------------------------------
set work_mem = '10MB';
-- set an artificially low work_mem to make sure work_mem exceeded warnings are printed
set work_mem = '64kB';
-- We do not actually print the warnings generated for exceeding work_mem because the work_mem
-- check does not work for postgres 13 and lower.So, if we printed the warnings, we would get a regression
-- failure in older postgres versions. We still reduce workmem to exercise relevant codepaths for coverage
set client_min_messages = 'ERROR';
CREATE TABLE small_world (
id SERIAL PRIMARY KEY,
v REAL[2]
Expand All @@ -19,6 +24,9 @@ INSERT INTO small_world (v) VALUES ('{1,1,1,1}');
ERROR: Wrong number of dimensions: 4 instead of 3 expected
\set ON_ERROR_STOP on
DROP TABLE small_world;
-- set work_mem to a value that is enough for the tests
set client_min_messages = 'WARNING';
set work_mem = '10MB';
---------------------------------------------------------------------
-- Test HNSW index inserts on non-empty table
---------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions test/sql/hnsw_create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@
\ir utils/small_world_array.sql
\ir utils/sift1k_array.sql

-- limit work_mem to trigger codepaths for exceeding work_mem
set work_mem = '64kB';
set client_min_messages = 'ERROR';

-- Validate that creating a secondary index works
CREATE INDEX ON sift_base1k USING hnsw (v) WITH (dim=128, M=4);
-- We do not actually print the warnings generated for exceeding work_mem because the work_mem
-- check does not work for postgres 13 and lower.So, if we printed the warnings, we would get a regression
-- failure in older postgres versions. We still reduce workmem to exercise relevant codepaths for coverage

set client_min_messages = 'WARNING';
set work_mem = '10MB';

SELECT * FROM ldb_get_indexes('sift_base1k');

-- Validate that index creation works with a larger number of vectors
Expand All @@ -17,6 +28,7 @@ SELECT v AS v4444 FROM sift_base10k WHERE id = 4444 \gset
EXPLAIN (COSTS FALSE) SELECT * FROM sift_base10k order by v <-> :'v4444' LIMIT 10;

--- Validate that M values inside the allowed range [2, 128] do not throw an error

CREATE INDEX ON small_world USING hnsw (v) WITH (M=2);
CREATE INDEX ON small_world USING hnsw (v) WITH (M=128);

Expand Down
11 changes: 10 additions & 1 deletion test/sql/hnsw_insert.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
---------------------------------------------------------------------
-- Test HNSW index inserts on empty table
---------------------------------------------------------------------
set work_mem = '10MB';
-- set an artificially low work_mem to make sure work_mem exceeded warnings are printed
set work_mem = '64kB';
-- We do not actually print the warnings generated for exceeding work_mem because the work_mem
-- check does not work for postgres 13 and lower.So, if we printed the warnings, we would get a regression
-- failure in older postgres versions. We still reduce workmem to exercise relevant codepaths for coverage
set client_min_messages = 'ERROR';

CREATE TABLE small_world (
id SERIAL PRIMARY KEY,
Expand All @@ -20,6 +25,10 @@ INSERT INTO small_world (v) VALUES ('{1,1,1,1}');

DROP TABLE small_world;

-- set work_mem to a value that is enough for the tests
set client_min_messages = 'WARNING';
set work_mem = '10MB';

---------------------------------------------------------------------
-- Test HNSW index inserts on non-empty table
---------------------------------------------------------------------
Expand Down

0 comments on commit ae27f6f

Please sign in to comment.