Исходный код СУБД 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
-- ----------------------------------------------------------------------
-- REFRESH MATERIALIZED VIEW (CONCURRENTLY) on a CFS materialized view.
--
-- refresh_by_match_merge() builds its transient table via make_new_heap(),
-- which copies the matview's reloptions -- including the CFS policy --
-- into a RELPERSISTENCE_TEMP relation.  Sidecar files cannot exist for a
-- temp locator, so CFS-ness must be refused for temp relations at the
-- policy/smgr level: the CONCURRENTLY refresh must succeed with the
-- transient table stored uncompressed, while the matview itself stays
-- CFS.  Guards: explicit CFS reloptions on TEMP/UNLOGGED tables remain
-- errors (the DDL-level persistence check), and the plain
-- (non-concurrent) refresh keeps working.
-- ----------------------------------------------------------------------
CREATE TABLE mvs (id int PRIMARY KEY, v text);
INSERT INTO mvs SELECT g, md5(g::text) FROM generate_series(1, 1000) g;
 
CREATE MATERIALIZED VIEW mv_cfs WITH (algorithm='lz4') AS SELECT * FROM mvs WITH DATA;
CREATE UNIQUE INDEX mv_cfs_id ON mv_cfs (id);
 
SELECT relkind, is_cfs, algorithm FROM pg_cfs_settings
  WHERE relname = 'mv_cfs';
 
-- Concurrent refresh: the transient temp table inherits the reloptions
-- but must never become a CFS relation.
INSERT INTO mvs SELECT g, md5(g::text) FROM generate_series(1001, 1200) g;
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_cfs;
SELECT count(*) FROM mv_cfs;
 
-- The matview itself stays CFS across the refresh.
SELECT relkind, is_cfs, algorithm FROM pg_cfs_settings
  WHERE relname = 'mv_cfs';
 
-- Plain (non-concurrent) refresh keeps working and keeps CFS.
REFRESH MATERIALIZED VIEW mv_cfs;
SELECT count(*) FROM mv_cfs;
SELECT relkind, is_cfs, algorithm FROM pg_cfs_settings
  WHERE relname = 'mv_cfs';
 
-- The DDL-level persistence guard must not regress: explicit CFS
-- reloptions on TEMP/UNLOGGED tables stay rejected.
CREATE TEMP TABLE mvs_temp (a int) WITH (algorithm='lz4');
CREATE UNLOGGED TABLE mvs_unlogged (a int) WITH (algorithm='lz4');
 
DROP MATERIALIZED VIEW mv_cfs;
DROP TABLE mvs;