I'm after some guidance or advice really. We've built an application and its gone mental with custom since coronavirus. We are after some advice for something we have never tackled.

The problem we are having is in fact the job table. We have 1000's of office-based users updating, creating, and editing jobs all day. We also have then 10's of thousands of apps out in the field connecting all-day to this table to read their rotas and then update it if they clock in or out of locations.

We've put in all relevant indexes and we are still starting to see a slowdown. To the point some times where we have to restart MYSQL.

After many hours of Googling, we have come across many solutions for big data including solutions on here but we'd like to ask the community what they think or the following idea, or is there a better way?

Idea 1

As the system grows and we get more clients this is only going to get worse. Being that the apps can only see 1 day back and 7 days forward whereas the rota table stores all of the rota history from the beginning of time we were thinking of creating an exact replica table of the job table. This table would store all rotas from yesterday and forward 7 days using a cronjob to delete older data and add new data each night. The apps would then connect to this table to get the jobs list and update the original table if they clock in or out.

If users update fields for jobs yesterday or within 7 days we would use triggers to keep the two tables in sync or maybe do it through code so it was more accurate?

This way we have taken the read load away from our main rota table by pointing the apps at the new table.

Our question is, is this a good way to go, or are we digging a hole we can't climb out of?

Idea 2

Simply archive off jobs from more than a year ago to another table. If users request to see jobs from over a year ago it simply looks in the other table. While we like this solution we can see its a sliding scale. As we get more customers we will have to start archiving sooner and sooner until the problem reappears in a few year's time.

if these ideas are no good does anybody have any other suggestions we can look at? Partitioning the table is not an option at the minute.

  • For advice on the configuration and optimizations: mysql.rjweb.org/doc.php/mysql_analysis
    – Rick James
    Commented May 2, 2020 at 20:55
  • What's the ratio between reads and writes? Do you have replication? If the focus is on 8 days, what is all the old data for?
    – Rick James
    Commented May 2, 2020 at 21:01

1 Answer 1


With the data visibility being only 7+1 days and keeping all the data for much longer, it sounds like what you really need to implement is partitioning by day. This will also make it orders of magnitude easier and quicker to purge the data you no longer wish to keep.

For archiving, you can use a 2nd replicated server that has longer partition retention. For example, the primary server can keep only 8 daily partitions, bit your scheduled event can omit partition dropping from the replication log by toggling sql_log_bin around partition dropping. The result would be that your primary server only has 8 days of data on it and is kept small and fast, while your archive replica keeps all the partitions for a much longer period, up to 8192 partitions at least, which is the limit on the number of partitions on a table. You then have 20-odd years to implement additional further archiving if you really need to keep the data forever. ;-)

In addition to that - it may be worth sharing your table definitions and slow queries - there is always the possibility that there is a more efficient way to query for the data or a better way to index, or a way to pre-aggregate for queries that have to touch thousands of rows.

  • Hi @gordanBobic sorry for my late reply. I've read a ton on partitioning now. I like your idea and I now think some form of partitioning along with archiving of old information is the right way to go. I have a further question about your answer though. The users in the office also access this jobs table. This data is changing a lot and the users in the office may need access to the last 3 months and the next 10 weeks bringing their total to 22 weeks. Would you keep your answer as above with regards to partitioning in this example? Commented May 13, 2020 at 6:59
  • 1
    It changes how many partitions to keep on which server, but it doesn't impact the overall approach. Commented May 13, 2020 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.