-- ---------------------------------------------------------------------- -- pageinspect on CFS heap pages, adapted from -- contrib/pageinspect/sql/page.sql. -- -- get_raw_page() reads a page through smgr by relation and block number, -- so on a CFS relation it exercises the decompressing smgrread path — -- making pageinspect the best available oracle that a decompressed CFS -- page is byte-correct: after evicting shared_buffers, the parsed page -- contents of a CFS table must match those of a plain twin table loaded -- with the same rows. -- -- Only structural fields are compared (lp, lp_off, lp_len, lp_flags, -- t_data): page LSNs and checksums legitimately differ between the two -- tables. -- -- Note: CFS relations cannot be TEMP, so unlike the core test this one -- uses a regular table; FSM/VM contents are read but not compared -- byte-for-byte. -- ---------------------------------------------------------------------- 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; $$; CREATE TABLE pi_cfs (a int, b text) WITH (algorithm = 'lz4'); INSERT INTO pi_cfs SELECT g, md5(g::text) FROM generate_series(1, 300) g; CREATE TABLE pi_plain (a int, b text); INSERT INTO pi_plain SELECT g, md5(g::text) FROM generate_series(1, 300) g; VACUUM (DISABLE_PAGE_SKIPPING) pi_cfs; VACUUM (DISABLE_PAGE_SKIPPING) pi_plain; -- A page can be read from every fork, same as for a plain table. CHECKPOINT; SELECT octet_length(get_raw_page('pi_cfs', 'main', 0)) AS main_0; SELECT octet_length(get_raw_page('pi_cfs', 'fsm', 0)) AS fsm_0; SELECT octet_length(get_raw_page('pi_cfs', 'vm', 0)) AS vm_0; -- Reading past the last block fails, same as vanilla. SELECT octet_length(get_raw_page('pi_cfs', 'main', -1)); -- The page header survives decompression (LSN and checksum excluded). SELECT pagesize, version FROM page_header(get_raw_page('pi_cfs', 0)); -- The real check: force both tables out of shared_buffers, then compare -- the parsed items of every main-fork page. For the CFS table these -- pages just came through decompression. SELECT cfs_evict('pi_cfs'); SELECT cfs_evict('pi_plain'); -- The block range of the CFS table comes from its logical size: the -- main fork of a CFS relation is only a small metadata stub, so -- pg_relation_size() cannot be used to find the page count. WITH cfs AS ( SELECT (heap_page_items(get_raw_page('pi_cfs', b))).* FROM generate_series(0, (SELECT logical_size / 8192 - 1 FROM pg_cfs_relation_size('pi_cfs'))) AS b ), plain AS ( SELECT (heap_page_items(get_raw_page('pi_plain', b))).* FROM generate_series(0, pg_relation_size('pi_plain') / 8192 - 1) AS b ) SELECT count(*) AS differing_items FROM ((SELECT lp, lp_off, lp_len, lp_flags, t_data FROM cfs EXCEPT SELECT lp, lp_off, lp_len, lp_flags, t_data FROM plain) UNION ALL (SELECT lp, lp_off, lp_len, lp_flags, t_data FROM plain EXCEPT SELECT lp, lp_off, lp_len, lp_flags, t_data FROM cfs)) AS d; -- tuple_data_split decodes the decompressed tuples back to the inserted -- values (spot-check the first tuple). SELECT tuple_data_split('pi_cfs'::regclass, t_data, t_infomask, t_infomask2, t_bits) FROM heap_page_items(get_raw_page('pi_cfs', 0)) WHERE lp = 1; DROP TABLE pi_cfs, pi_plain; DROP FUNCTION cfs_evict(regclass); DROP EXTENSION pageinspect; DROP EXTENSION pg_buffercache;