which sql consumes less memory

Posted by prmatta on Stack Overflow See other posts from Stack Overflow or by prmatta
Published on 2010-03-12T17:01:43Z Indexed on 2010/03/12 17:47 UTC
Read the original article Hit count: 181

Filed under:
|
|
|

Yesterday I asked a question on how to re-write sql to do selects and inserts in batches. I needed to do this to try and consume less virtual memory, since I need to move millions of rows here.

The object is to move rows from Table B into Table A. Here are the ways I can think of doing this:

SQL #1)

   INSERT INTO A (x, y, z)
   SELECT x, y, z
   FROM B b
   WHERE ...

SQL #2)

FOREACH SELECT x,y,z 
        FROM B b
        WHERE ...
            INSERT INTO A(x,y,z);
END FOREACH;

SQL #3)

FOREACH SELECT FIRST 2000 x,y,z 
        FROM B b
        WHERE ...
            INSERT INTO A(x,y,z);
END FOREACH;

SQL #4)

FOREACH SELECT FIRST 2000 x,y,z 
        FROM B b
        WHERE ...
          AND NOT EXISTS IN (SELECT * FROM A)
            INSERT INTO A(x,y,z);
END FOREACH;

Are any of the above incorrect? The database is informix 11.5.

© Stack Overflow or respective owner

Related posts about database

Related posts about sql