I have a DB2 SQL view created with below statement:
The problem I am facing is kind of strange. When we do a select * on this view, it runs slow for the first few times every new session. But then after 2 to 3 executions, the speed improves drastically and execution time reduces to 2 seconds from the initial 40 seconds.
What you are seeing is the DB2 server's internal optimizations kicking in. The more you use a statement, the more it tunes it.
There are a couple of things you can do to help. One is to set up an EXPLAIN to analyze where the "heavy lifting is done." With that information in mind, you can create indexes and re-order clauses to weed out the grossly-ineligible rows faster (since the smaller the dataset, the faster you can process it).
DB2 does also have some real-time performance measurement tools that are pretty decent.
In the case of a VIEW, also a materialized view is likely to respond better than a dynamic (plain) view. The downside to that being that the data might be stale.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...