-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uses pg_regress to run tests in parallel against the database. Allows custom DB initialization and finalization which can be used to load relevant data in the beginning and check relevant invariants in the end
- Loading branch information
1 parent
6c48316
commit 9e3e17b
Showing
24 changed files
with
351 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- This file handles initializing the database before parallel tests are run | ||
\ir utils/sift10k_array.sql | ||
CREATE TABLE IF NOT EXISTS sift_base10k ( | ||
id SERIAL PRIMARY KEY, | ||
v REAL[128] | ||
); | ||
\copy sift_base10k (v) FROM '/tmp/lantern/vector_datasets/siftsmall_base_arrays.csv' with csv; | ||
\ir utils/random_array.sql | ||
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$ | ||
begin | ||
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim - 1)); | ||
end | ||
$BODY$ LANGUAGE plpgsql; | ||
CREATE OR REPLACE FUNCTION random_array(dim integer, min real, max real) RETURNS REAL[] AS $BODY$ | ||
begin | ||
return (select array_agg(random() * (max - min) + min) from generate_series (0, dim - 1)); | ||
end | ||
$BODY$ LANGUAGE plpgsql; | ||
CREATE SEQUENCE serial START 10001; | ||
CREATE INDEX ON sift_base10k USING HNSW (v) WITH (M=5, ef=20, ef_construction=20); | ||
INFO: done init usearch index | ||
INFO: inserted 10000 elements | ||
INFO: done saving 10000 vectors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- This file contains invariants to be checked after the parallel tests have run | ||
SELECT COUNT(*) FROM sift_base10k; | ||
count | ||
------- | ||
10030 | ||
(1 row) | ||
|
||
SELECT * from sift_base10k WHERE id=4444; | ||
id | v | ||
------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
4444 | {55,61,11,4,5,2,13,24,65,49,13,9,23,37,94,38,54,11,14,14,40,31,50,44,53,4,0,0,27,17,8,34,12,10,4,4,22,52,68,53,9,2,0,0,2,116,119,64,119,2,0,0,2,30,119,119,116,5,0,8,47,9,5,60,7,7,10,23,56,50,23,5,28,68,6,18,24,65,50,9,119,75,3,0,1,8,12,85,119,11,4,6,8,9,5,74,25,11,8,20,18,12,2,21,11,90,25,32,33,15,2,9,84,67,8,4,22,31,11,33,119,30,3,6,0,0,0,26} | ||
(1 row) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
SELECT v AS v1111 FROM sift_base10k WHERE id = 1111 \gset | ||
SELECT v AS v2222 FROM sift_base10k WHERE id = 2222 \gset | ||
SELECT v AS v3333 FROM sift_base10k WHERE id = 3333 \gset | ||
SELECT v AS v4444 FROM sift_base10k WHERE id = 4444 \gset | ||
-- Make sure that our index queries will actually run against the index | ||
EXPLAIN (COSTS false) SELECT id FROM sift_base10k ORDER BY v <-> :'v1111' ASC LIMIT 1; | ||
QUERY PLAN | ||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
Limit | ||
-> Index Scan using sift_base10k_v_idx on sift_base10k | ||
Order By: (v <-> '{21,24,5,0,0,26,22,6,16,16,10,9,0,18,114,19,13,13,9,1,2,53,111,19,39,32,5,0,4,9,10,13,6,10,8,0,2,130,77,4,2,0,0,0,3,130,130,11,130,0,0,0,0,37,130,84,130,5,0,1,17,11,4,28,17,39,3,3,30,77,28,3,20,0,0,1,49,125,13,7,130,6,0,0,0,5,11,61,130,2,0,1,12,84,48,73,1,12,2,0,31,57,9,2,16,12,1,0,32,36,0,1,63,6,3,1,0,0,24,51,9,0,0,0,0,44,88,48}'::real[]) | ||
(3 rows) | ||
|
||
-- Do the queries | ||
SELECT id FROM sift_base10k ORDER BY v <-> :'v1111' ASC LIMIT 1; | ||
id | ||
------ | ||
1111 | ||
(1 row) | ||
|
||
SELECT id FROM sift_base10k ORDER BY v <-> :'v2222' ASC LIMIT 1; | ||
id | ||
------ | ||
2222 | ||
(1 row) | ||
|
||
SELECT id FROM sift_base10k ORDER BY v <-> :'v3333' ASC LIMIT 1; | ||
id | ||
------ | ||
3333 | ||
(1 row) | ||
|
||
SELECT id FROM sift_base10k ORDER BY v <-> :'v4444' ASC LIMIT 1; | ||
id | ||
------ | ||
4444 | ||
(1 row) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- This file handles initializing the database before parallel tests are run | ||
\ir utils/sift10k_array.sql | ||
\ir utils/random_array.sql | ||
|
||
CREATE SEQUENCE serial START 10001; | ||
CREATE INDEX ON sift_base10k USING HNSW (v) WITH (M=5, ef=20, ef_construction=20); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- This file contains invariants to be checked after the parallel tests have run | ||
SELECT COUNT(*) FROM sift_base10k; | ||
SELECT * from sift_base10k WHERE id=4444; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SELECT v AS v1111 FROM sift_base10k WHERE id = 1111 \gset | ||
SELECT v AS v2222 FROM sift_base10k WHERE id = 2222 \gset | ||
SELECT v AS v3333 FROM sift_base10k WHERE id = 3333 \gset | ||
SELECT v AS v4444 FROM sift_base10k WHERE id = 4444 \gset | ||
-- Make sure that our index queries will actually run against the index | ||
EXPLAIN (COSTS false) SELECT id FROM sift_base10k ORDER BY v <-> :'v1111' ASC LIMIT 1; | ||
-- Do the queries | ||
SELECT id FROM sift_base10k ORDER BY v <-> :'v1111' ASC LIMIT 1; | ||
SELECT id FROM sift_base10k ORDER BY v <-> :'v2222' ASC LIMIT 1; | ||
SELECT id FROM sift_base10k ORDER BY v <-> :'v3333' ASC LIMIT 1; | ||
SELECT id FROM sift_base10k ORDER BY v <-> :'v4444' ASC LIMIT 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
-- test helper functions that should exist in all test runs live here | ||
-- there is no need to explicitly include this file in other tests as the test runner will | ||
-- run this before running the actual test | ||
|
||
CREATE EXTENSION pageinspect; | ||
|
||
\set ON_ERROR_STOP on | ||
|
||
-- retrieves details for all indices associated with a given table, similar to \di+ | ||
-- the output of \di+ is not consistent across postgres versions | ||
-- todo:: add a columns to this function which returning number of used DB pages | ||
CREATE OR REPLACE FUNCTION ldb_get_indexes(tblname text) | ||
RETURNS TABLE( | ||
indexname name, | ||
size text, | ||
indexdef text, | ||
total_index_size text | ||
) AS | ||
$BODY$ | ||
BEGIN | ||
RETURN QUERY | ||
WITH total_size_data AS ( | ||
SELECT | ||
SUM(pg_relation_size(indexrelid)) as total_size | ||
FROM | ||
pg_index | ||
WHERE | ||
indisvalid | ||
AND indrelid = tblname::regclass | ||
) | ||
SELECT | ||
idx.indexname, | ||
pg_size_pretty(pg_relation_size(idx.indexname::REGCLASS)) as size, | ||
idx.indexdef, | ||
pg_size_pretty(total_size_data.total_size) as total_index_size | ||
FROM | ||
pg_indexes idx, | ||
total_size_data | ||
WHERE | ||
idx.tablename = tblname; | ||
END; | ||
$BODY$ | ||
LANGUAGE plpgsql; | ||
|
||
-- Determines if the provided SQL query (with an EXPLAIN prefix) uses an "Index Scan" | ||
-- by examining its execution plan. This function helps ensure consistent analysis | ||
-- across varying Postgres versions where EXPLAIN output may differ. | ||
CREATE OR REPLACE FUNCTION has_index_scan(explain_query text) RETURNS boolean AS $$ | ||
DECLARE | ||
plan_row RECORD; | ||
found boolean := false; | ||
BEGIN | ||
FOR plan_row IN EXECUTE explain_query LOOP | ||
IF position('Index Scan' in plan_row."QUERY PLAN") > 0 THEN | ||
found := true; | ||
EXIT; | ||
END IF; | ||
END LOOP; | ||
RETURN found; | ||
END; | ||
$$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$ | ||
begin | ||
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim - 1)); | ||
end | ||
$BODY$ LANGUAGE plpgsql; | ||
|
||
CREATE OR REPLACE FUNCTION random_array(dim integer, min real, max real) RETURNS REAL[] AS $BODY$ | ||
begin | ||
return (select array_agg(random() * (max - min) + min) from generate_series (0, dim - 1)); | ||
end | ||
$BODY$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE IF NOT EXISTS sift_base10k ( | ||
id SERIAL PRIMARY KEY, | ||
v REAL[128] | ||
); | ||
\copy sift_base10k (v) FROM '/tmp/lantern/vector_datasets/siftsmall_base_arrays.csv' with csv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# schedule.txt rules: | ||
# - every test that needs to be run must appear in a 'test:' line | ||
# - every test that needs to be run iff pgvector is installed appears in a 'test_pgvector:' line | ||
# - 'test' lines may have multiple space-separated tests. All tests in a single 'test' line will be run in parallel | ||
# parallel_schedule.txt notes: | ||
# - Begin runs before and end runs after the actual tests, they run in the same database, but begin runs before to handle the necessary setup and end runs after to check invariants. | ||
|
||
test_begin: begin | ||
test: insert insert2 insert3 select | ||
test_end: end |
Oops, something went wrong.