Will UUID as primary key in PostgreSQL give bad index performance?

后端 未结 2 2114
抹茶落季
抹茶落季 2021-01-29 20:30

I have created an app in Rails on Heroku using a PostgreSQL database.

It has a couple of tables designed to be able to sync with mobile devices where data can be created

2条回答
  •  情深已故
    2021-01-29 20:51

    As the accepted answer states, range queries may be slow in this case, but not only on id.

    Autoincrement is naturally sorted by date, so when autoincrement is used the data is stored chronologically on disk (see B-Tree) which speeds up reads (no seeking for HDDs). For example, if one lists all the users the natural order would be by date created which is the same as autoincrement and so range queries execute faster on HDDs while on SSD, i guess, the difference would be nonexistent since SSDs are by design always random access (no head seeking, no mechanical parts involved, just pure electricity)

提交回复
热议问题