Although it is not possible for me to give an absolute answer to this question, I can give you a good guess at what I think is causing the difference. The SQL statement in the program is bound as static SQL; the SQL statement in QMF is dynamic SQL. DB2 may be formulating a better access path for the dynamic SQL because it has access to the host variables. Have you considered using dynamic SQL in the application program (only for the query that is causing you problems)?
Dig Deeper on IBM DB2 management
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.