Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 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
-- ----------------------------------------------------------------------
-- The checkpoint's cost must track the journal, not the table: folding a
-- couple of journal records into .cfsmap must not assemble the
-- relation's complete in-memory page map (a throwaway full-map handle).
-- ----------------------------------------------------------------------
-- The full-map-opens counter is per-relation (the measured relation's
-- metadata slot), so the measurement is immune to unrelated backends
-- (autovacuum, the CFS background worker) opening full maps of other
-- relations in the same window.
CREATE TABLE cp_lazy (id int, payload text) WITH (algorithm = 'lz4');
INSERT INTO cp_lazy SELECT g, repeat('cp ', 100) FROM generate_series(1, 5000) g;
CHECKPOINT;
-- One page changed since the checkpoint above: the journal holds its
-- UPDATE record (ctid pins the update to a single heap page; a key-based
-- WHERE would seqscan and hint-bit-dirty every page).  Prove the
-- measured checkpoint really folded that record ...
SELECT checkpoint_map_rows_written AS rows_before
FROM pg_stat_get_cfs() WHERE relid = 'cp_lazy'::regclass \gset
UPDATE cp_lazy SET payload = repeat('changed ', 40) WHERE ctid = '(0,1)';
-- ... without opening a full map handle anywhere on the checkpoint path.
SELECT cfs_test_checkpoint_full_opens('cp_lazy') AS checkpoint_full_map_opens;
 checkpoint_full_map_opens 
---------------------------
                         0
(1 row)
 
SELECT checkpoint_map_rows_written AS rows_after
FROM pg_stat_get_cfs() WHERE relid = 'cp_lazy'::regclass \gset
SELECT :rows_after > :rows_before AS checkpoint_folded_real_rows;
 checkpoint_folded_real_rows 
-----------------------------
 t
(1 row)
 
DROP TABLE cp_lazy;