长期运行MERGE语句

时间:2014-03-18 18:35:14

标签: sql performance db2

我有以下MERGE声明需要很长时间(约20-30分钟)。环境是LINUX上的DB2 9.7。数据库上没有运行其他查询,因为它是开发环境。

MERGE INTO TEST.COMPANY cc
USING(SELECT c.COMPANY_ID COMPANY_ID, b.COUNTRY_ID COUNTRY_ID
      FROM COMPANY c, 
           BRNCH b
      WHERE b.branch_id IN (SELECT c.branch_id FROM COMPANY c)) a
ON(cc.COMPANY_ID=a.COMPANY_ID)
WHEN MATCHED AND a.COUNTRY_ID=11000 THEN
UPDATE SET cc.CTRY='US'
WHEN MATCHED AND a.COUNTRY_ID=11001 THEN
UPDATE SET cc.CTRY='CA';

TEST.COMPANY(86 COLUMNS)= 1000 ROWS

  • PK ON COMPANY_ID + COMPANY_REGION_ID

公司(86列)= 1.84百万行

  • PK ON COMPANY_ID + COMPANY_REGION_ID

BRNCH(117列)= 595

  • PK ON BRANCH_ID

执行此操作需要12分钟。我很感激任何sql调优帮助这一个。我希望我提供了足够的信息。

1 个答案:

答案 0 :(得分:2)

试试这个: -

MERGE INTO TEST.COMPANY cc
USING(SELECT c.COMPANY_ID COMPANY_ID, b.COUNTRY_ID COUNTRY_ID
      FROM COMPANY c 
           INNER JOIN 
           BRNCH b
           ON b.branch_id = c.branch_id) a
ON(cc.COMPANY_ID=a.COMPANY_ID)
WHEN MATCHED AND a.COUNTRY_ID=11000 THEN
UPDATE SET cc.CTRY='US'
WHEN MATCHED AND a.COUNTRY_ID=11001 THEN
UPDATE SET cc.CTRY='CA';