Since your have performance problems, the
only way to help you is if you provide all the requested information. In particular, you also have to tell us:
- how the GET_PERIOD_DATE function is defined,
- how DB2 is configured (buffer pools etc.),
- if and when you collected statistics on the table,
- what the exact execution plan is for the queries.
The thing is that the DB2 optimizer tries to take all relevant system and DB2 configurations as well as statistics etc. into account to come up with the (hopefully) best access plan.
My (wild) guess is that your function is created NOT DETERMINISTIC and/or with EXTERNAL ACTION. Thus, DB2
must call the function for each row in the table, resulting in a slow table scan. The 2nd query w/o function call can be much faster if there is an index on PERIOD_ENDING_DATE, for example.
p.s: The whole idea of an RDBMS is that you do not tell the system
how to retrieve the data - you only tell it which data it should return and the system does the rest.