1

以下のクエリは、実行に約 20 秒かかるようです。1 つのトランザクションで複数回実行されるため、パフォーマンスに悪影響を及ぼしています。

[update table1
            set column3 = 'new_str'  
          where column1||','||column2 in  
        (select table1.column1||','||column2  
           from table1   
       join table2 on table1.column1 = table2.column1  
      where table2.column4 = 'value4'  
        and table1.column2 = 'value2'  
        and column3 = 'old_str')]  

テーブル 1
column1 - char (12) - 主キー
column2 - char (30) - 主キー
column3 - char (25)

table2
column1 - char (12) - 主キー (テーブル 1 の外部キー)
column4 - char (12)

上記のテーブルには、約 1009578 および 1082555 のレコードがあります。

4

3 に答える 3

0

Table1 に対して不要なクエリを実行していると思います。これを試して:

 update table1 t1
 set column3 = 'new_str'  
 where EXISTS 
  (select *          
   from table2 t2
   where 
     t1.column1 = t2.column1 -- this is your link from t1 to t2
     and t2.column4 = 'value4'  
     and t1.column2 = 'value2'  
     and t2.column3 = 'old_str'
   )
于 2013-03-04T15:26:41.657 に答える
0

ここではそのIN原因は必要ないと思います:

update table1
    set column3 = 'new_str' 
    from table1 join table2 on table1.column1 = table2.column1  
      where table2.column4 = 'value4'  
        and table1.column2 = 'value2'  
        and table1.column3 = 'old_str'

解決策を書いてください ;] !

于 2013-03-04T15:30:42.743 に答える
0

それをテストすることはできませんが、私の意見では、計算フィールドに基づく基準を分割すると、更新が大幅に高速化されるはずです。このようなもの(何かが欠けている可能性があります)は、よりうまく機能するはずです:

[update table1
         set column3 = 'new_str'  
          where column1 in   
        (select table1.column1  
           from table1   
      where table1.column2 = 'value2'  
        and column3 = 'old_str')
        and 
         column2 in 
    (select table2.column2  
           from table2   
      where table2.column1 = column1
        and table2.column4 = 'value4')
        ] 
于 2013-03-04T14:56:53.853 に答える