-- test/sql/pending_distinct.sql -- -- aminsert writes one pending entry per DISTINCT trigram of a row, as the -- bulk build does. It used to write one per occurrence; nothing reads the -- position, so repeats were pure waste, and on whole source files (each -- trigram ~9x) the pending list reached ~24x the size of the text it -- indexed (field report 2026-09-29: 137 GB of index over 163 MB). CREATE EXTENSION IF NOT EXISTS pg_tre; psql:test/sql/pending_distinct.sql:9: NOTICE: extension "pg_tre" already exists, skipping CREATE EXTENSION DROP TABLE IF EXISTS pdi; psql:test/sql/pending_distinct.sql:11: NOTICE: table "pdi" does not exist, skipping DROP TABLE CREATE TABLE pdi (id serial PRIMARY KEY, body text) WITH (autovacuum_enabled = off); CREATE TABLE SET client_min_messages = warning; SET CREATE INDEX pdi_tre ON pdi USING tre (body); CREATE INDEX RESET client_min_messages; RESET -- 'abcabc...' has three distinct trigrams (abc, bca, cab) and ~30,000 -- occurrences. One entry each fits a single pending page; one per -- occurrence took ~90. INSERT INTO pdi (body) VALUES (repeat('abc', 10000)); INSERT 0 1 SELECT n_pages AS pending_pages FROM tre_page_kind_histogram('pdi_tre') WHERE page_kind = 'pending'; pending_pages --------------- 1 (1 row) -- Still found, via the pending overlay and after the merge. SET enable_seqscan = off; SET SELECT count(*) AS found_pending FROM pdi WHERE body ~ 'cabca'; found_pending --------------- 1 (1 row) RESET enable_seqscan; RESET VACUUM pdi; VACUUM SET enable_seqscan = off; SET SELECT count(*) AS found_merged FROM pdi WHERE body ~ 'cabca'; found_merged -------------- 1 (1 row) RESET enable_seqscan; RESET DROP TABLE pdi; DROP TABLE