Best practices with historical data in MySQL database

前端 未结 3 1500
北海茫月
北海茫月 2021-01-12 01:10

Recently I think about the best practices with storing historical data in MySQL database. For now, each versionable table has two columns - valid_from and

3条回答
  •  一向
    一向 (楼主)
    2021-01-12 01:38

    I'm nearing completion of an application which does exactly this. Most of my indexes index by key fields first and then the valid_to field which is set to NULL for current records thereby allowing current records to be found easily and instantly. Since most of my application deals with real time operations, the indexes provide fast performance. Once in a while someone needs to see historical records, and in that instance there's a performance hit, but from testing it's not too bad since most records don't have very many changes over their lifetime.

    In cases where you may have a lot more expired records of various keys than current records it may pay to index over valid_to before any key fields.

提交回复
热议问题