-- ---------------------------------------------------------------------- -- amcheck gin_index_check on a CFS-compressed GIN index. -- -- gin_index_check walks the GIN entry tree and posting trees through the -- buffer manager, so on a CFS GIN (inherited from a CFS heap) it reads -- decompressed pages. A clean run (no corruption) validates that every -- decompressed CFS GIN page is structurally correct. -- -- Based on contrib/amcheck/sql/check_gin.sql, reduced to the bulk-load and -- insert paths. -- ---------------------------------------------------------------------- CREATE EXTENSION amcheck; 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 $$; SELECT setseed(1); -- CFS heap with posting trees (frequent entries) and posting leaves (sparse). CREATE TABLE cfsgin_chk ("col" int[]) WITH (algorithm = 'lz4'); INSERT INTO cfsgin_chk SELECT array_agg(round(random() * 255)) FROM generate_series(1, 100000) i GROUP BY i % 10000; INSERT INTO cfsgin_chk SELECT array_agg(255 + round(random() * 100)) FROM generate_series(1, 100) i GROUP BY i % 100; CREATE INDEX cfsgin_chk_idx ON cfsgin_chk USING gin ("col"); SELECT cfs_relation_policy('cfsgin_chk_idx'::regclass) AS policy, cfs_relation_has_sidecars('cfsgin_chk_idx'::regclass) AS has_sidecars; -- Evict the CFS GIN pages so gin_index_check reads them through decompression. CHECKPOINT; SELECT cfs_evict('cfsgin_chk_idx'::regclass); -- gin_index_check must report no corruption (empty = clean). SELECT gin_index_check('cfsgin_chk_idx') AS cfs_gin_check; -- Repeat with the insert path (fastupdate off) rather than bulk load. DROP TABLE cfsgin_chk; SELECT setseed(1); CREATE TABLE cfsgin_chk ("col" int[]) WITH (algorithm = 'lz4'); CREATE INDEX cfsgin_chk_idx ON cfsgin_chk USING gin ("col"); ALTER INDEX cfsgin_chk_idx SET (fastupdate = false); INSERT INTO cfsgin_chk SELECT array_agg(round(random() * 255)) FROM generate_series(1, 100000) i GROUP BY i % 10000; CHECKPOINT; SELECT cfs_evict('cfsgin_chk_idx'::regclass); SELECT gin_index_check('cfsgin_chk_idx') AS cfs_gin_insert_check; DROP TABLE cfsgin_chk; DROP EXTENSION pg_buffercache; DROP EXTENSION amcheck;