--
|
-- src/test/performance/cfs/datashape_bytea.sql
|
--
|
-- Phase 13 / A13.2 -- data-shape benchmark: random (incompressible) bytea.
|
--
|
-- Cryptographically random payloads defeat compression; pages where
|
-- compressed_size + overhead would not beat min_gain_bytes are stored
|
-- uncompressed inside the CFS container. This script verifies that the CFS
|
-- table is NOT larger than the plain table by more than the per-page overhead,
|
-- i.e. that the "store uncompressed when no gain" path works.
|
--
|
-- psql -v rows=2000 -f datashape_bytea.sql
|
|
DROP TABLE IF EXISTS ds_bytea_plain;
|
DROP TABLE IF EXISTS ds_bytea_cfs;
|
|
CREATE TABLE ds_bytea_plain (id int primary key, payload bytea);
|
SELECT format('CREATE TABLE ds_bytea_cfs (id int primary key, payload bytea) WITH (algorithm=%L)', :'algo')\gexec
|
|
-- 2 KB of high-entropy data per row: 8 KB pages hold ~3 rows, all random.
|
-- md5() yields 32 hex chars per call; 64 calls -> 2048 bytes of random data.
|
INSERT INTO ds_bytea_plain
|
SELECT g, decode(string_agg(md5(g::text || k::text), ''), 'hex')
|
FROM generate_series(1, :rows) g, generate_series(1, 64) AS k
|
GROUP BY g;
|
|
INSERT INTO ds_bytea_cfs SELECT * FROM ds_bytea_plain;
|
CHECKPOINT;
|
|
SELECT 'ds_bytea' AS shape,
|
pg_size_pretty(pg_total_relation_size('ds_bytea_plain')) AS plain_size,
|
pg_size_pretty(pg_total_relation_size('ds_bytea_cfs')) AS cfs_size,
|
-- CFS must be within ~10% of plain for incompressible data.
|
round(pg_total_relation_size('ds_bytea_cfs')::numeric /
|
NULLIF(pg_total_relation_size('ds_bytea_plain'), 0), 2) AS ratio;
|