For optimal database performance, use conditions on bare columns. Don't wrap them in functions. For example, assuming dtcol is datatype DATE, DATETIME or TIMESTAMP...
SELECT t.dtcol
FROM mytable t
WHERE t.dtcol >= '2014-01-01'
AND t.dtcol < '2015-01-01'
This could also be expressed:
WHERE t.dtcol >= '2014-01-01'
AND t.dtcol < '2014-01-01' + INTERVAL 1 YEAR
If there is an index with dtcol
as the leading column, MySQL can use an index range scan operation.
DON'T do this:
WHERE YEAR(t.dtcol) = 2014
This will force MySQL to evaluate the function on every row in the table, and the compare the result from the function to the literal.
You won't notice any performance difference on small, test tables. But you will notice it (in a slowly painful way) on large tables in a busy system.
There are some significant differences between DATETIME and TIMESTAMP.
DATETIME supports a much larger range of values.
Currently, TIMESTAMP is implemented as a Unix-style 32-bit "seconds since the beginning of the epoch", with a range of values from '1970-01-01 00:00:01' up through some time on '2038-01-19'.