OLTP Aggregate queries best practices
For instance, an OLTP mail application with an 800 million row table they developer want to count stuff like the number of unread emails. What I’m finding is that when the count is high(200k) the queries are slow. Should I create an index using the CREATE_DATE? Or is there some other option I’m not thinking about.
So the query might be something like this.
select count(MAIL_ID)
from EMAILS
where
USER_ID= :1
DELETED = 0
FOLDER_TYPE_ID = -4
and CREATED_DATE > '09-18-2019' ;
select count(a.MESSAGE_ID)
from EMAILS s
inner join MESSAGE m