I have a table with 300K rows and b-tree index on "operator" field. While I'm runnig this query it isn't using an index. "operator" has the same data-type as dict.vw_dict_operator.id.
EXPLAIN SELECT
id,
name
FROM
dict.vw_dict_operator self
WHERE
EXISTS (
SELECT 42 FROM ti.ti_flight_availability flight_avail
WHERE flight_avail.operator = self.id
)
ORDER BY
self.name
"Sort (cost=3349.66..3351.02 rows=545 width=18)"
" Sort Key: dict_operator.name"
" -> Seq Scan on dict_operator (cost=0.00..3324.89 rows=545 width=18)"
" Filter: ((NOT trash) AND (subplan))"
" SubPlan"
" -> Seq Scan on ti_flight_availability flight_avail (cost=0.00..8513.66 rows=3750 width=0)"
" Filter: (operator = $0)"
UPD: thanks @gbn. index isnot used when joining tables as well
EXPLAIN SELECT self.id, self.name
FROM dict.vw_dict_operator self JOIN ti.ti_flight_availability flight_avail
ON flight_avail.operator = self.id
"Nested Loop (cost=0.00..92988.47 rows=228639 width=18)"
" -> Seq Scan on ti_flight_availability flight_avail (cost=0.00..7754.33 rows=303733 width=4)"
" -> Index Scan using pk_dict_operator on dict_operator (cost=0.00..0.27 rows=1 width=18)"
" Index Cond: (dict_operator.id = flight_avail.operator)"
" Filter: (NOT dict_operator.trash)"