Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
--
-- 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;