使用 postgresql DB 存储 NULL 值需要多少磁盘空间? [英] How much disk-space is needed to store a NULL value using postgresql DB?
问题描述
假设我的表上有一列定义了以下内容:
let's say I have a column on my table defined the following:
"MyColumn" smallint NULL
存储 0、1 或其他值之类的值应该需要 2 个字节 (1).但是如果我将MyColumn"设置为 NULL 需要多少空间?是否需要 0 个字节?
Storing a value like 0, 1 or something else should need 2 bytes (1). But how much space is needed if I set "MyColumn" to NULL? Will it need 0 bytes?
是否有一些额外需要的字节用于管理目的或每列/行的此类内容?
Are there some additional needed bytes for administration purpose or such things for every column/row?
(1) http://www.postgresql.org/docs/9.0/interactive/datatype-numeric.html
推荐答案
不存储空列.该行在开头有一个位图,每列有一个位,指示哪些是空的或非空的.如果一行中的所有列都不为空,则可以省略位图.因此,对于具有一个或多个空值的任何给定行,添加到其中的大小将是位图的大小(N 列表的 N 位,向上取整).
Null columns are not stored. The row has a bitmap at the start and one bit per column that indicates which ones are null or non-null. The bitmap could be omitted if all columns are non-null in a row. So for any given row with one or more nulls, the size added to it would be that of the bitmap(N bits for an N-column table, rounded up).
来自文档的更深入讨论 这里
More in depth discussion from the docs here
这篇关于使用 postgresql DB 存储 NULL 值需要多少磁盘空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!