Database optimization orders

前端 未结 4 546
心在旅途
心在旅途 2020-11-29 14:01

In a database where users can place orders, is it better to have a new table with addresses or each order has the address data in its header.

4条回答
  •  温柔的废话
    2020-11-29 14:31

    This is not just about users (and their addresses) but also about prices and other information about products you are selling, that can change after the order has been placed, yet the order itself must remain intact.

    Generally, there are 2 approaches to this:

    1. Copy everything you need in the order (and its items). Even if the "master" data changes, you still have a copy within the order that you can use.
    2. "Version" or "historize" the whole database, similar to this.

    (1) is the more "practical" approach, but can lead to data redundancies (e.g. when address doesn't change, you are nonetheless making separate copies of it).

    (2) is the more "purist" approach, but may require more JOINing and generally be more complex.

提交回复
热议问题