Its not TO_CHAR() itself, its the fact that using _any_ function to convert a column negates the use of the index unless you also create a function based index with that function on the column. In general, if a conversion needs to happen in a predicate, then use conversion functions on the predicate input values, not the columns.
Main Topics
Browse All Topics





by: mrjoltcolaPosted on 2009-08-25 at 09:10:15ID: 25179077
>>is using the to_char function degrading some of my query performance?
Yes.
1) It negates the use of an index on EVENTDATE, if such exists
2) It causes dates to be sorted lexically instead of by actual date value
3) It causes to_char() to be run on every row
Instead of:
AND to_char(T.EVENTDATE, 'YYYY-MM-DD') between '2009-08-20' and '2009-08-20'
Use:
AND T.EVENTDATE between TO_DATE('2009-08-20', 'YYYY-MM-DD') and TO_DATE('2009-08-20', 'YYYY-MM-DD')