--
|
-- src/test/performance/cfs/datashape_jsonb.sql
|
--
|
-- Phase 13 / A13.2 -- data-shape benchmark: large JSONB documents.
|
--
|
-- Loads N wide, repetitive JSONB documents into a plain and a CFS table and
|
-- reports the compression ratio. JSONB compresses well because key names and
|
-- many values repeat across rows. Parameter :rows controls the volume.
|
--
|
-- psql -v rows=2000 -f datashape_jsonb.sql
|
|
\set algo :algo
|
DROP TABLE IF EXISTS ds_jsonb_plain;
|
DROP TABLE IF EXISTS ds_jsonb_cfs;
|
|
CREATE TABLE ds_jsonb_plain (id int primary key, doc jsonb);
|
SELECT format('CREATE TABLE ds_jsonb_cfs (id int primary key, doc jsonb) WITH (algorithm=%L)', :'algo')\gexec
|
|
INSERT INTO ds_jsonb_plain
|
SELECT g, jsonb_build_object(
|
'group', g % 50,
|
'name', 'item-' || (g % 50),
|
'tags', (SELECT jsonb_agg(repeat('x', 8) || k) FROM generate_series(1,20) k),
|
'payload', repeat(md5(g::text), 40),
|
'nested', jsonb_build_object('a', g, 'b', repeat('y', 200))
|
) FROM generate_series(1, :rows) g;
|
|
INSERT INTO ds_jsonb_cfs SELECT * FROM ds_jsonb_plain;
|
CHECKPOINT;
|
|
SELECT 'ds_jsonb' AS shape,
|
pg_size_pretty(pg_total_relation_size('ds_jsonb_plain')) AS plain_size,
|
pg_size_pretty(pg_total_relation_size('ds_jsonb_cfs')) AS cfs_size,
|
round(pg_total_relation_size('ds_jsonb_plain')::numeric /
|
NULLIF(pg_total_relation_size('ds_jsonb_cfs'), 0), 2) AS ratio;
|