SQL Database Best Practices - Use of Archive tables?

♀尐吖头ヾ 提交于 2019-12-03 06:47:26

The notion of archiving is a physical, not logical, one. Logically the archive table contains the exact same entity and ought to be the same table.

Physical concerns tend to be pragmatic. The overarching notion is that the "database is getting too (big/slow"). Archiving records makes it easier to do things like:

  1. Optimize the index structure differently. Archive tables can have more indexes without affecting insert/update performance on the working table. In addition, the indexes can be rebuilt with full pages, while the working table will generally want to have pages that are 50% full and balanced.

  2. Optimize storage media differently. You can put the archive table on slower/less expensive disk drives that maybe have more capacity.

  3. Optimize backup strategies differently. Working tables may require hot backups or log shipping while archive tables can use snapshots.

  4. Optimize replication differently, if you are using it. If an archive table is only updated once per day via nightly batch, you can use snapshot as opposed to transactional replication.

  5. Different levels of access. Perhaps you want different security access levels for the archive table.

  6. Lock contention. If you working table is very hot you'd rather have your MIS developers access the archive table where they are less likely to halt your operations when they run something and forget to specify dirty read semantics.

The best practice would not to use archive tables but to move the data from the OLTP database to an MIS database, data warehouse, or data marts with denormalized data. But some organizations will have trouble justifying the cost of an additional DB system (which aren't cheap). There are far fewer hurdles to adding an additional table to an existing DB.

I say this frequently, but...

Multiple tables of identical structure almost never makes sense.

A status flag is a much better idea. There are proper ways to increase performance (partitioning/indexing) without denormalizing data or otherwise creating redundancies. 10 million records is pretty small in the world of modern rdbms, so what you're seeing is the product of poor planning or misunderstanding of databases.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!