I have an sqlite table Task(type INT ,due_date LONG) where due_date is stored in epoch
TYPE DUE_DATE
---- ----------
1 1582038293
1 1485034292
2 1082048291
3 1982088290
I want to optimize a query to retrieve all type 1 tasks with a given range and type 2 & 3 tasks that are after some date.
Assuming :from and :to are variables -
SELECT * FROM Task WHERE (type=1 AND due_date >= :from AND due_date < :to) OR
(type=2 AND due_date >= :from) OR (type=3 AND due_date >= :from)
- Would it be more optimal if I create an index for columns type & due_date?
- Should I use 3 separate queries for each type if I use index?