-- A write buffer larger than maintenance_work_mem is promoted through a sort that spills to disk, in key order, and -- the immutable segment answers like the write buffer did. CREATE EXTENSION pg_sift; SET sift.async_maintenance = off; SET maintenance_work_mem = '1MB'; SET enable_seqscan = off; CREATE TABLE ps (id serial, body text) WITH (autovacuum_enabled = off); CREATE INDEX ps_idx ON ps USING sift (body) WITH (write_buffer_limit = 1048576); INSERT INTO ps (body) SELECT string_agg('t' || ((g * 7 + j * 13) % 2003) || ' u' || (g % 31) || ' common', ' ') FROM generate_series(1, 6000) g, generate_series(1, 40) j GROUP BY g ORDER BY g; DELETE FROM ps WHERE id % 10 = 0; SELECT kind, ndocs FROM sift.segments('ps_idx') ORDER BY gen; kind | ndocs --------+------- buffer | 6000 (1 row) SELECT count(*) FROM ps WHERE body @@> 'common'; count ------- 5400 (1 row) SELECT count(*) FROM ps WHERE body @@> 't5 AND u3'; count ------- 3 (1 row) SELECT count(*) FROM ps WHERE body @@> 't1000 OR t1999'; count ------- 216 (1 row) SELECT sift.promote('ps_idx'); promote --------- 1 (1 row) SELECT kind, ndocs FROM sift.segments('ps_idx') ORDER BY gen; kind | ndocs -----------+------- buffer | 0 immutable | 6000 (2 rows) SELECT count(*) FROM ps WHERE body @@> 'common'; count ------- 5400 (1 row) SELECT count(*) FROM ps WHERE body @@> 't5 AND u3'; count ------- 3 (1 row) SELECT count(*) FROM ps WHERE body @@> 't1000 OR t1999'; count ------- 216 (1 row) SELECT sift.verify('ps_idx', true); verify -------- (1 row) DROP TABLE ps; DROP EXTENSION pg_sift;