From 222596b450e4b230bfc91b5f144a4ec88d8ebd68 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 2 Dec 2026 21:14:07 -0800 Subject: [PATCH] Improved test [skip ci] --- test/t/038_hnsw_sparsevec_vacuum_insert.pl | 31 +++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/test/t/038_hnsw_sparsevec_vacuum_insert.pl b/test/t/038_hnsw_sparsevec_vacuum_insert.pl index 69c57f00..f724828a 100644 --- a/test/t/038_hnsw_sparsevec_vacuum_insert.pl +++ b/test/t/038_hnsw_sparsevec_vacuum_insert.pl @@ -14,23 +14,28 @@ $node->safe_psql("postgres", "CREATE EXTENSION vector;"); $node->safe_psql("postgres", "CREATE TABLE tst (i serial, v sparsevec(100000));"); $node->safe_psql("postgres", "CREATE INDEX ON tst USING hnsw (v sparsevec_l2_ops);"); +sub random_sparsevec +{ + my @elements; + my %indices; + for (1 .. int(rand(1001))) + { + my $index = int(rand(100000)) + 1; + if (!exists($indices{$index})) + { + my $value = rand(); + push(@elements, "$index:$value"); + $indices{$index} = 1; + } + } + return "{" . join(",", @elements) . "}/100000"; +} + for (1 .. 3) { for (1 .. 100) { - my @elements; - my %indices; - for (1 .. int(rand(1001))) - { - my $index = int(rand(100000)) + 1; - if (!exists($indices{$index})) - { - my $value = rand(); - push(@elements, "$index:$value"); - $indices{$index} = 1; - } - } - my $embedding = "{" . join(",", @elements) . "}/100000"; + my $embedding = random_sparsevec(); $node->safe_psql("postgres", "INSERT INTO tst (v) VALUES ('$embedding');"); }