Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the pros and cons of having history tables?

WHAT is the better practice?:

  1. Keep history records in a separate history table

  2. Keep history records in the active table with different status?

In my opinion I rather to keep a separate table to avoid creating one huge table with duplicate records which may cause unwanted lag time when querying the table.

like image 446
Eric Avatar asked Jan 28 '26 06:01

Eric


1 Answers

My preference has always been to have a separate table with history, purely because it removes the need to have a "WHERE Status = 'LIVE'" or "WHERE CurrentRecord = 1" to get latest record (I won't get into one design that required an inline query to get max(version) to get the latest). It should mean that the current records table should remain smaller and access times may be improved, etc. In the worst case scenario, I've seen an ad-hoc query against a table pick up the wrong version of a record, causing all sorts of problems later on.

Also, if you are already getting the history from another table, you could shard the data, so all history from one year is in one table/db and all history from another is in another table/db and so on.

like image 94
Paul Hadfield Avatar answered Jan 30 '26 02:01

Paul Hadfield



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!