-- ---------------------------------------------------------------------- -- pageinspect on CFS GiST pages, adapted from contrib/pageinspect/sql/gist.sql. -- -- The core test uses an UNLOGGED table for predictable LSNs, but CFS does -- not support UNLOGGED, so this uses a regular CFS table. get_raw_page() on -- a CFS GiST index returns decompressed pages; pageinspect must parse them -- and the leaf item offsets/lengths must match a plain GiST on the same data. -- ---------------------------------------------------------------------- CREATE EXTENSION pageinspect; CREATE EXTENSION pg_buffercache; CREATE FUNCTION cfs_evict(p_rel regclass) RETURNS void LANGUAGE plpgsql AS $$ BEGIN PERFORM pg_buffercache_evict_relation(p_rel); END $$; -- CFS heap + GiST, plain mirror, identical data. CREATE TABLE pigist_cfs (p point, t text) WITH (algorithm = 'lz4'); CREATE TABLE pigist_plain (p point, t text); INSERT INTO pigist_cfs SELECT point(i, i), i::text FROM generate_series(1, 1000) i; INSERT INTO pigist_plain SELECT point(i, i), i::text FROM generate_series(1, 1000) i; CREATE INDEX pigist_cfs_idx ON pigist_cfs USING gist (p); CREATE INDEX pigist_plain_idx ON pigist_plain USING gist (p); SELECT cfs_relation_policy('pigist_cfs_idx'::regclass) AS policy, cfs_relation_has_sidecars('pigist_cfs_idx'::regclass) AS has_sidecars; -- Evict the CFS GiST so get_raw_page reads through decompression. CHECKPOINT; SELECT cfs_evict('pigist_cfs_idx'::regclass); -- Page 0 (root) and page 1 (leaf) are valid 8KB pages. SELECT octet_length(get_raw_page('pigist_cfs_idx', 0)) AS root_len, octet_length(get_raw_page('pigist_cfs_idx', 1)) AS leaf_len; -- Leaf item offsets/lengths/ctids must match the plain mirror: the -- decompressed CFS pages carry the exact same index tuples. SELECT count(*) AS differing_items FROM ( (SELECT itemoffset, ctid, itemlen FROM gist_page_items_bytea(get_raw_page('pigist_cfs_idx', 1)) EXCEPT SELECT itemoffset, ctid, itemlen FROM gist_page_items_bytea(get_raw_page('pigist_plain_idx', 1))) UNION ALL (SELECT itemoffset, ctid, itemlen FROM gist_page_items_bytea(get_raw_page('pigist_plain_idx', 1)) EXCEPT SELECT itemoffset, ctid, itemlen FROM gist_page_items_bytea(get_raw_page('pigist_cfs_idx', 1))) ) d; DROP TABLE pigist_cfs, pigist_plain; DROP EXTENSION pg_buffercache; DROP EXTENSION pageinspect;