Your index is uselessprobably not used because its leading columnit does not appear inmatch the WHERE
most selective conditions. Imagine you have a list sorted by last name and (within all people withIf too many rows are returned from the same last name) by first name. Now try to use that list to efficiently find all "William". See – it doesn't workindex scan, a sequential scan is more efficient.
Try this index:
CREATE INDEX ON account_transactions (transaction_type, subsidiary_type, status, transacted_at);
If the condition of any of the leading three columns is not selective, omitting the column from the index is better. The important part is that transacted_at
is last, because it is not used in a condition with =
and is used in ORDER BY
.
You can add WHERE
conditions to the index like you did in your question.