Django有SmallIntegerField的原因是什么? [英] What's the reason why Django has SmallIntegerField?
问题描述
我想在一个模型中存储出生年份,有点像
class Person(models.Model):
name = models.CharField(max_length = 256)
born = models.IntegerField )
当然这需要很少的空间,它应该总是4字符长,所以一个PositiveSmallIntegerField可能适合,但为什么我应该选择它而不是正常的IntegerField?
许多RDBM的性能可能严重依赖行大小。虽然纯粹主义的方法可能会说应用程序应该完全独立于底层数据结构,但是像使用较小的整数一样,许多行的改进可能会使表格大小刮掉千兆字节,这使得更多的表适合内存,这大大提高了性能。这是 ABCs 的 B a>。
我将使用一个这样的小整数来表示一个总是具有< 100行的表的主键,特别是当它存储为表中的外键我希望增长非常大。虽然大小是实现定义的,但至少可以假定它大于127。
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
class Person(models.Model):
name = models.CharField(max_length=256)
born = models.IntegerField()
Of course this requires very little space, it should always be 4 "characters" long, so a PositiveSmallIntegerField would maybe fit, but why should I choose it instead of normal IntegerField?
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.
这篇关于Django有SmallIntegerField的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!