I have a transactions table where when the data is fairly distributed across the accounts, the select query is very fast to fetch records for a particular account and order by transaction id, say:
select trans_id, account_no, file_content
from transactions_view
where account_no =:accountNo
order by trans_id
transaction_view is backed by transactions table. transaction_view is a normal view. account_no and trans_id are indexed in table.
So, if I add 1 million records first for account (2) transactions. Then I add the next million transaction across accounts 1 to 10. So the above select query is still fast for account 2 (low ms). But for other accounts it becomes very slow 10s+.
Any recommendations how to deal with skewed data and ordering data by indexed field to improve the query to become fast when fetching for any account?
There are currently around 60 accounts. I tried hash partition on account_no on table. Table also has range partition on date
I noticed if I change order by to account_no, trans_id. And create composite index with (account_no, trans_id) becomes faster. Will do more tests and see.