简体   繁体   English

DB2 LUW 10.5-如何强制DB2存储过程将最新统计信息用于最优化的计划

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

We see an issue occasionally. 我们偶尔会看到一个问题。 Stored procedure running a SQL runs very slow. 运行SQL的存储过程运行非常慢。 Same SQL when run from command line runs very fast. 从命令行运行时,相同的SQL运行速度非常快。 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. 有没有一种方法可以执行存储过程,并带有一条指令以在运行时重新生成执行计划,从而每次都能获得最佳计划。

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: 当您确实需要重新编译时(在稳定的环境中这种情况不会经常发生),可以使用REBIND_ROUTINE_PACKAGE系统存储过程:

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 如果确定每次调用该过程都希望重新创建计划,则可以在创建过程时使用手册中介绍的多种方法来设置REOPT ALWAYS绑定选项,例如通过执行call SYSPROC.SET_ROUTINE_OPTS('REOPT ALWAYS)创建过程之前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM