Reputation: 11967
This is my explain: https://explain.depesz.com/s/iR8X
I have an index on orders.account_id and orders.completion_date.
Upvotes: 0
Views: 1003
Reputation: 246463
You can use an index scan, which is much faster, if you create a multi-column index:
CREATE INDEX ON orders(orders_account_id, orders_brand_id);
The same holds for the other branch of the query, but since that is only executed once, it won't matter so much.
Further optimizations could only be suggested if we knew the query.
Upvotes: 1