Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7088745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:50:19+00:00 2026-05-28T07:50:19+00:00

I have a database of events which gets updated every night. A single event

  • 0

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.

The problem is because the data is spread across several tables this is what I have to do to insert a single event:

   (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...

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 each of which depends on getting the id from the previous one. 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!

EDIT: 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.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:50:19+00:00Added an answer on May 28, 2026 at 7:50 am

    Don’t use auto incrementing columns – preallocate your reference id’s before inserting. That way you can use a bulk insert and remove the dependency.

    Update:

    1. Select any existing id’s out of the database (ideally a single select for all known data).

    2. Enrich data to insert with any known id’s. ( calculate a key for each item, which would correspond with the primary key for your table in the database, use that to update the item with the id from the database ) – you want to ultimately split the data into items which you know about in the database, and thus have an known id – and data which doesn’t exist in the database, and thus needs a key allocating. I’m assuming your table has a primary key which isn’t just the id – otherwise how else would the database know you already have the data in the database.

    3. Allocate new id’s to any records without an id.

    4. bulk replace data in the database ( inserting multiple lines with a single statement ).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table of events. Each event has a category and a
I have an events app which gets events data from sqlite database and displays
I have button, which fires an event, that deletes a record from the database.
I have a database with event information, including date (in MMDDYYYY format). is it
I have a ListActivity which gets its data from a database query. I also
I have an events log database. I need to limit the size of SQL
I have a database with event names and dates. I am trying to create
I have a web application that has a dynamic javascript calendar, which allows users
i have a database where each row has lat/long info for goggle maps. each
I have a data model in Doctrine/symfony. I have a 'Course' which has many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.