--
|
-- src/test/performance/cfs/datashape_churn.sql
|
--
|
-- Phase 13 / A13.2 -- data-shape benchmark: update-heavy single-page churn.
|
--
|
-- Repeatedly rewrites the same small set of rows so a handful of heap pages
|
-- accumulate many dead records in the .cfp. Demonstrates dead_bytes/dead_pages
|
-- growth (the signal the background compactor consumes) and the effect of a
|
-- manual pg_cfs_compact().
|
--
|
-- psql -v rows=200 -v iterations=200 -f datashape_churn.sql
|
|
DROP TABLE IF EXISTS ds_churn_cfs;
|
CREATE TABLE ds_churn_cfs (id int primary key, payload text) WITH (algorithm = :'algo');
|
|
-- A small table that fits in very few pages.
|
INSERT INTO ds_churn_cfs SELECT g, repeat('v', 100) FROM generate_series(1, :rows) g;
|
CHECKPOINT;
|
|
-- Hammer the same rows. Each generated UPDATE runs as its own statement
|
-- (autocommit), so every iteration leaves a separate dead CFS record in the
|
-- .cfp -- exactly the churn the background compactor reclaims. \gexec is used
|
-- because psql does not substitute :variables inside a dollar-quoted body.
|
SELECT format(
|
'UPDATE ds_churn_cfs SET payload = repeat(''u'', 100) || %s WHERE id = (%s %% %s) + 1',
|
g, g, :rows)
|
FROM generate_series(1, :iterations) AS g
|
\gexec
|
CHECKPOINT;
|
|
-- Snapshot before compaction.
|
SELECT 'before' AS phase,
|
dead_pages,
|
pg_size_pretty(dead_bytes) AS dead_bytes,
|
pg_size_pretty(physical_size) AS physical_size
|
FROM pg_stat_cfs WHERE relname = 'ds_churn_cfs';
|
|
SELECT pg_cfs_compact('ds_churn_cfs');
|
|
SELECT 'after' AS phase,
|
dead_pages,
|
pg_size_pretty(dead_bytes) AS dead_bytes,
|
pg_size_pretty(physical_size) AS physical_size
|
FROM pg_stat_cfs WHERE relname = 'ds_churn_cfs';
|