-- The statistics a plan reads of a sift_col index (the sections of its segments, folded once for the server in a record of shared memory) are the same whichever -- segments a backend folds: when the record covers the first segments of the directory (a promotion added one), only the others are opened, and the statistics are -- those of folding all of them. sift._test_leaf_fold folds both ways and says how many segments each opened and whether the bytes are the same. CREATE EXTENSION pg_sift_test CASCADE; NOTICE: installing required extension "pg_sift" SET client_min_messages = warning; SET max_parallel_maintenance_workers = 0; CREATE TABLE lf (id int, dim_a_id int, kind int, label text, amount float8, doc jsonb) WITH (autovacuum_enabled = off); CREATE FUNCTION lf_rows(a int, b int) RETURNS void LANGUAGE sql AS $$ INSERT INTO lf SELECT g, g % 40, g % 7, CASE WHEN g % 9 = 0 THEN NULL ELSE 'l' || (g % 50) END, g * 0.5, CASE WHEN g % 3 = 0 THEN jsonb_build_object('items', jsonb_build_array(jsonb_build_object('t', 'x' || g % 11, 'v', g % 5))) END FROM generate_series(a, b) g $$; SELECT lf_rows(1, 6000); lf_rows --------- (1 row) CREATE INDEX lf_idx ON lf USING sift_col (id, dim_a_id, kind, label, amount, doc) WITH (key_cut = dim_a_id, paths = 'doc.items[]{t text, v float8}'); -- one segment, nothing in the ring yet SELECT folded_shared, folded_full, same FROM sift._test_leaf_fold('lf_idx'); folded_shared | folded_full | same ---------------+-------------+------ 1 | 1 | t (1 row) -- a promotion adds a segment: the record covers the first, the second is the only one opened SELECT lf_rows(6001, 7500); lf_rows --------- (1 row) SELECT sift.col_promote('lf_idx') > 0 AS promoted; promoted ---------- t (1 row) SELECT count(*) AS segments FROM sift._test_col_formats('lf_idx'); segments ---------- 2 (1 row) SELECT folded_shared, folded_full, same FROM sift._test_leaf_fold('lf_idx'); folded_shared | folded_full | same ---------------+-------------+------ 1 | 2 | t (1 row) -- and another one SELECT lf_rows(7501, 8200); lf_rows --------- (1 row) SELECT sift.col_promote('lf_idx') > 0 AS promoted; promoted ---------- t (1 row) SELECT folded_shared, folded_full, same FROM sift._test_leaf_fold('lf_idx'); folded_shared | folded_full | same ---------------+-------------+------ 1 | 3 | t (1 row) -- the same directory again: the record is the whole SELECT folded_shared, folded_full, same FROM sift._test_leaf_fold('lf_idx'); folded_shared | folded_full | same ---------------+-------------+------ 0 | 3 | t (1 row) -- rows in the write buffer do not move the record SELECT lf_rows(8201, 8300); lf_rows --------- (1 row) SELECT folded_shared, folded_full, same FROM sift._test_leaf_fold('lf_idx'); folded_shared | folded_full | same ---------------+-------------+------ 0 | 3 | t (1 row) -- a merge replaces the segments: no prefix, every segment is folded, and the statistics are the same SELECT sift.col_merge('lf_idx', true) >= 0 AS merged; merged -------- t (1 row) SELECT folded_shared = folded_full AS all_folded, same FROM sift._test_leaf_fold('lf_idx'); all_folded | same ------------+------ t | t (1 row) -- a promotion after the merge goes back to adding one SELECT lf_rows(8301, 9000); lf_rows --------- (1 row) SELECT sift.col_promote('lf_idx') > 0 AS promoted; promoted ---------- t (1 row) SELECT folded_shared, folded_full - 1 AS others, same FROM sift._test_leaf_fold('lf_idx'); folded_shared | others | same ---------------+--------+------ 1 | 1 | t (1 row) DROP FUNCTION lf_rows(int, int); DROP TABLE lf; DROP EXTENSION pg_sift_test, pg_sift CASCADE;