PostgreSQL: Defining a primary key on a large database

前端 未结 6 2085
面向向阳花
面向向阳花 2021-01-02 03:29

I am planing a database to store lots of text. (blog posts, news articles, etc.) The database needs to have the title, content (50k characters max), date, link and language

6条回答
  •  隐瞒了意图╮
    2021-01-02 03:45

    I would choose to use a surrogate key, ie. a key that isn't part of the business data of your application. The additional space requirements of an additional 64-bit integer when you're dealing with upto 50 kilobytes of text per record is negligible. You will actually be using less space as soon as you're starting using this key as a foreign key in other tables.

    Using a hash of the data stored in a record is a very bad candidate for a primary key, should the data on which the hash is based ever change. You will then have changed the primary key as well, resulting in updates all over the place if you have relations from other tables to this one.

    PS. A similar question has been asked and answered here before.

    Here's another nice write-up about the topic: http://www.agiledata.org/essays/keys.html

提交回复
热议问题