0

fastest way to delete thousands of rows from postgres db tables using java.Presently i am using the following code snippet:

query = "DELETE FROM NODE WHERE SEQUENCE_NO = " + sequenceNo;
            insertOrDelete(query);




insertOrDelete(String query){
    statement = createStatement();
    numRowUpdated = statement.executeUpdate(query);
    closeStatement(statement);
            }
2
  • 1
    java relates to javascript like car relates to carpet. Pick one. Commented Aug 22, 2012 at 4:30
  • Impossible to help improve delete performance without knowing the target database. Come on! Put some thought in your question. Commented Aug 22, 2012 at 5:04

3 Answers 3

2

It's not a Java problem - it's the database.

Make sure there is an index on SEQUENCE_NO. Beyond that, ask the database gurus (depending on the database, there might be things that can improve performance, but in the end it comes all down to database administration: chosing the correct data type for SEQUENCE_NO, keeping meta data up to date etc.).

You probably should add an SQL tag to your question.

Sign up to request clarification or add additional context in comments.

Comments

1

If you are already using a single query, then whether it is Java or anything else, I don't think it can get much faster.

Some tips :

  • use a PreparedStatement. It may be slightly faster, and it will be cleaner/safer/better
  • close the statement in a finally

Comments

1

You might want to consider building a statement like

DELETE FROM NODE WHERE SEQUENCE_NO In (...);

This would do your job in one commit instead of committing several times which would perform better in any case.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.