How to improve performance for datetime filtering in SQL Server?

Just a suggestion when it comes to indexes on datetime in msql is the index footprint impacts search times (Yes this seems obvious…but please read onward).

The importances to this when indexing on the datetime say for instance ‘2015-06-05 22:47:20.102’ the index has to account for every place within the datetime. This becomes very large spatially and bulky. A successful approach that I’ve leveraged is create a new datetime column and populate the data by rounding the time to the hour and then building the index upon this new column. Example ‘2015-06-05 22:47:20.102’ translates to ‘2015-06-05 22:00:00.000’. By taking this approach we leave the detailed data alone and can display it or use it by search on this new column which gives us approximately a 10x (at minimum) return on how fast results are returned. This is due to the fact that the index doesn’t have to account for the minutes, seconds and millisecond fields.

Leave a Comment