3

I'm looking to add about 7 million rows to a live production database table that gets 1-2 writes per second. Can I do this without locking the database for writes? I think so because the table uses InnoDB?

Are there other considerations or do I just write the insert statement and let it rip?

6
  • Cant you do it at night?One method is to disable all constraints,try to partially insert the data,WHERE someid < 500000 ,and put it in a transaction to make sure you dont lose data.
    – Mihai
    Aug 7, 2015 at 13:10
  • I can do it at night, that's a good idea.
    – tplants
    Aug 7, 2015 at 13:12
  • One confusion about transactions: If I am working on transaction A and a stack of writes B come in, do those writes get processed after I commit my transaction?
    – tplants
    Aug 7, 2015 at 13:12
  • 1
    You might get more knowledgeable answers here dba.stackexchange.com
    – Mihai
    Aug 7, 2015 at 13:15
  • If you want to make it snappy, use "load data infile" which is way faster than insert statements.
    – mattexx
    Aug 7, 2015 at 14:58

1 Answer 1

3

If you're using InnoDB, you don't need to do anything special. Just run your inserts. InnoDB uses row level locking for these situations, it will not lock the entire table.

Of course your performance could still take a hit due to the parallel work.

To answer your other question:

"One confusion about transactions: If I am working on transaction A and a stack of writes B come in, do those writes get processed after I commit my transaction"

In general, no. It will not need to wait. This does depend if you are working within the same keyspace or not, and also what isolation level you are working within.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.