如何解释 IBM Data Studio 中的存储过程?
我知道存在db2expln
命令。但我想要一个解决方案来解释图形界面中的 SP。
我也知道选择一个查询然后右键单击它,存在open visual explain
菜单进行解释但不知道解释 SP 的方式,以便我可以设置该 SP 的输入值。
谢谢
如何解释 IBM Data Studio 中的存储过程?
我知道存在db2expln
命令。但我想要一个解决方案来解释图形界面中的 SP。
我也知道选择一个查询然后右键单击它,存在open visual explain
菜单进行解释但不知道解释 SP 的方式,以便我可以设置该 SP 的输入值。
谢谢
如果我正确理解了您的要求,则您有一个程序,您想在该程序中解释查询计划。我会发明一些虚假的东西来解释我的想法:
create table t
( x int not null primary key
, y int not null) @
create procedure p (n int)
language sql
begin
declare c cursor for
select count(1) from t where y = n;
end @
假设您想解释游标中查询的计划:
db2 "explain plan for select count(1) from t where y = n"
[...]
SQL0206N "N" is not valid in the context where it is used. SQLSTATE=42703
由于 n 未绑定,编译器会抱怨。但是,将 n 更改为主变量或参数标记会很好(注意 ":" )
db2 "explain plan for select count(1) from t where y = :n"
或者:
db2 "explain plan for select count(1) from t where y = ?"
现在您可以使用 db2exfmt 查看计划:
db2exfmt -d sample -g -1 | tee q.plan
Access Plan:
-----------
Total Cost: 0.00644873
Query Degree: 1
Rows
RETURN
( 1)
Cost
I/O
|
1
GRPBY
( 2)
0.0063121
0
|
0
FETCH
( 3)
0.00627372
0
/-----+-----\
0 0
IXSCAN TABLE: LELLE
( 4) T
0.00613403 Q1
0
|
0
INDEX: SYSIBM
SQL141230182649950
Q1
我认为你会找到db2exfmt
一个比 更好的工具db2expln
,你会为你的计划获得更多的细节。