Исходный код СУБД 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
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
--
-- one_c_temp_memory_catalog_sequence
--
SET client_min_messages = warning;
SET enable_temp_memory_catalog = off;
CREATE TEMP SEQUENCE tmc_seq_phys
    START WITH 10
    INCREMENT BY 3;
WITH seq_oid AS (
    SELECT 'pg_temp.tmc_seq_phys'::regclass AS oid
)
SELECT
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = seq_oid.oid) AS pg_class_rows,
    (SELECT count(*) > 0
     FROM pg_catalog.pg_attribute
     WHERE attrelid = seq_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows_present,
    (SELECT count(*) FROM pg_catalog.pg_sequence WHERE seqrelid = seq_oid.oid) AS pg_sequence_rows,
    (SELECT count(*) > 0
     FROM pg_catalog.pg_depend
     WHERE classid = 'pg_catalog.pg_class'::regclass
       AND objid = seq_oid.oid) AS pg_depend_rows_present
FROM seq_oid;
 pg_class_rows | pg_attribute_rows_present | pg_sequence_rows | pg_depend_rows_present 
---------------+---------------------------+------------------+------------------------
             1 | t                         |                1 | t
(1 row)
 
SELECT nextval('pg_temp.tmc_seq_phys') AS phys_nextval_1;
 phys_nextval_1 
----------------
             10
(1 row)
 
SELECT nextval('pg_temp.tmc_seq_phys') AS phys_nextval_2;
 phys_nextval_2 
----------------
             13
(1 row)
 
SET enable_temp_memory_catalog = on;
ALTER SEQUENCE pg_temp.tmc_seq_phys
    RESTART WITH 20
    INCREMENT BY 5;
SELECT nextval('pg_temp.tmc_seq_phys') AS phys_nextval_3;
 phys_nextval_3 
----------------
             20
(1 row)
 
SELECT nextval('pg_temp.tmc_seq_phys') AS phys_nextval_4;
 phys_nextval_4 
----------------
             25
(1 row)
 
WITH seq_oid AS (
    SELECT 'pg_temp.tmc_seq_phys'::regclass AS oid
)
SELECT
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = seq_oid.oid) AS pg_class_rows,
    (SELECT count(*) > 0
     FROM pg_catalog.pg_attribute
     WHERE attrelid = seq_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows_present,
    (SELECT count(*) FROM pg_catalog.pg_sequence WHERE seqrelid = seq_oid.oid) AS pg_sequence_rows
FROM seq_oid;
 pg_class_rows | pg_attribute_rows_present | pg_sequence_rows 
---------------+---------------------------+------------------
             1 | t                         |                1
(1 row)
 
DROP SEQUENCE pg_temp.tmc_seq_phys;
SET enable_temp_memory_catalog = on;
CREATE TEMP SEQUENCE tmc_seq_mem
    START WITH 2
    INCREMENT BY 4;
WITH seq_oid AS (
    SELECT to_regclass('pg_temp.tmc_seq_mem') AS oid
)
SELECT
    to_regclass('pg_temp.tmc_seq_mem') IS NOT NULL AS mem_seq_visible,
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = seq_oid.oid) AS pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attribute
     WHERE attrelid = seq_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows,
    (SELECT count(*) FROM pg_catalog.pg_sequence WHERE seqrelid = seq_oid.oid) AS pg_sequence_rows,
    (SELECT count(*) FROM pg_catalog.pg_depend
     WHERE classid = 'pg_catalog.pg_class'::regclass
       AND objid = seq_oid.oid) AS pg_depend_rows
FROM seq_oid;
 mem_seq_visible | pg_class_rows | pg_attribute_rows | pg_sequence_rows | pg_depend_rows 
-----------------+---------------+-------------------+------------------+----------------
 t               |             0 |                 0 |                0 |              0
(1 row)
 
SET enable_temp_memory_catalog = off;
SELECT nextval('pg_temp.tmc_seq_mem') AS mem_nextval_1;
 mem_nextval_1 
---------------
             2
(1 row)
 
SELECT currval('pg_temp.tmc_seq_mem') AS mem_currval_1;
 mem_currval_1 
---------------
             2
(1 row)
 
SELECT setval('pg_temp.tmc_seq_mem', 50, false) AS mem_setval;
 mem_setval 
------------
         50
(1 row)
 
SELECT nextval('pg_temp.tmc_seq_mem') AS mem_nextval_2;
 mem_nextval_2 
---------------
            50
(1 row)
 
ALTER SEQUENCE pg_temp.tmc_seq_mem
    RESTART WITH 100
    INCREMENT BY 7;
SELECT nextval('pg_temp.tmc_seq_mem') AS mem_nextval_3;
 mem_nextval_3 
---------------
           100
(1 row)
 
SELECT nextval('pg_temp.tmc_seq_mem') AS mem_nextval_4;
 mem_nextval_4 
---------------
           107
(1 row)
 
WITH seq_oid AS (
    SELECT to_regclass('pg_temp.tmc_seq_mem') AS oid
)
SELECT
    to_regclass('pg_temp.tmc_seq_mem') IS NOT NULL AS mem_seq_visible,
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = seq_oid.oid) AS pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attribute
     WHERE attrelid = seq_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows,
    (SELECT count(*) FROM pg_catalog.pg_sequence WHERE seqrelid = seq_oid.oid) AS pg_sequence_rows
FROM seq_oid;
 mem_seq_visible | pg_class_rows | pg_attribute_rows | pg_sequence_rows 
-----------------+---------------+-------------------+------------------
 t               |             0 |                 0 |                0
(1 row)
 
SET enable_temp_memory_catalog = on;
CREATE TEMP TABLE tmc_seq_owner(id integer);
CREATE TEMP SEQUENCE tmc_seq_owned
    START WITH 1
    INCREMENT BY 1
    OWNED BY tmc_seq_owner.id;
SET enable_temp_memory_catalog = off;
WITH owned_oid AS (
    SELECT to_regclass('pg_temp.tmc_seq_owned') AS oid
),
owner_oid AS (
    SELECT to_regclass('pg_temp.tmc_seq_owner') AS oid
)
SELECT
    to_regclass('pg_temp.tmc_seq_owned') IS NOT NULL AS owned_seq_visible,
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = owned_oid.oid) AS pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attribute
     WHERE attrelid = owned_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows,
    (SELECT count(*) FROM pg_catalog.pg_sequence WHERE seqrelid = owned_oid.oid) AS pg_sequence_rows,
    (SELECT count(*) FROM pg_catalog.pg_depend
     WHERE classid = 'pg_catalog.pg_class'::regclass
       AND objid = owned_oid.oid) AS pg_depend_rows,
    (SELECT count(*) FROM pg_catalog.pg_depend
     WHERE classid = 'pg_catalog.pg_class'::regclass
       AND objid = owned_oid.oid
       AND refclassid = 'pg_catalog.pg_class'::regclass
       AND refobjid = owner_oid.oid
       AND refobjsubid = 1) AS owned_by_depend_rows
FROM owned_oid, owner_oid;
 owned_seq_visible | pg_class_rows | pg_attribute_rows | pg_sequence_rows | pg_depend_rows | owned_by_depend_rows 
-------------------+---------------+-------------------+------------------+----------------+----------------------
 t                 |             0 |                 0 |                0 |              0 |                    0
(1 row)
 
SELECT nextval('pg_temp.tmc_seq_owned') AS owned_nextval_1;
 owned_nextval_1 
-----------------
               1
(1 row)
 
DROP TABLE pg_temp.tmc_seq_owner;
SELECT to_regclass('pg_temp.tmc_seq_owned') IS NULL AS owned_seq_missing_after_drop;
 owned_seq_missing_after_drop 
------------------------------
 t
(1 row)
 
SET enable_temp_memory_catalog = on;
BEGIN;
SAVEPOINT tmc_seq_create_s;
CREATE TEMP SEQUENCE tmc_seq_create_rb
    START WITH 30
    INCREMENT BY 2;
SELECT to_regclass('pg_temp.tmc_seq_create_rb') IS NOT NULL AS create_rb_visible_inside;
 create_rb_visible_inside 
--------------------------
 t
(1 row)
 
SELECT nextval('pg_temp.tmc_seq_create_rb') AS create_rb_nextval_inside;
 create_rb_nextval_inside 
--------------------------
                       30
(1 row)
 
ROLLBACK TO SAVEPOINT tmc_seq_create_s;
RELEASE SAVEPOINT tmc_seq_create_s;
COMMIT;
WITH phys AS (
    SELECT oid
    FROM pg_catalog.pg_class
    WHERE relnamespace = pg_my_temp_schema()
      AND relname = 'tmc_seq_create_rb'
)
SELECT
    to_regclass('pg_temp.tmc_seq_create_rb') IS NULL AS create_rb_missing_after,
    (SELECT count(*) FROM phys) AS pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attribute
     WHERE attrelid IN (SELECT oid FROM phys)
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows,
    (SELECT count(*) FROM pg_catalog.pg_sequence
     WHERE seqrelid IN (SELECT oid FROM phys)) AS pg_sequence_rows;
 create_rb_missing_after | pg_class_rows | pg_attribute_rows | pg_sequence_rows 
-------------------------+---------------+-------------------+------------------
 t                       |             0 |                 0 |                0
(1 row)
 
SET enable_temp_memory_catalog = on;
CREATE TEMP SEQUENCE tmc_seq_drop_rb
    START WITH 300
    INCREMENT BY 2;
SET enable_temp_memory_catalog = off;
BEGIN;
SAVEPOINT tmc_seq_drop_s;
DROP SEQUENCE pg_temp.tmc_seq_drop_rb;
SELECT to_regclass('pg_temp.tmc_seq_drop_rb') IS NULL AS drop_rb_missing_inside;
 drop_rb_missing_inside 
------------------------
 t
(1 row)
 
ROLLBACK TO SAVEPOINT tmc_seq_drop_s;
RELEASE SAVEPOINT tmc_seq_drop_s;
COMMIT;
WITH seq_oid AS (
    SELECT to_regclass('pg_temp.tmc_seq_drop_rb') AS oid
)
SELECT
    to_regclass('pg_temp.tmc_seq_drop_rb') IS NOT NULL AS drop_rb_visible_after,
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = seq_oid.oid) AS pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attribute
     WHERE attrelid = seq_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows,
    (SELECT count(*) FROM pg_catalog.pg_sequence WHERE seqrelid = seq_oid.oid) AS pg_sequence_rows
FROM seq_oid;
 drop_rb_visible_after | pg_class_rows | pg_attribute_rows | pg_sequence_rows 
-----------------------+---------------+-------------------+------------------
 t                     |             0 |                 0 |                0
(1 row)
 
SELECT nextval('pg_temp.tmc_seq_drop_rb') AS drop_rb_nextval_after;
 drop_rb_nextval_after 
-----------------------
                   300
(1 row)
 
SET enable_temp_memory_catalog = on;
CREATE TEMP SEQUENCE tmc_seq_alter_rb
    START WITH 400
    INCREMENT BY 3;
SET enable_temp_memory_catalog = off;
BEGIN;
SAVEPOINT tmc_seq_alter_s;
ALTER SEQUENCE pg_temp.tmc_seq_alter_rb
    INCREMENT BY 11;
ROLLBACK TO SAVEPOINT tmc_seq_alter_s;
RELEASE SAVEPOINT tmc_seq_alter_s;
COMMIT;
SELECT nextval('pg_temp.tmc_seq_alter_rb') AS alter_rb_nextval_1;
 alter_rb_nextval_1 
--------------------
                400
(1 row)
 
SELECT nextval('pg_temp.tmc_seq_alter_rb') AS alter_rb_nextval_2;
 alter_rb_nextval_2 
--------------------
                403
(1 row)
 
WITH seq_oid AS (
    SELECT to_regclass('pg_temp.tmc_seq_alter_rb') AS oid
)
SELECT
    to_regclass('pg_temp.tmc_seq_alter_rb') IS NOT NULL AS alter_rb_visible_after,
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = seq_oid.oid) AS pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attribute
     WHERE attrelid = seq_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows,
    (SELECT count(*) FROM pg_catalog.pg_sequence WHERE seqrelid = seq_oid.oid) AS pg_sequence_rows
FROM seq_oid;
 alter_rb_visible_after | pg_class_rows | pg_attribute_rows | pg_sequence_rows 
------------------------+---------------+-------------------+------------------
 t                      |             0 |                 0 |                0
(1 row)
 
DROP SEQUENCE IF EXISTS pg_temp.tmc_seq_mem;
DROP SEQUENCE IF EXISTS pg_temp.tmc_seq_drop_rb;
DROP SEQUENCE IF EXISTS pg_temp.tmc_seq_alter_rb;
RESET enable_temp_memory_catalog;