0

I'm working with a table of 50+ million rows.

I'd like to know if I should expect a better performance if I first insert batches of ~50k rows in a temporary table, and then in one time insert all of them in the bulk table, instead of directly inserting the ~50k rows in the bulk table?

To be precise, which is better?

  • Many small inserts into the target table or

  • First insert into temp table, then all of them in the target table?

The table has no indices.

Any suggestions for performance increase are welcome, of course!

3
  • 1
    Insert all at once into the target table Commented Feb 26, 2019 at 20:20
  • direct insert = superior? @a_horse_with_no_name Commented Feb 26, 2019 at 20:25
  • @Willem yes, it should be. Commented Feb 26, 2019 at 21:40

1 Answer 1

1

With INSERT performance should not depend on the size of the batch.

The important thing is that you don't run each INSERT in its own transaction.

Additionally, it hurts if each tiny little INSERT has to be parsed separately, so use a prepared statement.

If you do that, it should be faster to insert the data directly rather than using an intermediary table.

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

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.