drop table if exists foo;

create table foo (a text, b text, c text);
create index on foo (a, b, c);

insert into foo values ('a1', 'b', 'xxx');
insert into foo values ('a1', 'b', 'yyy');
insert into foo values ('a2', 'b', 'xxx');
insert into foo values ('a2', 'b', 'yyy');

-- This produces incorrect result:
--
--  a | b 
-- ---+---
-- (0 rows)
--
set enable_indexskipscan=on;
SELECT DISTINCT ON (a, b)  a, b FROM foo where c like '%y%' and a like 'a%' and b = 'b';

-- This is the correct result:
--
--  a  | b 
-- ----+---
--  a1 | b
--  a2 | b
-- (2 rows)
--
set enable_indexskipscan=off;
SELECT DISTINCT ON (a, b)  a, b FROM foo where c like '%y%' and a like 'a%' and b = 'b';
