-- ----------------------------------------------------------------------
|
-- Storage Manager integration
|
--
|
-- Exercises the full read/write/truncate path through the smgr layer: a
|
-- relation created with the "algorithm" reloption is served transparently by
|
-- the CFS storage engine, while a plain relation keeps using md. The two
|
-- must produce identical logical results for identical input.
|
-- ----------------------------------------------------------------------
|
-- A CFS table (LZ4) and a plain table loaded with the same data.
|
CREATE TABLE smgr_lz4 (id int, payload text) WITH (algorithm = 'lz4');
|
CREATE TABLE smgr_plain (id int, payload text);
|
INSERT INTO smgr_lz4
|
SELECT g, repeat('cfs ', 40) FROM generate_series(1, 100) g;
|
INSERT INTO smgr_plain
|
SELECT g, repeat('cfs ', 40) FROM generate_series(1, 100) g;
|
-- The compressed and uncompressed relations must hold identical data.
|
SELECT (SELECT md5(string_agg(payload, '' ORDER BY id)) FROM smgr_lz4)
|
=
|
(SELECT md5(string_agg(payload, '' ORDER BY id)) FROM smgr_plain)
|
AS lz4_matches_plain;
|
lz4_matches_plain
|
-------------------
|
t
|
(1 row)
|
|
-- UPDATE / DELETE go through the CFS write path (append + journal).
|
UPDATE smgr_lz4 SET payload = repeat('updated ', 60) WHERE id <= 10;
|
DELETE FROM smgr_lz4 WHERE id > 90;
|
UPDATE smgr_plain SET payload = repeat('updated ', 60) WHERE id <= 10;
|
DELETE FROM smgr_plain WHERE id > 90;
|
SELECT count(*) AS lz4_rows,
|
(SELECT md5(string_agg(payload, '' ORDER BY id)) FROM smgr_lz4)
|
= (SELECT md5(string_agg(payload, '' ORDER BY id)) FROM smgr_plain)
|
AS lz4_still_matches_plain
|
FROM smgr_lz4;
|
lz4_rows | lz4_still_matches_plain
|
----------+-------------------------
|
90 | t
|
(1 row)
|
|
-- TRUNCATE goes through the CFS truncate bridge.
|
TRUNCATE smgr_lz4;
|
SELECT count(*) AS lz4_after_truncate FROM smgr_lz4;
|
lz4_after_truncate
|
--------------------
|
0
|
(1 row)
|
|
-- A CFS index inherits the table policy.
|
CREATE INDEX smgr_lz4_id_idx ON smgr_lz4 (id);
|
INSERT INTO smgr_lz4 SELECT g, repeat('idx ', 40) FROM generate_series(1, 5) g;
|
SELECT * FROM smgr_lz4 ORDER BY id;
|
id | payload
|
----+------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
1 | idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx
|
2 | idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx
|
3 | idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx
|
4 | idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx
|
5 | idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx idx
|
(5 rows)
|
|
-- A lazy smgr handle only knows the .cfsmap snapshot. Opening it (here via
|
-- a direct smgr read after dropping the metadata slot) must not publish that
|
-- snapshot-only size: the journal already contains a later extension.
|
CREATE TABLE smgr_lazy_meta (id int) WITH (algorithm = 'lz4');
|
INSERT INTO smgr_lazy_meta SELECT g FROM generate_series(1, 1000) g;
|
CHECKPOINT;
|
INSERT INTO smgr_lazy_meta SELECT g FROM generate_series(1001, 5000) g;
|
SELECT cfs_test_smgr_read_meta('smgr_lazy_meta') IS NULL AS lazy_did_not_publish;
|
lazy_did_not_publish
|
----------------------
|
t
|
(1 row)
|
|
DROP TABLE smgr_lazy_meta;
|
-- Sidecar files exist for the CFS relation but not for the plain one.
|
SELECT cfs_relation_has_sidecars('smgr_lz4') AS lz4_has_sidecars,
|
cfs_relation_has_sidecars('smgr_plain') AS plain_has_sidecars;
|
lz4_has_sidecars | plain_has_sidecars
|
------------------+--------------------
|
t | f
|
(1 row)
|
|
-- DROP removes the sidecar files (the relation is dropped cleanly).
|
DROP TABLE smgr_lz4;
|
DROP TABLE smgr_plain;
|