Исходный код СУБД 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
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
/*-------------------------------------------------------------------------
 * cfs_policy.h
 *    Compressed File Store (CFS) — per-relation compression policy shared
 *    by every reloptions struct.
 *
 * CfsRelPolicyOptions is embedded (as member "cfs") in StdRdOptions and in
 * every index AM's options struct, so the five policy fields are declared
 * exactly once.  CFS_POLICY_PARSE_ELTS(s) generates the matching
 * relopt_parse_elt entries for an options parse table; it expands to
 * nothing when CFS is compiled out, and must be the last entry of the
 * table (it does not emit a trailing comma).
 *
 * This header must be included after postgres.h.  It is intentionally
 * self-contained (no PostgreSQL includes) so it can be embedded in
 * access-method headers without adding include edges.
 *
 * Copyright (c) 2026, Kirillov Vyacheslav, QDB Development Group
 *
 * IDENTIFICATION
 *    src/include/storage/cfs/cfs_policy.h
 *
 *-------------------------------------------------------------------------
 */
#ifndef CFS_POLICY_H
#define CFS_POLICY_H
 
#ifdef USE_CFS
 
/*
 * CFS compression policy of one relation (heap, TOAST or index).
 *
 * - algorithm: the CfsAlgorithm value; CFS_ALGORITHM_RAW (0) means CFS is
 *   not enabled.  Unlike level/min_gain_bytes, no separate _set flag is
 *   needed because 0 (RAW) is an unambiguous "not set" sentinel.
 * - level / min_gain_bytes: user-specified values.
 * - level_set / min_gain_bytes_set: whether the user specified these
 *   options explicitly.  They are required because 0 is a valid value for
 *   both, so a sentinel cannot detect "not set".  When false, the
 *   effective value falls back to the per-algorithm cfs_default_lz4_level
 *   / cfs_default_zstd_level and cfs_default_min_gain_bytes GUCs of the
 *   writing session at runtime.  This mirrors the isset_offset mechanism
 *   used by vacuum_truncate_set.
 */
typedef struct CfsRelPolicyOptions
{
    int         algorithm;      /* CfsAlgorithm; 0 = no own policy */
    int         level;          /* compression level */
    int         min_gain_bytes; /* min gain before storing compressed */
    bool        level_set;      /* was "level" explicitly specified? */
    bool        min_gain_bytes_set; /* was "min_gain_bytes" set? */
} CfsRelPolicyOptions;
 
/*
 * relopt_parse_elt entries for the CFS policy options of struct 's'.
 * Requires access/reloptions.h at the expansion site (RELOPT_TYPE_* and
 * relopt_parse_elt).  Offsets are computed as member base + field, the
 * pattern StdRdOptions already uses for its autovacuum_* fields.
 */
#define CFS_POLICY_PARSE_ELTS(s) \
    {"algorithm", RELOPT_TYPE_ENUM, \
    offsetof(s, cfs) + offsetof(CfsRelPolicyOptions, algorithm)}, \
    {"level", RELOPT_TYPE_INT, \
    offsetof(s, cfs) + offsetof(CfsRelPolicyOptions, level), \
    offsetof(s, cfs) + offsetof(CfsRelPolicyOptions, level_set)}, \
    {"min_gain_bytes", RELOPT_TYPE_INT, \
    offsetof(s, cfs) + offsetof(CfsRelPolicyOptions, min_gain_bytes), \
    offsetof(s, cfs) + offsetof(CfsRelPolicyOptions, min_gain_bytes_set)}
#else
#define CFS_POLICY_PARSE_ELTS(s)
#endif
 
#endif                          /* CFS_POLICY_H */