Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-04-30 9f2ef60949ced4fab4d077a7e1c6d913f3620c9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
 
# Initialize node
my $node = PostgreSQL::Test::Cluster->new('node');
$node->init;
$node->start;
 
# Create table
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
$node->safe_psql("postgres", "CREATE TABLE tst (v bit(3));");
 
sub insert_vectors
{
    for my $i (1 .. 20)
    {
        $node->safe_psql("postgres", "INSERT INTO tst VALUES ('111');");
    }
}
 
sub test_duplicates
{
    my $res = $node->safe_psql("postgres", qq(
        SET enable_seqscan = off;
        SET hnsw.ef_search = 1;
        SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <~> '111') t;
    ));
    is($res, 10);
}
 
# Test duplicates with build
insert_vectors();
$node->safe_psql("postgres", "CREATE INDEX idx ON tst USING hnsw (v bit_hamming_ops);");
test_duplicates();
 
# Reset
$node->safe_psql("postgres", "TRUNCATE tst;");
 
# Test duplicates with inserts
insert_vectors();
test_duplicates();
 
# Test fallback path for inserts
$node->pgbench(
    "--no-vacuum --client=5 --transactions=100",
    0,
    [qr{actually processed}],
    [qr{^$}],
    "concurrent INSERTs",
    {
        "026_hnsw_bit_duplicates" => "INSERT INTO tst VALUES ('111');"
    }
);
 
done_testing();