Исходный код СУБД 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
--
-- one_c_temp_memory_catalog_basic
--
SET client_min_messages = warning;
DO $$
BEGIN
    IF current_setting('enable_temp_memory_catalog') <> 'off' THEN
        RAISE EXCEPTION 'unexpected default enable_temp_memory_catalog: %',
            current_setting('enable_temp_memory_catalog');
    END IF;
END;
$$;
CREATE TEMP TABLE tmc_off(id integer);
DO $$
DECLARE
    off_oid oid;
    rowcount bigint;
BEGIN
    off_oid := to_regclass('pg_temp.tmc_off');
    IF off_oid IS NULL THEN
        RAISE EXCEPTION 'tmc_off is missing while GUC is off';
    END IF;
 
    SELECT count(*) INTO rowcount
    FROM pg_catalog.pg_class
    WHERE oid = off_oid;
 
    IF rowcount <> 1 THEN
        RAISE EXCEPTION 'unexpected physical pg_class rowcount for tmc_off: got %, expected 1',
            rowcount;
    END IF;
END;
$$;
DROP TABLE pg_temp.tmc_off;
SELECT to_regclass('pg_temp.tmc_mem') IS NULL AS precreate_missing;
 precreate_missing 
-------------------
 t
(1 row)
 
SET enable_temp_memory_catalog = on;
CREATE TEMP SEQUENCE tmc_sequence_control;
DO $$
DECLARE
    seq_oid oid;
    rowcount bigint;
BEGIN
    seq_oid := to_regclass('pg_temp.tmc_sequence_control');
    IF seq_oid IS NULL THEN
        RAISE EXCEPTION 'tmc_sequence_control is missing';
    END IF;
 
    SELECT count(*) INTO rowcount
    FROM pg_catalog.pg_class
    WHERE oid = seq_oid;
 
    IF rowcount <> 0 THEN
        RAISE EXCEPTION
            'unexpected physical pg_class rowcount for tmc_sequence_control: got %, expected 0',
            rowcount;
    END IF;
END;
$$;
DROP SEQUENCE pg_temp.tmc_sequence_control;
CREATE TEMP TABLE tmc_mem(
    id integer,
    payload integer
);
INSERT INTO pg_temp.tmc_mem
VALUES (1, 10),
       (2, 20);
DO $$
DECLARE
    mem_oid oid;
    rowcount bigint;
    sum_ids bigint;
BEGIN
    SELECT to_regclass('pg_temp.tmc_mem') INTO mem_oid;
    IF mem_oid IS NULL THEN
        RAISE EXCEPTION 'tmc_mem is not visible through to_regclass';
    END IF;
 
    SELECT count(*), sum(id)
    INTO rowcount, sum_ids
    FROM pg_temp.tmc_mem;
 
    IF rowcount <> 2 OR sum_ids <> 3 THEN
        RAISE EXCEPTION 'unexpected tmc_mem contents: rowcount %, sum %',
            rowcount, sum_ids;
    END IF;
 
    SELECT count(*) INTO rowcount
    FROM pg_catalog.pg_class
    WHERE oid = mem_oid;
 
    IF rowcount <> 0 THEN
        RAISE EXCEPTION 'unexpected physical pg_class rowcount for tmc_mem: got %, expected 0',
            rowcount;
    END IF;
 
    SELECT count(*) INTO rowcount
    FROM pg_catalog.pg_attribute
    WHERE attrelid = mem_oid
      AND attnum > 0;
 
    IF rowcount <> 0 THEN
        RAISE EXCEPTION 'unexpected physical pg_attribute rowcount for tmc_mem: got %, expected 0',
            rowcount;
    END IF;
 
    SELECT count(*) INTO rowcount
    FROM pg_catalog.pg_type
    WHERE typrelid = mem_oid;
 
    IF rowcount <> 0 THEN
        RAISE EXCEPTION 'unexpected physical pg_type rowcount for tmc_mem: got %, expected 0',
            rowcount;
    END IF;
END;
$$;
SELECT to_regclass('pg_temp.tmc_mem') IS NOT NULL AS prerename_present;
 prerename_present 
-------------------
 t
(1 row)
 
SELECT to_regclass('pg_temp.tmc_mem_renamed') IS NULL
       AS prerenamed_missing;
 prerenamed_missing 
--------------------
 t
(1 row)
 
SET enable_temp_memory_catalog = off;
ALTER TABLE pg_temp.tmc_mem
RENAME TO tmc_mem_renamed;
SELECT to_regclass('pg_temp.tmc_mem') IS NULL AS old_name_missing;
 old_name_missing 
------------------
 t
(1 row)
 
SELECT to_regclass('pg_temp.tmc_mem_renamed') IS NOT NULL AS new_name_present;
 new_name_present 
------------------
 t
(1 row)
 
CREATE TEMP TABLE tmc_physical_after(id integer);
DO $$
DECLARE
    physical_oid oid;
    rowcount bigint;
BEGIN
    physical_oid := to_regclass('pg_temp.tmc_physical_after');
    IF physical_oid IS NULL THEN
        RAISE EXCEPTION 'tmc_physical_after is missing while GUC is off';
    END IF;
 
    SELECT count(*) INTO rowcount
    FROM pg_catalog.pg_class
    WHERE oid = physical_oid;
 
    IF rowcount <> 1 THEN
        RAISE EXCEPTION 'unexpected physical pg_class rowcount for tmc_physical_after: got %, expected 1',
            rowcount;
    END IF;
 
    IF to_regclass('pg_temp.tmc_mem_renamed') IS NULL THEN
        RAISE EXCEPTION 'tmc_mem_renamed disappeared after creating physical temp table';
    END IF;
END;
$$;
DROP TABLE pg_temp.tmc_physical_after;
DROP TABLE pg_temp.tmc_mem_renamed;
SELECT to_regclass('pg_temp.tmc_mem_renamed') IS NULL AS dropped_memory_missing;
 dropped_memory_missing 
------------------------
 t
(1 row)
 
SET enable_temp_memory_catalog = on;
BEGIN;
CREATE TEMP TABLE tmc_rollback(id integer);
SELECT to_regclass('pg_temp.tmc_rollback') IS NOT NULL
       AS rollback_created;
 rollback_created 
------------------
 t
(1 row)
 
ROLLBACK;
SELECT to_regclass('pg_temp.tmc_rollback') IS NULL AS rollback_missing;
 rollback_missing 
------------------
 t
(1 row)
 
BEGIN;
SAVEPOINT tmc_s;
CREATE TEMP TABLE tmc_savepoint(id integer);
SELECT to_regclass('pg_temp.tmc_savepoint') IS NOT NULL AS savepoint_created;
 savepoint_created 
-------------------
 t
(1 row)
 
ROLLBACK TO SAVEPOINT tmc_s;
RELEASE SAVEPOINT tmc_s;
COMMIT;
SELECT to_regclass('pg_temp.tmc_savepoint') IS NULL AS savepoint_missing_after_commit;
 savepoint_missing_after_commit 
--------------------------------
 t
(1 row)
 
RESET enable_temp_memory_catalog;