What's the reason why Django has SmallIntegerField?

后端 未结 2 1716
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:10

    It's not totally unreliable. SMALLINT is part of the SQL standard and certainly MySQL and PostgreSQL both have small integer types that go from -32768 to +32767

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题