Исходный код СУБД 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
--
-- src/test/performance/cfs/datashape_toast.sql
--
-- Phase 13 / A13.2 -- data-shape benchmark: TOAST-heavy (> 1 MB) values.
--
-- Each row holds a single 1 MB text value.  Heap pages themselves stay small
-- (pointers), so the real compression happens in the TOAST relation, which
-- inherits the main table's CFS policy (A5.4).  This script therefore reports
-- sizes split across main fork and TOAST.
--
--   psql -v rows=200 -f datashape_toast.sql
 
DROP TABLE IF EXISTS ds_toast_plain;
DROP TABLE IF EXISTS ds_toast_cfs;
 
CREATE TABLE ds_toast_plain (id int primary key, payload text);
SELECT format('CREATE TABLE ds_toast_cfs (id int primary key, payload text) WITH (algorithm=%L)', :'algo')\gexec
 
INSERT INTO ds_toast_plain SELECT g, repeat('toast-' || (g % 10), 150000) FROM generate_series(1, :rows) g;
INSERT INTO ds_toast_cfs   SELECT * FROM ds_toast_plain;
CHECKPOINT;
 
SELECT 'ds_toast' AS shape,
       pg_size_pretty(pg_relation_size('ds_toast_plain')) AS plain_main,
       pg_size_pretty(pg_total_relation_size('ds_toast_plain') -
                      pg_relation_size('ds_toast_plain')) AS plain_toast,
       pg_size_pretty(pg_total_relation_size('ds_toast_cfs') -
                      pg_relation_size('ds_toast_cfs')) AS cfs_toast,
       round((pg_total_relation_size('ds_toast_plain') -
              pg_relation_size('ds_toast_plain'))::numeric /
             NULLIF(pg_total_relation_size('ds_toast_cfs') -
                    pg_relation_size('ds_toast_cfs'), 0), 2) AS toast_ratio;