Comments on: Bundled mysql inserts http://www.imaginarybillboards.com/?p=50 Imagined things Thu, 28 Jan 2010 02:11:13 +0000 hourly 1 https://wordpress.org/?v=6.0.8 By: Matt S Trout http://www.imaginarybillboards.com/?p=50&cpage=1#comment-5 Thu, 13 Aug 2009 17:48:25 +0000 http://www.imaginarybillboards.com/?p=50#comment-5 You know, if you’ve got a $sth, I’m guessing those are the results of the SELECT – so you could equally do:

INSERT INTO foo (…) VALUES (SELECT …);

Of course, that can get slow if mysql tries to slurp the entire thing up front, so a COUNT(*) on the SELECT and then doing the INSERT several times with a LIMIT clause of some sort may be required.

The other thing to remember is that wrapping a transaction around a bunch of inserts may give you most of the same speed.

Oh, and of course LOAD DATA INFILE may be a better strategy if your data is external rather than a SELECT.

Finally, a neat trick with splice –

while (my @one_thousand = splice(@array, 0, 1000)) {

should, I -think-, DWIM – since the boolification of an array is based on its scalarification which is the number of elements – so you can use the truth value for that. or you could do –

do {
my @one_thousand = splice(@array, 0, 1000);

} while (@array);

this same trick is how you can have an iterator that may return undef – your next method returns () for exhaustion and then

while (my ($value) = $it->next) {

will do the right thing.

— mst

]]>
By: James http://www.imaginarybillboards.com/?p=50&cpage=1#comment-4 Thu, 13 Aug 2009 01:03:29 +0000 http://www.imaginarybillboards.com/?p=50#comment-4 No equivalent of the COPY command in MySQL?

]]>