Icon View Incident Report

Serious Serious
Reported By: Roy Lambert
Reported On: 6/18/2008
For: Version 2.00 Build 2
# 2677 Having Many Deleted Rows in a Table Can Negatively Affect INSERT, UPDATE, or DELETE Performance

I'm trying to use sql but have found that the code below is c100 times slower (1753ms) than the equivalent table version (16ms) when processing 5 records.

procedure TEMailsForm.DoUpdateReadStatus(NewMB: string);
begin
{ UpdateReadStatus.Close;
if not UpdateReadStatus.Prepared then UpdateReadStatus.Prepare;
UpdateReadStatus.ParamByName('UserID').AsString := HHCommons.UserID;
UpdateReadStatus.ParamByName('EMailID').AsString := EMails_MsgNo.AsString;
UpdateReadStatus.ParamByName('NewBox').AsString := NewMB;
UpdateReadStatus.ExecScript;
UpdateReadStatus.Close;}
if emReadStatus.FindKey([EMails_MsgNo.AsInteger, HHCommons.UserID]) then emReadStatus.Delete;
if NewMB <> '' then begin
  emReadStatus.Insert;
  emReadStatus_fkUsers.AsString := HHCommons.UserID;
  emReadStatus_fkEMails.AsInteger := EMails_MsgNo.AsInteger;
  emReadStatus_fkMailBoxes.AsInteger := StrToInt(NewMB);
  try
   emReadStatus.Post;
  except
   emReadStatus.Cancel;
  end;
end;
end;


The script is

SCRIPTINN EMailID VARCHAR, IN UserID VARCHAR, IN NewBox VARCHAR)
BEGIN
 DECLARE Cmnd VARCHAR;
 SET Cmnd = 'DELETE FROM emReadStatus WHERE emReadStatus._fkEMails = '+EMailID + ' AND _fkUsers = '''+UserID+'''';
 EXECUTE IMMEDIATE Cmnd;
 IF NewBox <> '' THEN
  BEGIN
    SET Cmnd = 'INSERT INTO emReadStatus (_fkEMails, _fkMailBoxes, _fkUsers) VALUES ('+ EMailID+', '+ NewBox+', '''+UserID+''')';
    EXECUTE IMMEDIATE Cmnd;
  END;
 END IF;
END



Comments Comments
The problem was due to the fact that there were 85k deleted rows in the table. ElevateDB was navigating through all 85k rows looking for a non-deleted row when it didn't actually have to. It was effectively scanning all 85k rows *twice* for each INSERT. ElevateDB simply does not perform that scan anymore, since it was completely unnecessary.


Resolution Resolution
Fixed Problem on 6/19/2008 in version 2.01 build 1
Image