【发布时间】:2012-11-14 09:38:12
【问题描述】:
第一次使用 DB2。我有一个执行联合的存储过程,无论如何它都会尝试。该过程超时。联合两侧的 select 语句在单独执行时快速执行,没有问题。为什么工会会这样做?
这里是 proc 的一些 sudo 代码,假设数据类型是 int 或 string,并且它们在比较或联合时匹配,除非 SQL 中另有说明:
DECLARE Foo CURSOR WITH RETURN FOR
Select STRIP(A.Name) as my_Name,
Case A.Number
when 2 then '(' || strip(char(A.Number)) || ')' strip(B.num)
when 3 then '(' || strip(char(A.Number)) || ')' strip(C.num)
when 4 then '(' || strip(char(A.Number)) || ')' strip(D.num)
when 5 then '(' || strip(char(A.Number)) || ')' strip(E.num)
when 6 then '(' || strip(char(A.Number)) || ')' strip(F.num)
end as my_number
FROM A
left outer join B on A.Number= 2 and A.Name = B.Name
left outer join C on A.Number= 3 and C.Name = B.Name
left outer join D on A.Number= 4 and D.Name = B.Name
left outer join E on A.Number= 5 and E.Name = B.Name
left outer join F on A.Number= 6 and F.Name = B.Name
,session.Temp_Result X
WHERE X.ID = A.ID
GROUP BY A.Number, A.Name, B.Name, C.Name, D.Name, E.Name, F.Name
for fetch only ur;
DROP TABLE Session.Temp_Result;
DECLARE GLOBAL TEMPORARY TABLE session.Temp_Result
( ID DECIMAL(18,0)
);
INSERT INTO session.Temp_Result
select X.ID
from Z, Y, X, Q
where Z.num = 6
and Z.ID = Y.ID2
and Y.GROUPA = 'ABC'
and Y.GROUPB = 'DEF'
and Y.ID = X.ID2
and X.ID = Q.ID
union
select W.ID
from Z, Y, W
where Z.num = 6
and Z.ID = Y.ID2
and Y.GROUPA = 'ABC'
and Y.GROUPB = 'DEF'
and Y.ID = W.ID2
group by ID;
OPEN C_HIERARCHIES;
【问题讨论】:
-
请发布SELECT语句,以及涉及的每一列的类型。
-
鉴于
UNION删除了重复项,我觉得这是问题的一部分。 (每条语句)返回了多少行,索引是什么等,可能是有用的信息。 -
每个语句此时返回大约 5 个 ID。直到明天我才能得到任何索引信息。
标签: sql performance timeout db2