SET enable_hashjoin = 'off';
SET enable_mergejoin = 'off';
SET enable_material = 'on';
 
 
CREATE TABLE big(id bigserial PRIMARY KEY, type_id int, val text);
CREATE TABLE small(id int, type text);
 
INSERT INTO big(type_id, val) SELECT 1,'BBB'||gs.* FROM generate_series(1,1e5) AS gs;
INSERT INTO small(id, type)  SELECT gs.*,'AAA'||gs.* FROM generate_series(1,1e3) AS gs;
VACUUM;
 
explain analyze SELECT * FROM big, small WHERE small.id = big.id AND small.id > 1e3 ORDER BY small.id desc LIMIT 1;

