-- A term lookup in a dictionary whose terms share their first 8 bytes (fixed-width ids, 'ord-0000' + 8 digits) finds -- its block by bisection, not by reading every block of the run (sift._test_read_stats counts the blocks read). CREATE EXTENSION pg_sift; CREATE EXTENSION pg_sift_test; CREATE TABLE ri (id int PRIMARY KEY, ref text); INSERT INTO ri SELECT i, 'ord-0000' || lpad(i::text, 8, '0') FROM generate_series(1, 40000) i; CREATE INDEX ri_idx ON ri USING sift (ref) WITH (analyzer = keyword); ANALYZE ri; -- every id of a sample is found, and what is not an id is not SELECT count(*) AS found, count(*) FILTER (WHERE (SELECT count(*) FROM ri r WHERE r.ref @@> t.ref) = 1) AS found_once FROM (SELECT ref FROM ri WHERE id % 97 = 0) t; found | found_once -------+------------ 412 | 412 (1 row) SELECT count(*) AS absent_found FROM (SELECT 'ord-0000' || lpad(i::text, 8, '0') AS ref FROM generate_series(40001, 40050) i) t WHERE EXISTS (SELECT 1 FROM ri r WHERE r.ref @@> t.ref); absent_found -------------- 0 (1 row) SELECT count(*) AS before_first FROM ri WHERE ref @@> 'ord-00000000-'; before_first -------------- 0 (1 row) SELECT count(*) AS after_last FROM ri WHERE ref @@> 'ord-0000zzzzzzzz'; after_last ------------ 0 (1 row) -- 400 lookups read about log2(blocks) blocks each: far fewer than the run of about 1250 blocks has SELECT count(*) > 0 AS reset FROM sift._test_read_stats(true); reset ------- t (1 row) SELECT count(*) AS lookups FROM (SELECT ref FROM ri WHERE id % 100 = 7) t WHERE (SELECT count(*) FROM ri r WHERE r.ref @@> t.ref) = 1; lookups --------- 400 (1 row) SELECT value AS probes FROM sift._test_read_stats() WHERE key = 'dict_block_probes' \gset SELECT :probes > 0 AS probed, :probes < 400 * 16 AS bisected; probed | bisected --------+---------- t | t (1 row) DROP TABLE ri; DROP EXTENSION pg_sift_test; DROP EXTENSION pg_sift;