0

I have a table where there is geospatial data receaved from hundred of mobile device every 10 second. The table is now around 20mln records and is growing very fast. I would like to increase performance and decrease the possibility of table crash.

Which is the best solution to adopt without rewriting all the queries that read/write on this table?

Best is to keep all data accessible but it is not mandatory, in worst case can keep last 30 days.

I have read about table partitioning but i don't know if it is the best solution in my case.

Thanks

3
  • 20 million records is not pretty large. What makes you think that there is any risk of "table crash"? Usually, the database server takes care of that
    – Nico Haase
    Commented Oct 19, 2021 at 8:39
  • Which is the best solution to adopt without rewriting all the queries that read/write on this table? You must define these "all queries" - it is not possible to optimise "in general". Anycase think about partitioning which provides that the query needs to access a small part of partitions only. For example, if the most part of queries needs in recent data then you may partition by the rows creation date - and the queries will access only 1-2 last partitions, not all of them.
    – Akina
    Commented Oct 19, 2021 at 8:52
  • all data accessible it’s not mandatory, in worst case can keep last 30 days.. Keep 30 days.
    – Bohemian
    Commented Oct 19, 2021 at 9:11

2 Answers 2

1

This is a big topic.

PARTITION

You mentioned 30 days, but you may find that you run out of disk space at some point, thereby necessitating some purging, whether at 30 or some other cutoff. So, plain on PARTITION BY RANGE(TO_DAYS(..)) now. I emphasize "now" because it will take downtime to add the partitioning, and you have "only" 20M rows now.

Such partitioning will allow rapid DROP PARTITION of old data. More details: http://mysql.rjweb.org/doc.php/partitionmaint

SELECT and INSERT work without change after the partitioning.

Do not expect any performance difference due to performance -- except when it comes to periodic purging.

With partitioning, you can decide later whether "30" is the right number.

With that partitioning, any query that includes WHERE datetime BETWEEN... will do 'partition pruning'.

Reports

Think about what the output needs to be.

Do you need to plot a vehicle's path for a date last year? If not, then you are saving too much info for too long.

Do you need the 10-sec report from a vehicle that is parked with the motor running (eg, a trucker keeping the AC running while napping)?

Is one of the bits of info "the engine is on/off". That's just one bit, but it rarely changes.

So think about how to shrink or jettison selected bits of info.

If you provide more details on how the data is used, I can provide more tips.

1
  • thanks for the detailed answer. The data it is used to plot a vehicle's path on google maps. Each path Is inside a daily schedule there is not path through different days. Commented Nov 2, 2021 at 10:26
-1

you can create one history table and store older data on to history table and in this case you just need to write trigger or cron job which run on every day and move older data in to history table. for example: your table name id tbl_1 then create one more table with name table_1_history and move all data into table_1_history table which is older then 30 days.

1
  • Please share more details. How does this decrease the chance of data loss? How does this work without rewriting the querys that read the data?
    – Nico Haase
    Commented Oct 20, 2021 at 6:40

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.