diff --git a/scripts/run_all_tests.sh b/scripts/run_all_tests.sh index 46109f201..6c0e2c9f5 100755 --- a/scripts/run_all_tests.sh +++ b/scripts/run_all_tests.sh @@ -85,11 +85,15 @@ if [ "$PARALLEL" -eq 1 ]; then else SCHEDULE='schedule.txt' fi -if [ -n "$FILTER" ] && [ -z "$PARALLEL" ]; then - if [[ "$pgvector_installed" == "1" ]]; then - TEST_FILES=$(cat $SCHEDULE | grep -E '^(test:|test_pgvector:)' | sed -E -e 's/^test:|test_pgvector://' | tr " " "\n" | sed -e '/^$/d') +if [ -n "$FILTER" ]; then + if [ "$PARALLEL" -eq 1 ]; then + TEST_FILES=$(cat $SCHEDULE | grep -E '^(test:|test_begin:|test_end:)' | sed -E -e 's/^test:|test_begin:|test_end://' | tr " " "\n" | sed -e '/^$/d') else - TEST_FILES=$(cat $SCHEDULE | grep '^test:' | sed -e 's/^test://' | tr " " "\n" | sed -e '/^$/d') + if [[ "$pgvector_installed" == "1" ]]; then + TEST_FILES=$(cat $SCHEDULE | grep -E '^(test:|test_pgvector:)' | sed -E -e 's/^test:|test_pgvector://' | tr " " "\n" | sed -e '/^$/d') + else + TEST_FILES=$(cat $SCHEDULE | grep '^test:' | sed -e 's/^test://' | tr " " "\n" | sed -e '/^$/d') + fi fi while IFS= read -r f; do diff --git a/test/parallel/expected/begin.out b/test/parallel/expected/begin.out index 55d3de5a5..d04b8895a 100644 --- a/test/parallel/expected/begin.out +++ b/test/parallel/expected/begin.out @@ -4,6 +4,18 @@ CREATE TABLE IF NOT EXISTS sift_base10k ( 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 diff --git a/test/parallel/expected/insert.out b/test/parallel/expected/insert.out index 91a05b630..604cf2ccd 100644 --- a/test/parallel/expected/insert.out +++ b/test/parallel/expected/insert.out @@ -1,17 +1,13 @@ -\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; -DO $$ -BEGIN - FOR i IN 1..10 LOOP - INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); - END LOOP; -END; $$ +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; diff --git a/test/parallel/expected/insert2.out b/test/parallel/expected/insert2.out index 91a05b630..604cf2ccd 100644 --- a/test/parallel/expected/insert2.out +++ b/test/parallel/expected/insert2.out @@ -1,17 +1,13 @@ -\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; -DO $$ -BEGIN - FOR i IN 1..10 LOOP - INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); - END LOOP; -END; $$ +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; diff --git a/test/parallel/expected/insert3.out b/test/parallel/expected/insert3.out index 91a05b630..604cf2ccd 100644 --- a/test/parallel/expected/insert3.out +++ b/test/parallel/expected/insert3.out @@ -1,17 +1,13 @@ -\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; -DO $$ -BEGIN - FOR i IN 1..10 LOOP - INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); - END LOOP; -END; $$ +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; diff --git a/test/parallel/expected/select.out b/test/parallel/expected/select.out new file mode 100644 index 000000000..8e0a6407a --- /dev/null +++ b/test/parallel/expected/select.out @@ -0,0 +1,28 @@ +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 +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) + diff --git a/test/parallel/sql/begin.sql b/test/parallel/sql/begin.sql index bc38c00f4..1681f596f 100644 --- a/test/parallel/sql/begin.sql +++ b/test/parallel/sql/begin.sql @@ -1,3 +1,5 @@ \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); diff --git a/test/parallel/sql/insert.sql b/test/parallel/sql/insert.sql index 6b3fcd24f..604cf2ccd 100644 --- a/test/parallel/sql/insert.sql +++ b/test/parallel/sql/insert.sql @@ -1,7 +1,13 @@ -\ir utils/random_array.sql -DO $$ -BEGIN - FOR i IN 1..10 LOOP - INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); - END LOOP; -END; $$ +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; diff --git a/test/parallel/sql/insert2.sql b/test/parallel/sql/insert2.sql index 6b3fcd24f..604cf2ccd 100644 --- a/test/parallel/sql/insert2.sql +++ b/test/parallel/sql/insert2.sql @@ -1,7 +1,13 @@ -\ir utils/random_array.sql -DO $$ -BEGIN - FOR i IN 1..10 LOOP - INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); - END LOOP; -END; $$ +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; diff --git a/test/parallel/sql/insert3.sql b/test/parallel/sql/insert3.sql index 6b3fcd24f..604cf2ccd 100644 --- a/test/parallel/sql/insert3.sql +++ b/test/parallel/sql/insert3.sql @@ -1,7 +1,13 @@ -\ir utils/random_array.sql -DO $$ -BEGIN - FOR i IN 1..10 LOOP - INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); - END LOOP; -END; $$ +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; diff --git a/test/parallel/sql/select.sql b/test/parallel/sql/select.sql new file mode 100644 index 000000000..3aafecad2 --- /dev/null +++ b/test/parallel/sql/select.sql @@ -0,0 +1,8 @@ +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 +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; diff --git a/test/parallel_schedule.txt b/test/parallel_schedule.txt index a60f04b09..83eccac0b 100644 --- a/test/parallel_schedule.txt +++ b/test/parallel_schedule.txt @@ -4,5 +4,5 @@ # - 'test' lines may have multiple space-separated tests. All tests in a single 'test' line will be run in parallel test_begin: begin -test: insert insert2 insert3 +test: insert insert2 insert3 select test_end: end