Your query is getting data for a specific day, so in this case you can omit the AND news.date_online < NOW()
part (Maybe the query optimizer does this for you).
In the other case, where you want all active news without specifying a date_online
, you also should get rid of the NOW(). The problem is, that your query cannot be cached by the database, because it contains parts ( NOW() ) that are different for every execution. You can do this by providing a calculated constant there. If you omit let's say the minute part during comparison, it can be cached for max. 60 seconds.
Next, you should create a multi-column index for the columns that you are using, because I guess category_id
, date_online
and activated
are used in almost every query. This will make inserts a little slower, but from what it looks like (news application) there will be much more reads than inserts.