Let's say I have GIN index on column A that allows me to filter table fast on that column by appropriate WHERE condition which would be slow without that index. However I would like also to order filtered rows by using ORDER BY statement on, let's say column B. Ordering without index is slow, so I use BTREE index on column B. The problem is that pg don't want to use both indexes - if both WHERE cond on column A and ORDER BY B are present in query, pg uses only GIN index. When I remove WHERE cond from query, then it uses BTREE index on col B.
What I can do to force pg to use both indexes, one to filter rows and second one to order them?
explain (analyze, verbose)
for your queries. I think you are overestimating the cost of sorting. For a few thousand rows it's most probably faster to sort them in memory than to read the sort key from an index and then do a lookup based on that index.