/*------------------------------------------------------------------------- * 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 */