Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
Parsed test spec with 3 sessions
 
starting permutation: s1_wait_before_lock s2_updates s2_check s2_wakeup_before_lock s1_check
injection_points_attach
-----------------------
                       
(1 row)
 
step s1_wait_before_lock: 
    REPACK (CONCURRENTLY) repack_toast;
 <waiting ...>
step s2_updates: 
    DELETE FROM repack_toast WHERE i=1;
    INSERT INTO repack_toast(i, j, k) VALUES (1, gen_external(), gen_compressible(1));
 
    -- existing toast data unchanged.  (This covers the case where we
    -- adjust the toast pointer.)
    UPDATE repack_toast SET i=i+300 where i % 10 = 2 RETURNING OLD.i, NEW.i;
 
    -- "j" is here an external indirect, written to the file separately.
    UPDATE repack_toast SET j=gen_external() where i % 10 = 3 RETURNING OLD.i, NEW.i;
 
    -- the updated value of "j" is compressed.
    UPDATE repack_toast SET j=gen_compressible(1), k=k||'' where i % 10 = 4 RETURNING i;
 
    -- the updated value of "j" is compressed externally.
    UPDATE repack_toast SET j=gen_compressible_external(2) where i % 10 = 5 RETURNING i;
 
    -- the updated value of "j" stays inline.
    UPDATE repack_toast SET j=gen_inline(), k=repeat(k,5) where i % 10 = 6 RETURNING i;
 
    -- updated value of "j" is a short varlena; "k" is written separately.
    UPDATE repack_toast SET j=gen_short(), k=gen_external() where i % 10 = 7 RETURNING i;
 
 i|  i
--+---
 2|302
12|312
(2 rows)
 
 i| i
--+--
 3| 3
13|13
(2 rows)
 
 i
--
 4
14
(2 rows)
 
 i
--
 5
15
(2 rows)
 
 i
--
 6
16
(2 rows)
 
 i
--
 7
17
(2 rows)
 
step s2_check: 
    INSERT INTO relfilenodes(node)
    SELECT c2.relfilenode
    FROM pg_class c1 JOIN pg_class c2 ON c2.oid = c1.oid OR c2.oid = c1.reltoastrelid
    WHERE c1.relname='repack_toast';
 
    INSERT INTO data_s2(i, j, j_toast, k, k_toast)
    SELECT i, j, COALESCE(pg_column_toast_chunk_id(j), 0) AS j_toast,
    k, COALESCE(pg_column_toast_chunk_id(k), 0) AS k_toast
    FROM repack_toast;
 
step s2_wakeup_before_lock: 
    SELECT injection_points_wakeup('repack-concurrently-before-lock');
 
injection_points_wakeup
-----------------------
                       
(1 row)
 
step s1_wait_before_lock: <... completed>
step s1_check: 
    INSERT INTO relfilenodes(node)
    SELECT c2.relfilenode
    FROM pg_class c1 JOIN pg_class c2 ON c2.oid = c1.oid OR c2.oid = c1.reltoastrelid
    WHERE c1.relname='repack_toast';
 
    SELECT count(DISTINCT node) FROM relfilenodes;
 
    INSERT INTO data_s1(i, j, j_toast, k, k_toast)
    SELECT i,
    j, COALESCE(pg_column_toast_chunk_id(j), 0) AS j_toast,
    k, COALESCE(pg_column_toast_chunk_id(k), 0) AS k_toast
    FROM repack_toast;
 
    -- this should be empty
    SELECT d1.i, substring(d1.j FOR 12) AS d1_j, substring(d1.k FOR 12) AS d1_k,
        d2.i, substring(d2.j FOR 12) AS d2_j, substring(d2.k FOR 12) AS d2_k,
        d1.j_toast as d1_j_tst, d2.j_toast as d2_j_tst,
        d1.k_toast as d1_k_tst, d2.k_toast AS d2_k_tst
    FROM data_s1 d1 FULL JOIN data_s2 d2 USING (i, j, k)
    WHERE d1.i ISNULL OR d2.i ISNULL;
 
count
-----
    4
(1 row)
 
i|d1_j|d1_k|i|d2_j|d2_k|d1_j_tst|d2_j_tst|d1_k_tst|d2_k_tst
-+----+----+-+----+----+--------+--------+--------+--------
(0 rows)
 
injection_points_detach
-----------------------
                       
(1 row)
 
 
starting permutation: s2_begin s1_wait_before_lock s3_rewrite_toast s3_noop s2_commit s2_updates s2_check s2_wakeup_before_lock s1_check
injection_points_attach
-----------------------
                       
(1 row)
 
step s2_begin: 
    BEGIN;
    SELECT pg_current_xact_id() IS NOT NULL AS has_xid;
 
has_xid
-------
t      
(1 row)
 
step s1_wait_before_lock: 
    REPACK (CONCURRENTLY) repack_toast;
 <waiting ...>
step s3_rewrite_toast: 
    SET lock_timeout = '10ms';
    DO $$
    BEGIN
        EXECUTE format('REPACK %s',
                       (SELECT reltoastrelid::regclass FROM pg_class
                        WHERE relname = 'repack_toast'));
    END;
    $$;
 <waiting ...>
step s3_rewrite_toast: <... completed>
ERROR:  canceling statement due to lock timeout
step s3_noop: 
step s2_commit: 
    COMMIT;
 
step s2_updates: 
    DELETE FROM repack_toast WHERE i=1;
    INSERT INTO repack_toast(i, j, k) VALUES (1, gen_external(), gen_compressible(1));
 
    -- existing toast data unchanged.  (This covers the case where we
    -- adjust the toast pointer.)
    UPDATE repack_toast SET i=i+300 where i % 10 = 2 RETURNING OLD.i, NEW.i;
 
    -- "j" is here an external indirect, written to the file separately.
    UPDATE repack_toast SET j=gen_external() where i % 10 = 3 RETURNING OLD.i, NEW.i;
 
    -- the updated value of "j" is compressed.
    UPDATE repack_toast SET j=gen_compressible(1), k=k||'' where i % 10 = 4 RETURNING i;
 
    -- the updated value of "j" is compressed externally.
    UPDATE repack_toast SET j=gen_compressible_external(2) where i % 10 = 5 RETURNING i;
 
    -- the updated value of "j" stays inline.
    UPDATE repack_toast SET j=gen_inline(), k=repeat(k,5) where i % 10 = 6 RETURNING i;
 
    -- updated value of "j" is a short varlena; "k" is written separately.
    UPDATE repack_toast SET j=gen_short(), k=gen_external() where i % 10 = 7 RETURNING i;
 
 i|  i
--+---
 2|302
12|312
(2 rows)
 
 i| i
--+--
 3| 3
13|13
(2 rows)
 
 i
--
 4
14
(2 rows)
 
 i
--
 5
15
(2 rows)
 
 i
--
 6
16
(2 rows)
 
 i
--
 7
17
(2 rows)
 
step s2_check: 
    INSERT INTO relfilenodes(node)
    SELECT c2.relfilenode
    FROM pg_class c1 JOIN pg_class c2 ON c2.oid = c1.oid OR c2.oid = c1.reltoastrelid
    WHERE c1.relname='repack_toast';
 
    INSERT INTO data_s2(i, j, j_toast, k, k_toast)
    SELECT i, j, COALESCE(pg_column_toast_chunk_id(j), 0) AS j_toast,
    k, COALESCE(pg_column_toast_chunk_id(k), 0) AS k_toast
    FROM repack_toast;
 
step s2_wakeup_before_lock: 
    SELECT injection_points_wakeup('repack-concurrently-before-lock');
 
injection_points_wakeup
-----------------------
                       
(1 row)
 
step s1_wait_before_lock: <... completed>
step s1_check: 
    INSERT INTO relfilenodes(node)
    SELECT c2.relfilenode
    FROM pg_class c1 JOIN pg_class c2 ON c2.oid = c1.oid OR c2.oid = c1.reltoastrelid
    WHERE c1.relname='repack_toast';
 
    SELECT count(DISTINCT node) FROM relfilenodes;
 
    INSERT INTO data_s1(i, j, j_toast, k, k_toast)
    SELECT i,
    j, COALESCE(pg_column_toast_chunk_id(j), 0) AS j_toast,
    k, COALESCE(pg_column_toast_chunk_id(k), 0) AS k_toast
    FROM repack_toast;
 
    -- this should be empty
    SELECT d1.i, substring(d1.j FOR 12) AS d1_j, substring(d1.k FOR 12) AS d1_k,
        d2.i, substring(d2.j FOR 12) AS d2_j, substring(d2.k FOR 12) AS d2_k,
        d1.j_toast as d1_j_tst, d2.j_toast as d2_j_tst,
        d1.k_toast as d1_k_tst, d2.k_toast AS d2_k_tst
    FROM data_s1 d1 FULL JOIN data_s2 d2 USING (i, j, k)
    WHERE d1.i ISNULL OR d2.i ISNULL;
 
count
-----
    4
(1 row)
 
i|d1_j|d1_k|i|d2_j|d2_k|d1_j_tst|d2_j_tst|d1_k_tst|d2_k_tst
-+----+----+-+----+----+--------+--------+--------+--------
(0 rows)
 
injection_points_detach
-----------------------
                       
(1 row)