-- Short reproduction for the mail body. usage: psql -X -f repro_short.sql \set ON_ERROR_STOP on \pset pager off select version(); drop table if exists orproof_t; create table orproof_t (c int not null, a text not null, b timestamp not null, d int); insert into orproof_t select i % 5, 'K' || lpad(i::text, 7, '0'), timestamp '2026-01-01' + (i % 10) * interval '1 day', i from generate_series(1, 500000) i; create index orproof_t_c_a_b on orproof_t (c, a, b); vacuum analyze orproof_t; -- Builds "c = 1 AND (a, b) IN ()"; every entry of the list exists in the table with c = 1. create or replace function orproof_q(n int) returns text language sql as $$ select 'explain (costs off, summary on) select * from orproof_t where c = 1 and (a, b) in (' || string_agg(format('(%L,%L)', 'K' || lpad((5 * k + 1)::text, 7, '0'), timestamp '2026-01-01' + ((5 * k + 1) % 10) * interval '1 day'), ',') || ')' from generate_series(1, n) k $$; -- Prints only the top plan node and the planning time. create or replace function orproof_plan(n int) returns setof text language plpgsql as $$ declare l text; first boolean := true; begin for l in execute orproof_q(n) loop if first or l like 'Planning Time:%' then return next format('n = %s: %s', n, l); end if; first := false; end loop; end $$; select orproof_plan(n) from unnest(array[250, 500, 1000, 2000, 4000]) n; set enable_bitmapscan = off; select orproof_plan(n) from unnest(array[250, 500, 1000, 2000, 4000]) n; reset enable_bitmapscan; drop function orproof_plan(int); drop function orproof_q(int); drop table orproof_t;