-- ----------------------------------------------------------------------
|
-- 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;
|