如果 Django postgresql 数据库中 char 字段的值为 null,那么 table 中实际分配了多少 space?
How much space will be actually allocated in a table if the value for char field is null in Django postgresql database?
我在 Django 中使用 Postgresql 数据库。现在假设我有一个包含三个字段的模型(table):
class TempModel(models.Model):
url = models.CharField(_('Url'), blank=True, null=True, max_length=100)
file = models.FileField(_('File'), upload_to=custom_file_path, null=True, blank=True, max_length=1024)
order = models.IntegerField(_('Order'), blank=False, null=False)
现在,如果我不在 URL 和文件字段中提供任何值,那么空值将存储在这些字段中。 null 占用大约 1 个字节的内存。但最大内存限制分别为 100 个字符和 1024 个字符。
So my doubt is, How much space will be allocated for the URL and file field if I don't provide any input data? Will there be any wastage of memory in database?
NULL 值不占用数据库中的任何存储空间space。
如果 table 有可为空的列,则每个 table 行都有一个 null 位图,表示哪些列为 NULL。这个位图当然占存储空间,但是不管有没有NULL值,它都会占存储空间。
我在 Django 中使用 Postgresql 数据库。现在假设我有一个包含三个字段的模型(table):
class TempModel(models.Model):
url = models.CharField(_('Url'), blank=True, null=True, max_length=100)
file = models.FileField(_('File'), upload_to=custom_file_path, null=True, blank=True, max_length=1024)
order = models.IntegerField(_('Order'), blank=False, null=False)
现在,如果我不在 URL 和文件字段中提供任何值,那么空值将存储在这些字段中。 null 占用大约 1 个字节的内存。但最大内存限制分别为 100 个字符和 1024 个字符。
So my doubt is, How much space will be allocated for the URL and file field if I don't provide any input data? Will there be any wastage of memory in database?
NULL 值不占用数据库中的任何存储空间space。
如果 table 有可为空的列,则每个 table 行都有一个 null 位图,表示哪些列为 NULL。这个位图当然占存储空间,但是不管有没有NULL值,它都会占存储空间。