I run a query that returns me a set of date objects for months between a specific date range. The request works fine, but very slow (~ 2 seconds on my local computer, ~ 30 in our corporate development environment). There he is:
SELECT ADD_MONTHS(TO_DATE('200804', 'YYYYMM'), -1+rownum) AS MONTH
FROM all_objects
WHERE ADD_MONTHS(TO_DATE('200804', 'YYYYMM'), -1+rownum) <= TO_DATE('200805', 'YYYYMM')
Currently, it returns only one month, but if you extend the second date string, it returns more.
I have two questions. First, why is this happening so slowly? I know that Oracle features really slow down the request, but it takes about 30 seconds on the development machine at my work.
A second and more cryptic question: why is the reduction in runtime reduced to a fraction of a second when you expand the range to, say, '201805'? I think a larger range will take longer. It looks like the opposite effect.
source
share