Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- index on date fields?


arms - 9:58 am on Sep 27, 2011 (gmt 0)


I wouldn't create an index just for that, but maybe create an index when I need it then delete it when finished, but also I'd look at your query, you're creating an overhead using 2 functions (year(), month()) on a table scan, try using a between statement ie

SELECT * FROM table
WHERE datefield BETWEEN '01-Mar-2011' and '31-Mar-2011 23:59:59'

if you think about it, it's exactly the same request as

SELECT * FROM table WHERE month(datefield) = 3 and year(datefield) = 2011


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4367508.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com