Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# REPACK (CONCURRENTLY) on a temporal replica identity index with lossy
# multirange equality.
#
# The leading identity column is of type int4multirange. Two distinct rows
# have different multirange values but the same union range, so GiST equality
# can produce both as candidates and requires exact recheck.
setup
{
    CREATE EXTENSION injection_points;
 
    CREATE TABLE repack_temporal_multirange (
        id int4multirange,
        valid_at datemultirange,
        label text,
        CONSTRAINT rtm_pkey PRIMARY KEY (id, valid_at WITHOUT OVERLAPS)
    );
 
    ALTER TABLE repack_temporal_multirange
        REPLICA IDENTITY USING INDEX rtm_pkey;
 
    -- (1,3)+(5,7) is the same union range of (1-7), but needs recheck
    INSERT INTO repack_temporal_multirange(id, valid_at, label)
    VALUES
        (int4multirange(int4range(1, 3), int4range(5, 7)),
         datemultirange(daterange('2000-01-01', '2000-02-01')),
         'other'),
        (int4multirange(int4range(1, 7)),
         datemultirange(daterange('2000-01-01', '2000-02-01')),
         'target');
 
    CREATE TABLE relfilenodes(node oid);
}
 
teardown
{
    DROP TABLE repack_temporal_multirange;
    DROP EXTENSION injection_points;
    DROP TABLE relfilenodes;
}
 
session s1
setup
{
    SELECT injection_points_set_local();
    SELECT injection_points_attach('repack-concurrently-before-lock', 'wait');
}
step wait_before_lock
{
    REPACK (CONCURRENTLY) repack_temporal_multirange
        USING INDEX rtm_pkey;
}
step final_check
{
    INSERT INTO relfilenodes(node)
    SELECT relfilenode
    FROM pg_class
    WHERE relname = 'repack_temporal_multirange';
 
    -- Expect 2, proving that repack has rewritten the table
    SELECT count(DISTINCT node) FROM relfilenodes;
 
    -- Expect 2 rows
    SELECT id, valid_at, label
    FROM repack_temporal_multirange
    ORDER BY id, valid_at, label;
}
teardown
{
    SELECT injection_points_detach('repack-concurrently-before-lock');
}
 
session s2
step update_target
{
    UPDATE repack_temporal_multirange
    SET label = 'updated'
    WHERE id = int4multirange(int4range(1, 7))
      AND valid_at = datemultirange(daterange('2000-01-01', '2000-02-01'));
}
step check_after_update
{
    INSERT INTO relfilenodes(node)
    SELECT relfilenode
    FROM pg_class
    WHERE relname = 'repack_temporal_multirange';
 
    -- Expect 2 rows
    SELECT id, valid_at, label
    FROM repack_temporal_multirange
    ORDER BY id, valid_at, label;
}
step wakeup_before_lock
{
    SELECT injection_points_wakeup('repack-concurrently-before-lock');
}
 
permutation
    wait_before_lock
    update_target
    check_after_update
    wakeup_before_lock
    final_check