?
Solved

multi insert transactions

Posted on 2011-04-28
2
Medium Priority
?
389 Views
Last Modified: 2012-06-22
Hello

I am using a multi insert transaction to enter data in batches it there any benefit i changing this:

START TRANSACTION;
NSERT table (field1,field2) VALUES (data1,data2);
INSERT table (field1,field2) VALUES (data3,data4);
INSERT table (field1,field2) VALUES (data5,data6);
INSERT table (field1,field2) VALUES (data7,data8);
INSERT table (field1,field2) VALUES (data9,data10);
COMMIT;

to this


START TRANSACTION;
INSERT table (field1,field2) VALUES
(data1,data2), (data3,data4), (data5,data6), (data7,data8), (data9,data10);
COMMIT;


The latter method is generally quicker without a transcation but is it still quicker whilst using a transaction?

MAny thanks
0
Comment
Question by:andieje
2 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 2000 total points
ID: 35500556
In this case, the transaction offers no benefit assuming all of your data is valid. If one of your inserts fails, you will not be able to detect it easily

see http://andreas.scherbaum.la/blog/archives/171-Pitfalls-of-missing-transactions-when-handling-multiple-inserts-in-Mysql.html

and also http://dev.mysql.com/doc/refman/5.0/en/constraint-invalid-data.html

As far as speed is concerned, you pay a premium for transactions, and if the data is very likely to be good, I would use the mulit-insert without a transaction.

0
 

Author Closing Comment

by:andieje
ID: 35517228
thank-you - I'm sure you recognised your advice to me in this question from a previous question :)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question