There are a couple ways to do this.  As some others have suggested, you could drop the 
keys first, insert the data, and then restore the keys.  I think this is the second 
fastest method.  Here are my picks, in speed order:

1. LOAD DATA INFILE -- this is very fast, and will not update the keys until you're 
done
2. drop keys, insert, then restore keys -- this is not much of an option if you'll 
have other queries executing on the table at the same time
3. explicitly lock the table, do your inserts, and unlock the table -- again, not an 
option if you'll have other queries executing
4. use the extended insert syntax -- see http://www.mysql.com/doc/I/N/INSERT.html

Options #2 and #3 are probably a tossup in speed, and #3 is actually a little easier 
to do.  If you use #4, you may have to break the inserts up into smaller groups -- you 
may not be able to get all those inserts through in one query very easily, depending 
on the total size.  PHP might choke a little on a 1.5 million byte string, also...  If 
you can get them all in one query successfully, then #4 will probably be faster than 
#2 and #3.  You may also find that some combination of them works best for you -- for 
instance, lock the table, do a few extended inserts, and unlock it.  As well as not 
updating the index until all inserts are done, the extended insert also cuts down on 
query overhead.

Hope that helps!
 
Steve Meyers


> -----Original Message-----
> From: Priya Ramkumar [mailto:[EMAIL PROTECTED]]
> Sent: Monday, October 22, 2001 4:01 AM
> To: [EMAIL PROTECTED]
> Subject: faster inserts & updates
> 
> 
> Hi
> 
> I have a PHP program which adds records to a MySQL table. The number of
> records in the table after the execution of the program is around 
> 28,000. I
> also have select & update queries in the program on the same table. The
> process takes a very long time to complete all insertions to the table. I
> already tried "Insert Delayed" on a sample segment of data but 
> found that it
> does not speed up things. Can anyone suggest a method  so that the
> insertions & updates to the table can be faster?
> 
> Thanks for any help.
> 
> Regards,
> Priya
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
> <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> 
> 



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to