Исходный код СУБД 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
--
-- one_c_temp_memory_catalog_define_relation
--
 
SET client_min_messages = warning;
 
SET enable_temp_memory_catalog = off;
 
CREATE TEMP TABLE tmc_defrel_phys(
    id integer NOT NULL,
    value integer DEFAULT 5,
    CHECK (value > 0)
);
 
WITH phys_oid AS (
    SELECT 'pg_temp.tmc_defrel_phys'::regclass AS oid
)
SELECT
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = phys_oid.oid) AS pg_class_rows,
    (SELECT count(*) > 0
     FROM pg_catalog.pg_attribute
     WHERE attrelid = phys_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows_present,
    (SELECT count(*) > 0
     FROM pg_catalog.pg_attrdef
     WHERE adrelid = phys_oid.oid) AS pg_attrdef_rows_present,
    (SELECT count(*) > 0
     FROM pg_catalog.pg_constraint
     WHERE conrelid = phys_oid.oid) AS pg_constraint_rows_present
FROM phys_oid;
 
INSERT INTO pg_temp.tmc_defrel_phys(id, value)
VALUES (1, DEFAULT), (2, 9);
 
SELECT id, value
FROM pg_temp.tmc_defrel_phys
ORDER BY id;
 
SET enable_temp_memory_catalog = on;
 
CREATE TEMP TABLE tmc_defrel_mem(
    id integer NOT NULL,
    value integer DEFAULT 7,
    CHECK (value > 0)
);
 
SELECT to_regclass('pg_temp.tmc_defrel_mem') IS NOT NULL AS mem_table_visible;
 
SET enable_temp_memory_catalog = off;
 
INSERT INTO pg_temp.tmc_defrel_mem(id, value)
VALUES (10, DEFAULT), (11, 8);
 
SELECT id, value
FROM pg_temp.tmc_defrel_mem
ORDER BY id;
 
DO $$
DECLARE
    check_failed boolean := false;
BEGIN
    BEGIN
        INSERT INTO pg_temp.tmc_defrel_mem(id, value)
        VALUES (12, 0);
    EXCEPTION
        WHEN check_violation THEN
            check_failed := true;
    END;
 
    IF NOT check_failed THEN
        RAISE EXCEPTION 'tmc_defrel_mem check constraint did not fire';
    END IF;
END;
$$;
 
WITH mem_oid AS (
    SELECT to_regclass('pg_temp.tmc_defrel_mem') AS oid
)
SELECT
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = mem_oid.oid) AS pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attribute
     WHERE attrelid = mem_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows,
    (SELECT count(*) FROM pg_catalog.pg_attrdef
     WHERE adrelid = mem_oid.oid) AS pg_attrdef_rows,
    (SELECT count(*) FROM pg_catalog.pg_constraint
     WHERE conrelid = mem_oid.oid) AS pg_constraint_rows
FROM mem_oid;
 
SET enable_temp_memory_catalog = on;
 
WITH phys_oid AS (
    SELECT 'pg_temp.tmc_defrel_phys'::regclass AS oid
)
SELECT
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = phys_oid.oid) AS pg_class_rows,
    (SELECT count(*) > 0
     FROM pg_catalog.pg_attribute
     WHERE attrelid = phys_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows_present,
    (SELECT count(*) > 0
     FROM pg_catalog.pg_attrdef
     WHERE adrelid = phys_oid.oid) AS pg_attrdef_rows_present,
    (SELECT count(*) > 0
     FROM pg_catalog.pg_constraint
     WHERE conrelid = phys_oid.oid) AS pg_constraint_rows_present
FROM phys_oid;
 
CREATE TEMP VIEW tmc_defrel_view AS
SELECT 41::integer AS answer;
 
SET enable_temp_memory_catalog = off;
 
SELECT answer
FROM pg_temp.tmc_defrel_view;
 
WITH view_oid AS (
    SELECT to_regclass('pg_temp.tmc_defrel_view') AS oid
)
SELECT
    to_regclass('pg_temp.tmc_defrel_view') IS NOT NULL AS view_visible,
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = view_oid.oid) AS pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attribute
     WHERE attrelid = view_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS pg_attribute_rows
FROM view_oid;
 
SET enable_temp_memory_catalog = on;
 
CREATE TEMP TABLE tmc_defrel_part(
    id integer NOT NULL,
    value integer,
    CHECK (value > 0)
) PARTITION BY RANGE (id);
 
CREATE TEMP TABLE tmc_defrel_part_1
PARTITION OF pg_temp.tmc_defrel_part
FOR VALUES FROM (0) TO (100);
 
SET enable_temp_memory_catalog = off;
 
INSERT INTO pg_temp.tmc_defrel_part(id, value)
VALUES (5, 15);
 
SELECT id, value
FROM pg_temp.tmc_defrel_part_1;
 
WITH parent_oid AS (
    SELECT to_regclass('pg_temp.tmc_defrel_part') AS oid
),
child_oid AS (
    SELECT to_regclass('pg_temp.tmc_defrel_part_1') AS oid
)
SELECT
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = parent_oid.oid) AS parent_pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attribute
     WHERE attrelid = parent_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS parent_pg_attribute_rows,
    (SELECT count(*) FROM pg_catalog.pg_partitioned_table
     WHERE partrelid = parent_oid.oid) AS parent_pg_partitioned_table_rows,
    (SELECT count(*) FROM pg_catalog.pg_class WHERE oid = child_oid.oid) AS child_pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attribute
     WHERE attrelid = child_oid.oid
       AND attnum > 0
       AND NOT attisdropped) AS child_pg_attribute_rows,
    (SELECT count(*) FROM pg_catalog.pg_inherits
     WHERE inhrelid = child_oid.oid
       AND inhparent = parent_oid.oid) AS pg_inherits_rows
FROM parent_oid, child_oid;
 
SET enable_temp_memory_catalog = on;
 
BEGIN;
SAVEPOINT tmc_defrel_s;
 
CREATE TEMP TABLE tmc_defrel_rb(
    id integer NOT NULL,
    value integer DEFAULT 9,
    CONSTRAINT tmc_defrel_rb_value_check CHECK (value > 0)
);
 
SELECT to_regclass('pg_temp.tmc_defrel_rb') IS NOT NULL AS rb_visible_inside;
 
ROLLBACK TO SAVEPOINT tmc_defrel_s;
RELEASE SAVEPOINT tmc_defrel_s;
COMMIT;
 
WITH phys AS (
    SELECT oid
    FROM pg_catalog.pg_class
    WHERE relnamespace = pg_my_temp_schema()
      AND relname = 'tmc_defrel_rb'
)
SELECT
    to_regclass('pg_temp.tmc_defrel_rb') IS NULL AS rb_missing_after,
    (SELECT count(*) FROM phys) AS pg_class_rows,
    (SELECT count(*) FROM pg_catalog.pg_attrdef
     WHERE adrelid IN (SELECT oid FROM phys)) AS pg_attrdef_rows,
    (SELECT count(*) FROM pg_catalog.pg_constraint
     WHERE conname = 'tmc_defrel_rb_value_check') AS pg_constraint_rows
;
 
DROP VIEW pg_temp.tmc_defrel_view;
DROP TABLE pg_temp.tmc_defrel_part;
DROP TABLE pg_temp.tmc_defrel_mem;
DROP TABLE pg_temp.tmc_defrel_phys;
 
RESET enable_temp_memory_catalog;