title: Tricky MySQL batch query
body: <p>I have a database of events which gets updated every night.  A single event has information across three (or more) tables.  Recently the volume of updates has caused my MySQL engine to be very slow to the point that my other queries get frozen while new events are being inserted.  In order to speed things up I want to make a series of batch queries instead of having to do each one separately which I feel like is a large part of the overhead.</p>
  
  <p>The problem is because the data is spread across several tables this is what I have to do to insert a single event:</p>
  
  <pre><code>   (in Mysql) INSERT INTO 'locations' (...) VALUES (...) ON DUPLICATE KEY UPDATE ...
     (in php get the last inserted id into variable $locationID)
     (in Mysql) INSERT INTO 'event_info' (...) VALUES ($locationID, ...) ON DUPLICATE KEY UPDATE...
     (in php get the last inserted id into variable $eventID)
     (in Mysql) INSERT INTO 'event_times' (...) VALUES ($eventID, ...) ON DUPLICATE KEY UPDATE...
  </code></pre>
  
  <p>I'm not looking for help in designing the tables, but as you can see to insert a single event requires at least three inserts <em>each of which depends on getting the id from the previous one.</em>  This is why I didn't know where to begin for making this into a batch request.  Any help for designing this process into a batch request would be awesome, thanks!</p>
  
  <p><strong>EDIT:</strong>  I might already have the location or the event info previously and that is why the ON DUPLICATE KEY UPDATE part is there so that if it was already in the database I get the old id.  I don't know until the insert if it is new data or if it already exists in the database. (because of that unless I am misunderstanding, I can't do things that preallocate the ids since this assume a new id every time.)</p>