DB2 LUW 10.5 - How to force DB2 Stored procedures to use latest stats for most optimized plan

久未见 提交于 2019-12-13 03:07:19

问题


We see an issue occasionally. Stored procedure running a SQL runs very slow. Same SQL when run from command line runs very fast. It seems stored procedure uses a different path. The workaround for us is to drop and recreate the procedure, after which it picks up the right plan.

Is there a way to execute a stored procedure with an instruction to regenerate execution plan at run time, so as to get the best plan every time.


回答1:


You probably don't want to recompile plans every time you call your procedure, as you lose the performance benefit of having the procedure in the first place.

When you do need to recompile it, which shouldn't happen too frequently in a stable environment, you can use the REBIND_ROUTINE_PACKAGE system stored procedure:

call SYSPROC.REBIND_ROUTINE_PACKAGE('P', 'YOUR_SP', '')

If you do decide that you want the plan to be recreated each time the procedure is called, you can set the REOPT ALWAYS bind option when you create the procedure, using the many ways described in the manual, for example by executing call SYSPROC.SET_ROUTINE_OPTS('REOPT ALWAYS) before creating the procedure



来源:https://stackoverflow.com/questions/47613287/db2-luw-10-5-how-to-force-db2-stored-procedures-to-use-latest-stats-for-most-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!