Firebird删除速度很慢

时间:2015-04-07 05:44:30

标签: sql firebird firebird2.5

我正在做这个简单的交易:

DELETE FROM ominve01 
WHERE CVE_OBS IN (SELECT CVE_OBS 
                  FROM minve01 M 
                  WHERE M.FECHA_DOCU < '31.12.2010' 
                  OR FECHA_DOCU > '31.12.2015')
  • minve01有189k行
  • ominve01有86k行

但完成删除大约需要2个半小时。我的查询不好吗?我怎样才能改善它?

或如何提高交易速度?

  • ominve01.cve_obs是pk
  • minve01.cve_obs不是pk

1 个答案:

答案 0 :(得分:1)

DELETE FROM ominve01 N 
WHERE 
exists(SELECT * FROM minve01 M 
       WHERE M.FECHA_DOCU < '31.12.2010' 
       OR FECHA_DOCU > '31.12.2015' and
N.CVE_OBS=M.CVE_OBS)

或执行块(您需要更正变量类型)

execute block
as
declare variable v integer;
begin
for SELECT M.CVE_OBS 
                  FROM minve01 M 
                  WHERE M.FECHA_DOCU < '31.12.2010' 
                  OR FECHA_DOCU > '31.12.2015'
into :v do delete from ominve01 WHERE CVE_OBS=:v;
end