Исходный код СУБД 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
--
-- one_c_temp_storage_parallel
--
 
SET client_min_messages = warning;
 
SET enable_temp_memory_catalog = on;
 
BEGIN;
CREATE TEMP TABLE tmc_storage_mem(
    id integer,
    grp integer,
    payload text
);
INSERT INTO pg_temp.tmc_storage_mem(id, grp, payload)
SELECT g, g % 10, repeat('m', 200)
FROM generate_series(1, 5000) AS g;
CREATE INDEX tmc_storage_mem_idx ON pg_temp.tmc_storage_mem(grp, id);
ANALYZE pg_temp.tmc_storage_mem;
COMMIT;
 
VACUUM pg_temp.tmc_storage_mem;
SELECT count(*) AS mem_rows_after_vacuum,
       sum(id) AS mem_id_sum_after_vacuum
FROM pg_temp.tmc_storage_mem;
REINDEX INDEX pg_temp.tmc_storage_mem_idx;
SELECT count(*) AS mem_rows_after_reindex
FROM pg_temp.tmc_storage_mem
WHERE grp = 0;
 
BEGIN;
TRUNCATE pg_temp.tmc_storage_mem;
INSERT INTO pg_temp.tmc_storage_mem(id, grp, payload)
SELECT g, g % 3, repeat('n', 50)
FROM generate_series(1, 12) AS g;
COMMIT;
 
VACUUM (ANALYZE) pg_temp.tmc_storage_mem;
SELECT count(*) AS mem_rows_after_truncate,
       min(id) AS mem_min_id,
       max(id) AS mem_max_id,
       sum(grp) AS mem_grp_sum
FROM pg_temp.tmc_storage_mem;
 
BEGIN;
DROP TABLE pg_temp.tmc_storage_mem;
COMMIT;
 
SET enable_temp_memory_catalog = off;
 
CREATE TEMP TABLE tmc_storage_phys(
    id integer,
    grp integer
);
INSERT INTO pg_temp.tmc_storage_phys(id, grp)
SELECT g, g % 4
FROM generate_series(1, 20) AS g;
CREATE INDEX tmc_storage_phys_idx ON pg_temp.tmc_storage_phys(grp, id);
VACUUM pg_temp.tmc_storage_phys;
SELECT count(*) AS phys_rows_after_vacuum
FROM pg_temp.tmc_storage_phys;
REINDEX INDEX pg_temp.tmc_storage_phys_idx;
SELECT count(*) AS phys_rows_after_reindex
FROM pg_temp.tmc_storage_phys
WHERE grp = 0;
TRUNCATE pg_temp.tmc_storage_phys;
INSERT INTO pg_temp.tmc_storage_phys(id, grp)
VALUES (10, 1), (20, 2), (30, 3);
SELECT count(*) AS phys_rows_after_truncate,
       sum(id) AS phys_id_sum_after_truncate
FROM pg_temp.tmc_storage_phys;
DROP TABLE pg_temp.tmc_storage_phys;
 
SET enable_temp_memory_catalog = on;
 
BEGIN;
CREATE TEMP TABLE tmc_storage_guc(
    id integer,
    payload text
);
INSERT INTO pg_temp.tmc_storage_guc(id, payload)
SELECT g, repeat('g', 40)
FROM generate_series(1, 9) AS g;
CREATE INDEX tmc_storage_guc_idx ON pg_temp.tmc_storage_guc(id);
COMMIT;
 
SET enable_temp_memory_catalog = off;
 
VACUUM pg_temp.tmc_storage_guc;
REINDEX INDEX pg_temp.tmc_storage_guc_idx;
TRUNCATE pg_temp.tmc_storage_guc;
INSERT INTO pg_temp.tmc_storage_guc(id, payload)
VALUES (41, 'after-off-one'), (42, 'after-off-two');
SELECT count(*) AS guc_rows_after_toggle,
       min(id) AS guc_min_id,
       max(id) AS guc_max_id
FROM pg_temp.tmc_storage_guc;
DROP TABLE pg_temp.tmc_storage_guc;
 
DROP TABLE IF EXISTS tmc_storage_perm;
 
CREATE TABLE tmc_storage_perm(
    id integer,
    grp integer,
    payload text
);
INSERT INTO tmc_storage_perm(id, grp, payload)
SELECT g, g % 8, repeat('p', 200)
FROM generate_series(1, 5000) AS g;
CREATE INDEX tmc_storage_perm_idx ON tmc_storage_perm(grp, id);
ALTER TABLE tmc_storage_perm SET (parallel_workers = 2);
ANALYZE tmc_storage_perm;
VACUUM tmc_storage_perm;
REINDEX INDEX tmc_storage_perm_idx;
TRUNCATE tmc_storage_perm;
INSERT INTO tmc_storage_perm(id, grp, payload)
SELECT g, g % 8, repeat('q', 200)
FROM generate_series(1, 5000) AS g;
ANALYZE tmc_storage_perm;
SELECT count(*) AS perm_rows_after_truncate,
       sum(id) AS perm_id_sum_after_truncate
FROM tmc_storage_perm;
 
SET enable_temp_memory_catalog = on;
 
CREATE TEMP TABLE tmc_storage_mem_parallel(
    id integer,
    grp integer,
    payload text
);
INSERT INTO pg_temp.tmc_storage_mem_parallel(id, grp, payload)
SELECT g, g % 8, repeat('r', 200)
FROM generate_series(1, 5000) AS g;
ALTER TABLE pg_temp.tmc_storage_mem_parallel SET (parallel_workers = 2);
ANALYZE pg_temp.tmc_storage_mem_parallel;
 
SET max_parallel_workers_per_gather = 2;
SET min_parallel_table_scan_size = 0;
SET parallel_setup_cost = 0;
SET parallel_tuple_cost = 0;
SET enable_indexscan = off;
SET enable_indexonlyscan = off;
SET enable_bitmapscan = off;
 
EXPLAIN (COSTS OFF)
SELECT sum(id) FROM tmc_storage_perm;
 
EXPLAIN (COSTS OFF)
SELECT sum(id) FROM pg_temp.tmc_storage_mem_parallel;
 
RESET enable_bitmapscan;
RESET enable_indexonlyscan;
RESET enable_indexscan;
RESET parallel_tuple_cost;
RESET parallel_setup_cost;
RESET min_parallel_table_scan_size;
RESET max_parallel_workers_per_gather;
RESET enable_temp_memory_catalog;
 
DROP TABLE pg_temp.tmc_storage_mem_parallel;
DROP TABLE tmc_storage_perm;