July 2010
Intermediate to advanced
840 pages
16h 33m
English
If a column appears in a mathematical or string expression, then the optimizer cannot use its indexes. For example, given a table of tasks and their start and finish dates, to find the tasks that took three days to complete in 1994 we could write:
SELECT task_nbr
FROM Tasks
WHERE (finish_date - start_date) = INTERVAL '3' DAY
AND start_date >= CAST ('2005-01-01' AS DATE);But since most of the reports deal with the finish dates, we have an index on that column. This means that the query will run faster if it is rewritten as:
SELECT task_nbr
FROM Tasks
WHERE finish_date = (start_date + INTERVAL '3' DAY)
AND start_date >= ('2005-01-01' AS DATE);This same principle applies to columns in string functions ...
Read now
Unlock full access