In a recent project, we had a problem with performing several queries, which were largely based on ordering the results by the datetime field (MSSQL 2008 database).
When we ran queries with ORDER BY RecordDate DESC (or ASC), the queries ran 10 times slower than without them. The order for any other area did not lead to such slow results.
We tried all the indexing options, used the setup wizard, nothing has changed.
One proposed solution was to convert the datetime field to an integer field representing the number of seconds or milliseconds in this datetime field. It will be calculated using a simple algorithm, something like "enter me the number of seconds from RecordDate to 1980-01-01." This value will be stored during insertion, and all sorting will be performed in the integer field, and not in the datetime field.
We never tried, but I'm curious what you guys think?
steven
source share