mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-06 05:51:21 +08:00
Fixed failed to add index item error with sparsevec - fixes #625
This commit is contained in:
38
test/t/038_hnsw_sparsevec_vacuum_insert.pl
Normal file
38
test/t/038_hnsw_sparsevec_vacuum_insert.pl
Normal file
@@ -0,0 +1,38 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use PostgresNode;
|
||||
use TestLib;
|
||||
use Test::More;
|
||||
|
||||
# Initialize node
|
||||
my $node = get_new_node('node');
|
||||
$node->init;
|
||||
$node->start;
|
||||
|
||||
# Create table and index
|
||||
$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);");
|
||||
|
||||
for (1 .. 3) {
|
||||
for (1 .. 100) {
|
||||
my @elements;
|
||||
my %indices;
|
||||
for (1 .. int(rand() * 100)) {
|
||||
my $index = int(rand() * (100000 - 1)) + 1;
|
||||
if (!exists($indices{$index})) {
|
||||
my $value = rand();
|
||||
push(@elements, "$index:$value");
|
||||
$indices{$index} = 1;
|
||||
}
|
||||
}
|
||||
my $embedding = "{" . join(",", @elements) . "}/100000";
|
||||
$node->safe_psql("postgres", "INSERT INTO tst (v) VALUES ('$embedding');");
|
||||
}
|
||||
|
||||
$node->safe_psql("postgres", "DELETE FROM tst WHERE i % 2 = 0;");
|
||||
$node->safe_psql("postgres", "VACUUM tst;");
|
||||
is(1, 1);
|
||||
}
|
||||
|
||||
done_testing();
|
||||
Reference in New Issue
Block a user