What's the reason why Django has SmallIntegerField?

后端 未结 2 1715
Happy的楠姐
Happy的楠姐 2021-02-11 14:52

I\'m wonder why it\'s provided. The field is database dependent, doesn\'t that make it totally unreliable to use?

I want to store birth year in a model, kinda like

2条回答
  •  [愿得一人]
    2021-02-11 15:26

    Performance on many RDBMs can be heavily dependent on row size. While a "purist" approach might say that the application should be completely independent of the underlying data structure, over many rows improvements like using a smaller integer could shave gigabytes off table size, which makes more of the table fit in memory, which drastically improves performance. It's the Brief part of the ABCs.

    I would use a small integer like this for say, a primary key on a table that would always have <100 rows, especially when this is stored as a foreign key in a table I expect to grow very large. While the size is implementation defined, it's safe to assume that it is greater than 127 at the very least.

提交回复
热议问题