Исходный код СУБД 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
-- ----------------------------------------------------------------------
-- amcheck gin_index_check on a CFS-compressed GIN index.
--
-- gin_index_check walks the GIN entry tree and posting trees through the
-- buffer manager, so on a CFS GIN (inherited from a CFS heap) it reads
-- decompressed pages.  A clean run (no corruption) validates that every
-- decompressed CFS GIN page is structurally correct.
--
-- Based on contrib/amcheck/sql/check_gin.sql, reduced to the bulk-load and
-- insert paths.
-- ----------------------------------------------------------------------
CREATE EXTENSION amcheck;
CREATE EXTENSION pg_buffercache;
CREATE FUNCTION cfs_evict(p_rel regclass) RETURNS void
  LANGUAGE plpgsql AS $$ BEGIN
  PERFORM pg_buffercache_evict_relation(p_rel);
END $$;
ERROR:  function "cfs_evict" already exists with same argument types
SELECT setseed(1);
 setseed 
---------
 
(1 row)
 
-- CFS heap with posting trees (frequent entries) and posting leaves (sparse).
CREATE TABLE cfsgin_chk ("col" int[]) WITH (algorithm = 'lz4');
INSERT INTO cfsgin_chk
  SELECT array_agg(round(random() * 255))
    FROM generate_series(1, 100000) i GROUP BY i % 10000;
INSERT INTO cfsgin_chk
  SELECT array_agg(255 + round(random() * 100))
    FROM generate_series(1, 100) i GROUP BY i % 100;
CREATE INDEX cfsgin_chk_idx ON cfsgin_chk USING gin ("col");
SELECT cfs_relation_policy('cfsgin_chk_idx'::regclass) AS policy,
       cfs_relation_has_sidecars('cfsgin_chk_idx'::regclass) AS has_sidecars;
    policy     | has_sidecars 
---------------+--------------
 (t,lz4,1,512) | t
(1 row)
 
-- Evict the CFS GIN pages so gin_index_check reads them through decompression.
CHECKPOINT;
SELECT cfs_evict('cfsgin_chk_idx'::regclass);
 cfs_evict 
-----------
 
(1 row)
 
-- gin_index_check must report no corruption (empty = clean).
SELECT gin_index_check('cfsgin_chk_idx') AS cfs_gin_check;
 cfs_gin_check 
---------------
 
(1 row)
 
-- Repeat with the insert path (fastupdate off) rather than bulk load.
DROP TABLE cfsgin_chk;
SELECT setseed(1);
 setseed 
---------
 
(1 row)
 
CREATE TABLE cfsgin_chk ("col" int[]) WITH (algorithm = 'lz4');
CREATE INDEX cfsgin_chk_idx ON cfsgin_chk USING gin ("col");
ALTER INDEX cfsgin_chk_idx SET (fastupdate = false);
INSERT INTO cfsgin_chk
  SELECT array_agg(round(random() * 255))
    FROM generate_series(1, 100000) i GROUP BY i % 10000;
CHECKPOINT;
SELECT cfs_evict('cfsgin_chk_idx'::regclass);
 cfs_evict 
-----------
 
(1 row)
 
SELECT gin_index_check('cfsgin_chk_idx') AS cfs_gin_insert_check;
 cfs_gin_insert_check 
----------------------
 
(1 row)
 
DROP TABLE cfsgin_chk;
DROP EXTENSION pg_buffercache;
DROP EXTENSION amcheck;