We are currently using Oracle Database:
Consider a table TRANSACTION
with the fields TRAN_ID
, STATUS
, CREATED_TIME
, ....
The below query gets executed multiple times in a day.
select tran_id
from TRANSACTION table
where created_time <= TO_DATE(:1,'YYYY-MM-DD HH24:MI:SS')
and created time > TO_DATE(:2, 'YYYY-MM-DD HH24:MI:SS')
AND STATUS = :3`
Possible values are I- InProgress
, F- Failed
, S - Successful
. Currently only TRAN_ID is Indexed, so the table goes through a full table scan.
Have the following options:
- Introduce an index on status, this will solve the problem for handling 'In Progress' transaction as they can be low, but failed and success would be higher (However query on 'failed' or 'success' would run once or twice in a day).
- Introduce a composite index(status,created_at) but as I understand the data would get skewed as time progresses and index table will also grow rapidly.
- Move the data from the in progress table to another history table at regular intervals so that it can work coupled with option a. coupled with quite some application changes.
I am not sure if there are other options available.
InProgress
states, it runs every 5 minutes (0.2% relevant records compared to full table) and forFailed
andSuccess
states it runs once in a day ( 2%) which would keep progressively decreasing.