lvm отсутствует
select ...
from tablename t
where t.flag = 1
and not exists(select null from tablename sq where sq.link_id = t.link_id and sq.flag != 1)
В документации postgresql указано, что gin индекс быстрее чем gist
A variant of the above query is
SELECT t, t <-> 'word' AS dist
FROM test_trgm
ORDER BY dist LIMIT 10;
This can be implemented quite efficiently by GiST indexes, but not by GIN indexes. It will usually beat the first formulation when only a small number of the closest matches is wanted.
А то ещё окажется, что вы вовсе не можете использовать postgresql. а обязаны ставить какой-то форк с отдельными патчами.