-- ---------------------------------------------------------------------- -- CFS reloptions validation and SET/RESET semantics, adapted from -- src/test/regress/sql/reloptions.sql. -- -- The core test validates option parsing against the toast.* namespace; -- here the same cases are mirrored against the CFS options "algorithm" -- (enum lz4/zstd), "level" (int, 1..22) and "min_gain_bytes" (int, -- 0..BLCKSZ) as declared in src/backend/access/common/reloptions.c. -- -- The fork-specific rules under test (develop/iface_sql.md): -- section 4: unspecified level / min_gain_bytes are frozen from GUC -- into reloptions at DDL time; -- section 7: RESET (level) / RESET (min_gain_bytes) do not remove the -- option but freeze the current GUC value into reloptions; -- section 9: a TOAST relation stores a verbatim copy of the table's -- CFS reloptions, updated on every policy change. -- -- This test is metadata-only (reloptions and policy inspection), so no -- buffer eviction is needed. -- ---------------------------------------------------------------------- -- Value range checks: level must be within 1..22, min_gain_bytes within -- 0..BLCKSZ (8192). CREATE TABLE ro_bad (i int) WITH (algorithm = 'lz4', level = 0); CREATE TABLE ro_bad (i int) WITH (algorithm = 'lz4', level = 23); CREATE TABLE ro_bad (i int) WITH (algorithm = 'lz4', min_gain_bytes = -1); CREATE TABLE ro_bad (i int) WITH (algorithm = 'lz4', min_gain_bytes = 8193); -- Improper value types and unknown enum values. CREATE TABLE ro_bad (i int) WITH (algorithm = 'lz4', level = 'string'); CREATE TABLE ro_bad (i int) WITH (algorithm = 'lz4', level = true); CREATE TABLE ro_bad (i int) WITH (algorithm = 'gzip'); -- An option may not be specified twice. CREATE TABLE ro_bad (i int) WITH (algorithm = 'lz4', algorithm = 'zstd'); -- Specifying the name only works only for Boolean options. CREATE TABLE ro_bad (i int) WITH (algorithm); -- Boundary values are accepted. CREATE TABLE ro_bounds_zstd (i int) WITH (algorithm = 'zstd', level = 22, min_gain_bytes = 8192); SELECT * FROM cfs_relation_policy('ro_bounds_zstd'); CREATE TABLE ro_bounds_lz4 (i int) WITH (algorithm = 'lz4', level = 1, min_gain_bytes = 0); SELECT * FROM cfs_relation_policy('ro_bounds_lz4'); -- Option names are case-insensitive (mirrors the FiLLFaCToR case). CREATE TABLE ro_case (i int) WITH (AlGorithm = 'lz4', LeVeL = 4); SELECT * FROM cfs_relation_policy('ro_case'); -- Simple ALTER TABLE: SET replaces only the named options. CREATE TABLE ro_alter (i int) WITH (algorithm = 'lz4'); ALTER TABLE ro_alter SET (level = 5, min_gain_bytes = 128); SELECT option_name, option_value FROM pg_options_to_table((SELECT reloptions FROM pg_class WHERE oid = 'ro_alter'::regclass)) ORDER BY option_name; -- RESET of a parameter removes the option from the catalog and returns -- the field to runtime resolve; no GUC value is frozen in its place. ALTER TABLE ro_alter RESET (level); SELECT * FROM cfs_relation_policy('ro_alter'); SELECT option_name, option_value FROM pg_options_to_table((SELECT reloptions FROM pg_class WHERE oid = 'ro_alter'::regclass)) ORDER BY option_name; -- RESET fails if a value is specified. ALTER TABLE ro_alter RESET (level = 12); -- TOAST follows the owning table at runtime: the toast relation stores no -- CFS options of its own; only its genuine toast.* options are stored. CREATE TABLE ro_toast (s text) WITH (algorithm = 'zstd', level = 6, toast.autovacuum_enabled = false); SELECT option_name, option_value FROM pg_options_to_table((SELECT reloptions FROM pg_class WHERE oid = (SELECT reltoastrelid FROM pg_class WHERE oid = 'ro_toast'::regclass))) ORDER BY option_name; -- No rewrite for a parameter change; the toast's stored options do not -- change either (the policy follows the table at runtime). ALTER TABLE ro_toast SET (level = 8); SELECT option_name, option_value FROM pg_options_to_table((SELECT reloptions FROM pg_class WHERE oid = (SELECT reltoastrelid FROM pg_class WHERE oid = 'ro_toast'::regclass))) ORDER BY option_name; -- RESET (algorithm) rewrites the table back to plain storage; the toast's -- stored options do not change, its effective policy stops being CFS. ALTER TABLE ro_toast RESET (algorithm); SELECT option_name, option_value FROM pg_options_to_table((SELECT reloptions FROM pg_class WHERE oid = (SELECT reltoastrelid FROM pg_class WHERE oid = 'ro_toast'::regclass))) ORDER BY option_name; -- CREATE INDEX / ALTER INDEX with own CFS policy on a plain table -- (mirrors the btree reloptions section of the core test). CREATE TABLE ro_idx_t (i int); CREATE INDEX ro_idx ON ro_idx_t (i) WITH (algorithm = 'zstd', level = 5); SELECT * FROM cfs_relation_policy('ro_idx'); -- Changing a parameter touches only reloptions. ALTER INDEX ro_idx SET (level = 7); SELECT * FROM cfs_relation_policy('ro_idx'); -- Resetting the algorithm rebuilds the index back to plain storage. ALTER INDEX ro_idx RESET (algorithm); SELECT * FROM cfs_relation_policy('ro_idx'); -- ---------------------------------------------------------------------- -- Toast mirror acceptance: vanilla pg_dump dumps a TOAST relation's -- CFS reloptions back into the table's WITH clause as toast.* options, so -- the server must accept a toast.* triple that verbatim mirrors the table's -- own options, and still reject any independent (differing or orphaned) -- toast policy. -- ---------------------------------------------------------------------- -- toast.* CFS options are rejected unconditionally: a TOAST relation has -- no independent CFS policy; it follows the owning table's policy at -- runtime and stores no CFS options of its own. CREATE TABLE ro_mirror (s text) WITH (algorithm = 'zstd', level = 3, min_gain_bytes = 512); -- Even a verbatim mirror of the table's triple is rejected now. CREATE TABLE ro_bad (s text) WITH (algorithm = 'zstd', level = 3, min_gain_bytes = 512, toast.algorithm = 'zstd', toast.level = '3', toast.min_gain_bytes = '512'); -- A toast.* CFS option on a table with no CFS policy at all is rejected -- as well. CREATE TABLE ro_bad (s text) WITH (toast.algorithm = 'zstd', toast.level = '3', toast.min_gain_bytes = '512'); -- ALTER: any toast.* CFS option is rejected, even one that would mirror -- the table's current policy. ALTER TABLE ro_mirror SET (toast.level = '3'); -- ALTER: RESET of a toast.* CFS option is rejected too. ALTER TABLE ro_mirror RESET (toast.algorithm); -- The toast relation of a CFS table carries no CFS options at all: its -- policy is resolved from the owning table at runtime. SELECT reloptions FROM pg_class WHERE oid = (SELECT reltoastrelid FROM pg_class WHERE oid = 'ro_mirror'::regclass); DROP TABLE ro_bounds_zstd, ro_bounds_lz4, ro_case, ro_alter, ro_toast, ro_idx_t, ro_mirror;