-- ----------------------------------------------------------------------
|
-- CFS policy defaults: explicit-only catalog, runtime GUC resolve.
|
--
|
-- Contract (docs/ai/refactory/cfs-guc-runtime-defaults-spec.md): the
|
-- catalog stores ONLY what the user spelled out — "algorithm" (the CFS
|
-- marker) plus optionally "level" / "min_gain_bytes". Nothing is frozen
|
-- from the cfs_default_* GUCs at DDL time: an unset field is resolved by
|
-- the writer from its session's per-algorithm GUC at the moment of the
|
-- write (vanilla default_toast_compression pattern).
|
--
|
-- Covered: CREATE TABLE option subsets, GUC independence of the catalog,
|
-- runtime writes under non-default GUCs, ALTER SET/RESET, indexes,
|
-- partitioned tables, materialized views, TOAST copy, CLUSTER, hand-made
|
-- partial catalog triples (no longer an error) and explicit-range
|
-- validation.
|
--
|
-- Metadata-only: no buffer eviction is needed.
|
-- ----------------------------------------------------------------------
|
|
-- The per-algorithm defaults the runtime resolve falls back to.
|
SHOW cfs_default_lz4_level;
|
SHOW cfs_default_zstd_level;
|
SHOW cfs_default_min_gain_bytes;
|
|
-- ----------------------------------------------------------------------
|
-- 1. CREATE TABLE: the catalog stores exactly what was spelled out.
|
-- ----------------------------------------------------------------------
|
|
-- Algorithm only: nothing else lands in pg_class.reloptions.
|
CREATE TABLE pd_t_algo_only (i int) WITH (algorithm = 'lz4');
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_t_algo_only'::regclass))
|
ORDER BY option_name;
|
|
-- Level given: algorithm + level.
|
CREATE TABLE pd_t_level_only (i int) WITH (algorithm = 'lz4', level = 7);
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_t_level_only'::regclass))
|
ORDER BY option_name;
|
|
-- min_gain_bytes given: algorithm + min_gain_bytes.
|
CREATE TABLE pd_t_mgb_only (i int) WITH (algorithm = 'zstd', min_gain_bytes = 256);
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_t_mgb_only'::regclass))
|
ORDER BY option_name;
|
|
-- Everything given: stored verbatim.
|
CREATE TABLE pd_t_both (i int)
|
WITH (algorithm = 'zstd', level = 2, min_gain_bytes = 64);
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_t_both'::regclass))
|
ORDER BY option_name;
|
|
-- ----------------------------------------------------------------------
|
-- 2. The catalog does not depend on the GUC values in effect at DDL
|
-- time: nothing is frozen from them.
|
-- ----------------------------------------------------------------------
|
|
SET cfs_default_lz4_level = 5;
|
SET cfs_default_min_gain_bytes = 77;
|
|
CREATE TABLE pd_t_guc (i int) WITH (algorithm = 'lz4');
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_t_guc'::regclass))
|
ORDER BY option_name;
|
|
RESET cfs_default_lz4_level;
|
RESET cfs_default_min_gain_bytes;
|
|
-- ----------------------------------------------------------------------
|
-- 3. Runtime resolve: unset fields follow the session GUC at write time.
|
-- Writes under non-default GUC values must succeed and stay readable
|
-- (every .cfp record carries its own algorithm/level marker).
|
-- ----------------------------------------------------------------------
|
|
CREATE TABLE pd_rt (id int, payload text) WITH (algorithm = 'zstd');
|
|
SET cfs_default_zstd_level = 7;
|
INSERT INTO pd_rt SELECT g, 'row ' || g FROM generate_series(1, 20) g;
|
RESET cfs_default_zstd_level;
|
|
SET cfs_default_zstd_level = 11;
|
INSERT INTO pd_rt SELECT g, 'row ' || g FROM generate_series(21, 40) g;
|
RESET cfs_default_zstd_level;
|
|
-- Explicit level wins over the session GUC: the write resolves the
|
-- stored level=7, not cfs_default_lz4_level.
|
SET cfs_default_lz4_level = 12;
|
INSERT INTO pd_t_level_only SELECT g FROM generate_series(1, 10) g;
|
SELECT is_cfs, algorithm, level, min_gain_bytes
|
FROM cfs_relation_policy('pd_t_level_only');
|
RESET cfs_default_lz4_level;
|
|
SELECT count(*) AS pd_rt_rows, count(*) FILTER (WHERE payload = 'row 7') AS row7
|
FROM pd_rt;
|
SELECT count(*) AS level_only_rows FROM pd_t_level_only;
|
|
-- The effective policy of pd_rt for this session: level follows the
|
-- current (default) GUC value, not any value used at insert time.
|
SELECT is_cfs, algorithm, level, min_gain_bytes
|
FROM cfs_relation_policy('pd_rt');
|
SET cfs_default_zstd_level = 9;
|
SELECT is_cfs, algorithm, level, min_gain_bytes
|
FROM cfs_relation_policy('pd_rt');
|
RESET cfs_default_zstd_level;
|
|
-- ----------------------------------------------------------------------
|
-- 3b. Resolve the level at physical write time; compare the same page bytes.
|
-- ----------------------------------------------------------------------
|
\pset format unaligned
|
\pset tuples_only on
|
CREATE EXTENSION pg_buffercache;
|
CREATE EXTENSION pageinspect;
|
CREATE TABLE rt_lvl_probe (id int, payload text) WITH (algorithm = 'lz4');
|
SET cfs_default_min_gain_bytes = 0;
|
SET cfs_default_lz4_level = 1;
|
INSERT INTO rt_lvl_probe
|
SELECT 1, string_agg(repeat(chr(65 + (i * 7) % 26), 61), '')
|
FROM generate_series(1, 85) i;
|
SELECT pg_buffercache_evict_relation('rt_lvl_probe');
|
CREATE TEMP TABLE rt_lvl_first AS
|
SELECT * FROM cfs_test_lz4_record('rt_lvl_probe', 1);
|
SELECT records = 1 AND record_offset = 8, matches_fast, NOT matches_hc,
|
length(page) = 8192 AND page = get_raw_page('rt_lvl_probe', 0)
|
FROM rt_lvl_first;
|
SET cfs_default_lz4_level = 12;
|
SELECT pg_buffercache_mark_dirty_relation('rt_lvl_probe');
|
-- A dirty page alone must not be mistaken for a new physical record.
|
SELECT records = 2 FROM cfs_test_lz4_record('rt_lvl_probe', 1);
|
SELECT records FROM cfs_test_lz4_record('rt_lvl_probe', 2);
|
SELECT pg_buffercache_evict_relation('rt_lvl_probe');
|
CREATE TEMP TABLE rt_lvl_second AS
|
SELECT * FROM cfs_test_lz4_record('rt_lvl_probe', 2);
|
SELECT b.records = 2 AND b.record_offset = a.record_end,
|
b.page = a.page, b.payload <> a.payload,
|
b.matches_hc, NOT b.matches_fast,
|
b.page = get_raw_page('rt_lvl_probe', 0)
|
FROM rt_lvl_first a, rt_lvl_second b;
|
SELECT r.records = 2 AND r.record_offset = a.record_offset
|
AND r.record_end = a.record_end AND r.payload = a.payload
|
AND r.page = a.page, r.matches_fast, NOT r.matches_hc
|
FROM cfs_test_lz4_record('rt_lvl_probe', 1) r, rt_lvl_first a;
|
SELECT count(*) = 1 AND min(id) = 1 AND
|
min(md5(payload)) = (SELECT md5(string_agg(repeat(chr(65 + (i * 7) % 26), 61), ''))
|
FROM generate_series(1, 85) i)
|
FROM rt_lvl_probe;
|
-- Explicit level wins over the backend session level.
|
CREATE TABLE rt_lvl_explicit (LIKE rt_lvl_probe)
|
WITH (algorithm = 'lz4', level = 1, min_gain_bytes = 0);
|
INSERT INTO rt_lvl_explicit
|
SELECT 2, string_agg(repeat(chr(65 + (i * 7) % 26), 61), '')
|
FROM generate_series(1, 85) i;
|
SELECT pg_buffercache_evict_relation('rt_lvl_explicit');
|
SELECT records = 1, matches_fast, NOT matches_hc
|
FROM cfs_test_lz4_record('rt_lvl_explicit', 1);
|
SELECT r.page = a.page FROM cfs_test_lz4_record('rt_lvl_explicit', 1) r,
|
rt_lvl_first a;
|
-- Reject a valid physical record using the wrong algorithm.
|
CREATE TABLE rt_lvl_wrong (LIKE rt_lvl_probe)
|
WITH (algorithm = 'zstd', min_gain_bytes = 0);
|
INSERT INTO rt_lvl_wrong
|
SELECT 1, string_agg(repeat(chr(65 + (i * 7) % 26), 61), '')
|
FROM generate_series(1, 85) i;
|
SELECT pg_buffercache_evict_relation('rt_lvl_wrong');
|
SELECT records FROM cfs_test_lz4_record('rt_lvl_wrong', 1);
|
-- CHECKPOINT uses the physical writer configuration, not session SET.
|
CREATE TABLE rt_lvl_ckpt (LIKE rt_lvl_probe)
|
WITH (algorithm = 'lz4', min_gain_bytes = 0);
|
INSERT INTO rt_lvl_ckpt
|
SELECT 1, string_agg(repeat(chr(65 + (i * 7) % 26), 61), '')
|
FROM generate_series(1, 85) i;
|
CHECKPOINT;
|
SELECT records = 1, matches_fast, NOT matches_hc
|
FROM cfs_test_lz4_record('rt_lvl_ckpt', 1);
|
RESET cfs_default_lz4_level;
|
ALTER SYSTEM SET cfs_default_lz4_level = 12;
|
SELECT pg_reload_conf();
|
SELECT pg_sleep(1);
|
SHOW cfs_default_lz4_level;
|
SET cfs_default_lz4_level = 1;
|
CREATE TABLE rt_lvl_global (LIKE rt_lvl_probe)
|
WITH (algorithm = 'lz4', min_gain_bytes = 0);
|
INSERT INTO rt_lvl_global
|
SELECT 1, string_agg(repeat(chr(65 + (i * 7) % 26), 61), '')
|
FROM generate_series(1, 85) i;
|
CHECKPOINT;
|
SELECT records = 1, matches_hc, NOT matches_fast
|
FROM cfs_test_lz4_record('rt_lvl_global', 1);
|
ALTER SYSTEM RESET cfs_default_lz4_level;
|
SELECT pg_reload_conf();
|
SELECT pg_sleep(1);
|
RESET cfs_default_lz4_level;
|
SHOW cfs_default_lz4_level;
|
RESET cfs_default_min_gain_bytes;
|
DROP TABLE rt_lvl_first, rt_lvl_second, rt_lvl_probe, rt_lvl_explicit,
|
rt_lvl_wrong, rt_lvl_ckpt, rt_lvl_global;
|
DROP EXTENSION pageinspect;
|
DROP EXTENSION pg_buffercache;
|
\pset tuples_only off
|
\pset format aligned
|
-- ----------------------------------------------------------------------
|
-- 4. ALTER paths.
|
-- ----------------------------------------------------------------------
|
|
-- (a) A plain table gains only what was SET.
|
CREATE TABLE pd_alter_plain (i int);
|
|
ALTER TABLE pd_alter_plain SET (algorithm = 'lz4');
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_alter_plain'::regclass))
|
ORDER BY option_name;
|
|
-- (b) SET (level) adds the explicit key next to the algorithm.
|
ALTER TABLE pd_alter_plain SET (level = 4);
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_alter_plain'::regclass))
|
ORDER BY option_name;
|
|
-- (c) RESET (level) removes the key from the catalog and returns the
|
-- field to runtime resolve (no GUC value is frozen in its place).
|
SET cfs_default_lz4_level = 9;
|
|
ALTER TABLE pd_alter_plain RESET (level);
|
|
RESET cfs_default_lz4_level;
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_alter_plain'::regclass))
|
ORDER BY option_name;
|
|
-- (d) A non-CFS SET leaves the stored policy verbatim.
|
CREATE TABLE pd_alter_ff (i int)
|
WITH (algorithm = 'lz4', level = 6, min_gain_bytes = 111);
|
|
ALTER TABLE pd_alter_ff SET (fillfactor = 50);
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_alter_ff'::regclass))
|
ORDER BY option_name;
|
|
-- (e) RESET (algorithm) with an explicit level left behind is still
|
-- rejected (auxiliary options require the algorithm).
|
CREATE TABLE pd_alter_noalgo (i int)
|
WITH (algorithm = 'lz4', level = 4, min_gain_bytes = 128);
|
|
ALTER TABLE pd_alter_noalgo RESET (algorithm);
|
|
-- ----------------------------------------------------------------------
|
-- 5. Indexes on a CFS table: an index inherits the parent's physical
|
-- fact (algorithm) and only the parent's EXPLICIT auxiliary fields;
|
-- its own unset fields resolve at runtime and are never GUC-filled.
|
-- ----------------------------------------------------------------------
|
|
-- (a) Full explicit parent policy: the index inherits the complete
|
-- explicit triple.
|
CREATE TABLE pd_idx_t (i int, t text)
|
WITH (algorithm = 'lz4', level = 6, min_gain_bytes = 300);
|
|
CREATE INDEX pd_idx_copy ON pd_idx_t (i);
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_idx_copy'::regclass))
|
ORDER BY option_name;
|
|
-- (b) Own algorithm: stored verbatim, no GUC freeze of the aux keys.
|
SET cfs_default_zstd_level = 5;
|
|
CREATE INDEX pd_idx_algo ON pd_idx_t (t) WITH (algorithm = 'zstd');
|
|
RESET cfs_default_zstd_level;
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_idx_algo'::regclass))
|
ORDER BY option_name;
|
|
-- (c) Own partial policy: only what was spelled out.
|
CREATE INDEX pd_idx_partial ON pd_idx_t (i, t) WITH (algorithm = 'lz4', level = 4);
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_idx_partial'::regclass))
|
ORDER BY option_name;
|
|
-- (d) Algo-only parent: the index inherits the algorithm alone.
|
CREATE TABLE pd_idx_algo_only (i int) WITH (algorithm = 'zstd');
|
|
CREATE INDEX pd_idx_inherit_min ON pd_idx_algo_only (i);
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_idx_inherit_min'::regclass))
|
ORDER BY option_name;
|
|
-- (e) ALTER INDEX SET (algorithm) on an index with an inherited policy:
|
-- the algorithm is replaced, the stored keys are kept as they are.
|
ALTER INDEX pd_idx_copy SET (algorithm = 'zstd');
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_idx_copy'::regclass))
|
ORDER BY option_name;
|
|
-- ----------------------------------------------------------------------
|
-- 6. Partitioning: the partitioned root stores only its explicit keys,
|
-- and a partition created without own options inherits exactly those.
|
-- ----------------------------------------------------------------------
|
|
CREATE TABLE pd_part (id int, payload text) PARTITION BY RANGE (id)
|
WITH (algorithm = 'lz4');
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_part'::regclass))
|
ORDER BY option_name;
|
|
CREATE TABLE pd_part_1 PARTITION OF pd_part FOR VALUES FROM (0) TO (100);
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_part_1'::regclass))
|
ORDER BY option_name;
|
|
-- A partition without an explicit level resolves it from the session GUC
|
-- at write time, exactly like any CFS relation (with the divergence warning
|
-- machinery gone, unset fields on both sides track the live GUC, so a
|
-- partition cannot silently diverge from the parent default).
|
SET cfs_default_lz4_level = 6;
|
SELECT is_cfs, algorithm, level, min_gain_bytes
|
FROM cfs_relation_policy('pd_part_1');
|
RESET cfs_default_lz4_level;
|
|
-- The partitioned root is not a physical CFS relation (is_cfs stays
|
-- false in the storage sense) but exposes its default policy.
|
SELECT relkind, is_cfs, algorithm, level, min_gain_bytes,
|
is_partitioned_root, is_supported, level_effective, min_gain_effective
|
FROM pg_cfs_relation_info('pd_part');
|
|
SELECT relkind, is_cfs, algorithm, level, min_gain_bytes, is_partitioned_root
|
FROM pg_cfs_settings WHERE relname = 'pd_part';
|
|
-- pg_cfs_settings shows the stored policy only: unset fields carry the 0
|
-- sentinel (exactly like the WAL policy record), never the reloption
|
-- parser's placeholder default (3 / 512).
|
SELECT relkind, is_cfs, algorithm, level, min_gain_bytes
|
FROM pg_cfs_settings WHERE relname = 'pd_t_algo_only';
|
|
-- A partitioned root without a default policy keeps showing NULL, exactly
|
-- like any other non-CFS relation.
|
CREATE TABLE pd_part_plain (id int) PARTITION BY RANGE (id);
|
SELECT relkind, is_cfs, algorithm, level, min_gain_bytes,
|
level_effective, min_gain_effective
|
FROM pg_cfs_relation_info('pd_part_plain');
|
SELECT relkind, is_cfs, algorithm, level, min_gain_bytes, is_partitioned_root
|
FROM pg_cfs_settings WHERE relname = 'pd_part_plain';
|
DROP TABLE pd_part_plain;
|
|
-- An ordinary non-CFS table is unaffected (regression guard).
|
CREATE TABLE pd_plain_t (id int);
|
SELECT relkind, is_cfs, algorithm, level, min_gain_bytes,
|
level_effective, min_gain_effective
|
FROM pg_cfs_relation_info('pd_plain_t');
|
SELECT relkind, is_cfs, algorithm, level, min_gain_bytes, is_partitioned_root
|
FROM pg_cfs_settings WHERE relname = 'pd_plain_t';
|
DROP TABLE pd_plain_t;
|
|
-- ----------------------------------------------------------------------
|
-- 7. Materialized view.
|
-- ----------------------------------------------------------------------
|
|
CREATE MATERIALIZED VIEW pd_mv WITH (algorithm = 'lz4') AS SELECT 1 AS a;
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_mv'::regclass))
|
ORDER BY option_name;
|
|
-- ----------------------------------------------------------------------
|
-- 8. TOAST: the toast relation follows the owning table's policy at
|
-- runtime and stores no CFS options of its own.
|
-- ----------------------------------------------------------------------
|
|
CREATE TABLE pd_toast_t (s text) WITH (algorithm = 'lz4');
|
|
SELECT reloptions
|
FROM pg_class
|
WHERE oid = (SELECT reltoastrelid FROM pg_class
|
WHERE oid = 'pd_toast_t'::regclass);
|
|
-- The toast policy resolves through the owning table: same algorithm,
|
-- same runtime-resolved level.
|
SELECT is_cfs, algorithm, level, min_gain_bytes
|
FROM cfs_relation_policy((SELECT reltoastrelid FROM pg_class
|
WHERE oid = 'pd_toast_t'::regclass));
|
|
SET cfs_default_lz4_level = 4;
|
|
SELECT is_cfs, algorithm, level
|
FROM cfs_relation_policy((SELECT reltoastrelid FROM pg_class
|
WHERE oid = 'pd_toast_t'::regclass));
|
|
RESET cfs_default_lz4_level;
|
|
-- And the toast data is still stored/readable through the CFS write path.
|
INSERT INTO pd_toast_t SELECT repeat('x', 10000) FROM generate_series(1, 5) g;
|
|
SELECT count(*) AS toast_rows, count(*) FILTER (WHERE length(s) = 10000) AS full_rows
|
FROM pd_toast_t;
|
|
-- A renamed TOAST relation no longer matches "pg_toast_<oid>": the owning
|
-- table must be recovered from the catalog reltoastrelid back-link, or the
|
-- TOAST would resolve as non-CFS although its sidecars already hold data.
|
-- Incompressible payload: a repeated literal would compress inline and never
|
-- reach the TOAST relation, leaving it without sidecars. Renaming a TOAST
|
-- relation is a developer operation, hence allow_system_table_mods.
|
SET allow_system_table_mods = on;
|
|
DO $$
|
DECLARE
|
toast_oid oid;
|
BEGIN
|
SELECT reltoastrelid INTO toast_oid
|
FROM pg_class WHERE oid = 'pd_toast_t'::regclass;
|
EXECUTE format('ALTER TABLE %s RENAME TO pd_toast_t_renamed',
|
toast_oid::regclass);
|
END
|
$$;
|
|
INSERT INTO pd_toast_t (s)
|
SELECT string_agg(md5(g::text), '') FROM generate_series(1, 300) g;
|
|
SELECT is_cfs, algorithm, level
|
FROM cfs_relation_policy((SELECT reltoastrelid FROM pg_class
|
WHERE oid = 'pd_toast_t'::regclass));
|
SELECT cfs_relation_has_sidecars((SELECT reltoastrelid FROM pg_class
|
WHERE oid = 'pd_toast_t'::regclass))
|
AS toast_sidecars;
|
SELECT count(*) AS toast_rows,
|
count(*) FILTER (WHERE length(s) = 9600) AS new_rows
|
FROM pd_toast_t;
|
|
-- Misleading name: a TOAST relation renamed to "pg_toast_<oid>" of another
|
-- CFS table. The decoy has no toast relation of its own (no toastable
|
-- column), so the name is free; it parses to the decoy's OID, and only the
|
-- back-link check can reject it. The TOAST must keep the real owner's
|
-- policy (lz4), not the decoy's (zstd).
|
CREATE TABLE pd_toast_decoy (i int) WITH (algorithm = 'zstd');
|
|
DO $$
|
DECLARE
|
toast_oid oid;
|
decoy_oid oid;
|
BEGIN
|
SELECT reltoastrelid INTO toast_oid
|
FROM pg_class WHERE oid = 'pd_toast_t'::regclass;
|
SELECT oid INTO decoy_oid
|
FROM pg_class WHERE oid = 'pd_toast_decoy'::regclass;
|
EXECUTE format('ALTER TABLE %s RENAME TO %I',
|
toast_oid::regclass, 'pg_toast_' || decoy_oid);
|
END
|
$$;
|
|
SELECT algorithm
|
FROM cfs_relation_policy((SELECT reltoastrelid FROM pg_class
|
WHERE oid = 'pd_toast_t'::regclass));
|
|
RESET allow_system_table_mods;
|
|
-- ----------------------------------------------------------------------
|
-- 9. Hand-made partial catalog triple: "algorithm" without "level" /
|
-- "min_gain_bytes" is normal now — the read path resolves it, it is
|
-- not an error.
|
-- ----------------------------------------------------------------------
|
|
CREATE TABLE pd_incomplete (i int) WITH (algorithm = 'lz4', level = 3,
|
min_gain_bytes = 512);
|
|
UPDATE pg_class
|
SET reloptions = '{algorithm=lz4,min_gain_bytes=512}'
|
WHERE oid = 'pd_incomplete'::regclass;
|
|
-- Resolution works and does not error.
|
SELECT is_cfs, algorithm, level, min_gain_bytes
|
FROM cfs_relation_policy('pd_incomplete');
|
SELECT relkind, is_cfs, algorithm, level, min_gain_bytes,
|
level_effective, min_gain_effective
|
FROM pg_cfs_relation_info('pd_incomplete');
|
|
-- pg_cfs_relation_info NULL/effective contract: unset policy fields read
|
-- as NULL (the stored policy is exactly what was spelled out), while the
|
-- *_effective columns resolve the unset fields from the session GUCs the
|
-- same way the write path does. Explicit fields show their stored value
|
-- and do not follow the GUC.
|
SELECT relkind, is_cfs, algorithm, level, min_gain_bytes,
|
level_effective, min_gain_effective
|
FROM pg_cfs_relation_info('pd_t_algo_only');
|
|
SET cfs_default_lz4_level = 8;
|
SELECT level, min_gain_bytes, level_effective, min_gain_effective
|
FROM pg_cfs_relation_info('pd_t_algo_only');
|
SELECT level, min_gain_bytes, level_effective, min_gain_effective
|
FROM pg_cfs_relation_info('pd_t_both');
|
RESET cfs_default_lz4_level;
|
|
-- ----------------------------------------------------------------------
|
-- 10. Validation: the explicit level is range-checked per algorithm;
|
-- the GUC values are not validated against any algorithm (the GUC
|
-- applies only to the algorithm it belongs to).
|
-- ----------------------------------------------------------------------
|
|
CREATE TABLE pd_bad_level (i int) WITH (algorithm = 'lz4', level = 13);
|
|
-- A zstd-range GUC value does not hinder creating an lz4 table without
|
-- an explicit level (inversion of the old M9 cross-check).
|
SET cfs_default_zstd_level = 22;
|
CREATE TABLE pd_guc_wide (i int) WITH (algorithm = 'lz4');
|
RESET cfs_default_zstd_level;
|
|
-- The generic cfs_default_level GUC is gone: the per-algorithm GUCs
|
-- replaced it.
|
SET cfs_default_level = 5;
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_guc_wide'::regclass))
|
ORDER BY option_name;
|
|
-- ----------------------------------------------------------------------
|
-- 11. CLUSTER: a full table rewrite copies the stored (possibly
|
-- partial) reloptions verbatim.
|
-- ----------------------------------------------------------------------
|
|
CREATE TABLE pd_cluster (id int, payload text)
|
WITH (algorithm = 'lz4', min_gain_bytes = 200);
|
|
INSERT INTO pd_cluster SELECT g, 'row ' || g FROM generate_series(1, 50) g;
|
|
CREATE INDEX pd_cluster_idx ON pd_cluster (id);
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_cluster'::regclass))
|
ORDER BY option_name;
|
|
CLUSTER pd_cluster USING pd_cluster_idx;
|
|
SELECT option_name, option_value
|
FROM pg_options_to_table((SELECT reloptions FROM pg_class
|
WHERE oid = 'pd_cluster'::regclass))
|
ORDER BY option_name;
|
|
-- ----------------------------------------------------------------------
|
-- 12. Bulk assertion: over every relation of this test (the pd_%
|
-- namespace, TOAST relations included), the catalog carries only
|
-- what was explicitly requested — the presence of "algorithm="
|
-- no longer implies anything about the auxiliary keys.
|
-- ----------------------------------------------------------------------
|
|
-- Negative control: reloptions without an "algorithm=" entry — this
|
-- table must not appear in the query result below.
|
CREATE TABLE pd_plain (i int) WITH (fillfactor = 60);
|
|
WITH pd AS
|
(
|
SELECT oid, relname, reltoastrelid
|
FROM pg_class
|
WHERE relnamespace = 'public'::regnamespace
|
AND relname LIKE 'pd\_%'
|
)
|
SELECT r.relname,
|
array_to_string(r.reloptions, ',') ~ '(^|,)level=' AS has_level,
|
array_to_string(r.reloptions, ',') ~ '(^|,)min_gain_bytes=' AS has_mgb
|
FROM (
|
SELECT c.relname, c.reloptions
|
FROM pg_class c
|
JOIN pd ON c.oid = pd.oid
|
WHERE c.reloptions IS NOT NULL
|
AND array_to_string(c.reloptions, ',') ~ '(^|,)algorithm='
|
UNION ALL
|
SELECT pd.relname || ' [toast]', t.reloptions
|
FROM pg_class t
|
JOIN pd ON t.oid = pd.reltoastrelid
|
WHERE t.reloptions IS NOT NULL
|
AND array_to_string(t.reloptions, ',') ~ '(^|,)algorithm='
|
) AS r
|
ORDER BY r.relname;
|