The EMPLOYEES table from Use The Index, Luke has the DATE_OF_BIRTH field (Type: date). How can one query for all employees that are, let's say, 42 years old - USING AN INDEX? asked Sep 06 '10 at 04:01 Markus Winand ♦♦ |
I like the solution above but I would change the query to not use a function. The application code would pass along 2 dates which would represent the "between" dates so that the following index can be used: CREATE INDEX emp_date_of_birth ON employees (date_of_birth); thoughts?
This answer is marked "community wiki".
answered Mar 02 '11 at 23:41 levg62 There is nothing against that. But you need to take care of the details, especially when using BETWEEN, which is always inclusive. That's why you sometimes need ugly code like shown in Obfuscating Dates. Code like that, which must know the smallest representable interval for the particular database/type, should probably not go to the application. I'd use explicit >= and < in that case.
(Mar 03 '11 at 01:11)
Markus Winand ♦♦
|