-- ----------------------------------------------------------------------
|
-- QDB-1516 T7: pg_stat_cfs equivalence on a fixed scenario. The atomic
|
-- counters must publish the same arithmetic the lock-protected counters
|
-- always did: every accounted write is exactly one compress operation and
|
-- lands in exactly one of the two page counters, every served read is a
|
-- decompression, and pg_cfs_reset_stats() zeroes the counters of exactly
|
-- the named relation while stamping last_reset.
|
-- ----------------------------------------------------------------------
|
SET client_min_messages = warning;
|
CREATE EXTENSION IF NOT EXISTS test_cfs;
|
CREATE EXTENSION IF NOT EXISTS pg_buffercache;
|
RESET client_min_messages;
|
|
CREATE TABLE t7_lz4 (id int, payload text) WITH (algorithm = 'lz4');
|
INSERT INTO t7_lz4 SELECT g, repeat('t7 ', 64) FROM generate_series(1, 4000) g;
|
UPDATE t7_lz4 SET payload = payload || 'u' WHERE id % 40 = 0;
|
CHECKPOINT;
|
|
-- Force the scan through the CFS read path: evict the relation's buffers
|
-- so the seqscan below is served by smgr reads.
|
SELECT buffers_evicted > 0 AS t7_evicted
|
FROM pg_buffercache_evict_relation('t7_lz4');
|
SELECT count(*) AS t7_rows FROM t7_lz4;
|
|
SELECT write_count > 0 AS writes_accounted,
|
write_count = compress_count AS writes_are_compressions,
|
compressed_pages + uncompressed_pages = write_count
|
AS page_split_exact,
|
read_count > 0 AS reads_accounted,
|
read_count = decompress_count AS reads_are_decompressions,
|
crc_failures = 0 AS no_crc_failures
|
FROM pg_stat_cfs WHERE relid = 't7_lz4'::regclass;
|
|
-- Byte-level sanity: the published logical size agrees with the logical
|
-- size the size function measures, and the compressible payload keeps
|
-- the physical sidecars smaller than the logical bytes.
|
SELECT logical_size = (pg_cfs_relation_size('t7_lz4')).logical_size
|
AS logical_size_exact,
|
physical_size > 0 AS physical_bytes_present,
|
compression_ratio > 1 AS payload_compresses
|
FROM pg_stat_cfs WHERE relid = 't7_lz4'::regclass;
|
|
-- Reset contract: every counter back to zero, the reset time stamped.
|
DO $$ BEGIN PERFORM pg_cfs_reset_stats('t7_lz4'); END $$;
|
SELECT write_count = 0 AND compress_count = 0
|
AND read_count = 0 AND decompress_count = 0
|
AND compressed_pages = 0 AND uncompressed_pages = 0
|
AND crc_failures = 0
|
AS all_counters_zero,
|
last_reset IS NOT NULL AS reset_stamped
|
FROM pg_stat_cfs WHERE relid = 't7_lz4'::regclass;
|
|
DROP TABLE t7_lz4;
|