-- ---------------------------------------------------------------------- -- pageinspect on CFS hash pages, adapted from contrib/pageinspect/sql/hash.sql. -- -- get_raw_page() on a CFS hash index returns decompressed pages; pageinspect -- must parse them identically to a plain hash on the same data. This is the -- byte-correctness oracle for decompressed CFS hash pages. -- ---------------------------------------------------------------------- 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 + hash, plain mirror, identical data (enough for a couple of -- bucket/overflow pages). CREATE TABLE pihash_cfs (a int, b text) WITH (algorithm = 'lz4'); CREATE TABLE pihash_plain (a int, b text); INSERT INTO pihash_cfs SELECT g % 100, g::text FROM generate_series(1, 5000) g; INSERT INTO pihash_plain SELECT g % 100, g::text FROM generate_series(1, 5000) g; CREATE INDEX pihash_cfs_idx ON pihash_cfs USING hash (a); CREATE INDEX pihash_plain_idx ON pihash_plain USING hash (a); SELECT cfs_relation_policy('pihash_cfs_idx'::regclass) AS policy, cfs_relation_has_sidecars('pihash_cfs_idx'::regclass) AS has_sidecars; -- Evict the CFS hash index so get_raw_page reads through decompression. CHECKPOINT; SELECT cfs_evict('pihash_cfs_idx'::regclass); -- The metapage (page 0) is a valid 8KB page and parses. SELECT octet_length(get_raw_page('pihash_cfs_idx', 0)) AS page0_len; SELECT hash_page_type(get_raw_page('pihash_cfs_idx', 0)) AS page0_type; SELECT hash_page_type(get_raw_page('pihash_cfs_idx', 1)) AS page1_type; -- Metapage key fields must match the plain mirror. SELECT (magic, version, bsize, bmsize, maxbucket) FROM hash_metapage_info( get_raw_page('pihash_cfs_idx', 0)); -- Bucket page (page 1) item counts must match the plain mirror. SELECT (SELECT live_items FROM hash_page_stats(get_raw_page('pihash_cfs_idx', 1))) = (SELECT live_items FROM hash_page_stats(get_raw_page('pihash_plain_idx', 1))) AS bucket1_live_items_match; DROP TABLE pihash_cfs, pihash_plain; DROP EXTENSION pg_buffercache; DROP EXTENSION pageinspect;