Please consider following sample query
SELECT * FROM subscriber WHERE subscription_date>DATE(NOW()-INTERVAL 10 DAY)
My question is, if there are 100 records in subscriber table, then how many times the functions NOW() and DATE() will be called? Will these functions be evaluated for comparing with every row, or will they be evaluated just once in the start of the query?
It will be called once. MySQL tries to evaluate the
WHEREclause first, so internally it converts it into a static value.BTW: by using
NOW()your query won’t be cached in MySQL, so when this query is called again some seconds later it has to executed again instead. So better useDATE('2012-01-05 04:00:00'-INTERVAL 10 DAY)