If I have a query like
select sum(number) as points, user from point
where expiryDate < NOW()
group by user
limit 1;
will the DB need to process the entire point table even though it will only need to return 1 row (or afew rows).
Some background:
Users have points that can expire, when points expire, I want to process it. Here I am querying for expired points for each user. Since there are possibly many such points, I am trying to do this process in batches, thus the LIMIT
. But my guess is this does not actually optimize anything if the DB searches the entire DB anyways. Is there a better way?