Search code examples
sqldmlingresansi-92

delete first X row Ingres ANSI


I have 730000+ records which I need to delete in Ingres db which work with ANSI92 and I need to delete then without overload db, simple delete where search condition, doesn't work, DB just use all memory and trowing error. thinking to run it in loop, and delete by portions 10-20K of records .

i tried to use top and it didn't work

 delete top (10)from TABLE where web_id <0 ;

, also was trying to use Limit also didnt work

DELETE FROM from TABLE where web_id <0  LIMIT 10;

any ideas how to do it ? Thank you !


Solution

  • You could use a session temporary table to hold the first 10 tids (tuple id's) and then delete based on those:

    declare global temporary table session.tenrows as
    select first 10 tid the_tid from "table" where web_id<0
    on commit preserve rows with norecovery;
    
    delete from "table" where tid in (select the_tid from session.tenrows);
    

    When you say "without overload db", do you mean avoiding hitting the force-abort limit of the transaction log file? If so what might work for you is:

    set session with on_logfull=notify;
    delete from table where web_id<0;
    

    This would automatically commit your transaction at points where force-abort is reached then carry on, rather than rolling back and reporting an error. A downside of using this setting is that it can be tricky to unpick what has/hasn't been done if any other error should occur (your work will likely be partially committed), but since this appears to be a straight delete from a table it should be quite obvious which rows remain and which don't. The "set session" statement must be run at the start of a transaction. I would advise not running concurrent sessions with "on_logfull=notify" (there have been bugs in this area, whether they're fixed in your installation depends on your version/patch level).