PostgreSQL: Defining a primary key on a large database

前端 未结 6 2110
面向向阳花
面向向阳花 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 04:01

    You'd have to have an awful lot of records before your primary key integer ran out.

    The integer will be faster for joins than a 64 character string primary key would be. Also it is much easier for people writing queries to deal with.

    If a collision is ever possible, you can't use the hash as your primary key. Primary keys must be guarnateed to be unique by definintion.

    I've seen hundreds of production databases for different corporations and government entities and not one used a hash primary key. Think there might be a reason?

    But, it seems stupid and a waste of disc space, because the field wouldn't serve any purpose but to be a primary key.

    Since a surrogate primary key should always be meaningless except as a primary key, I'm not sure what your objection would be.

提交回复
热议问题