这部分还不是特别了解,仅供探讨,欢迎指正错误。
首先看源代码 src/include/c.h,这里有一个结构定义: struct varlena { char vl_len_[4]; /* Do not touch this field directly! */ char vl_dat[1]; };
紧跟着这个定义之后,我们会发现: typedef struct varlena bytea; typedef struct varlena text; typedef struct varlena BpChar; /* blank-padded char,ie SQL char(n) */ typedef struct varlena VarChar; /* var-length char,ie SQL varchar(n) */ 可以看出,实际有四个类型使用这个结构定义。
文档中提到字符类型时,有这样一段描述: There is no performance difference among these three types,apart from increased storage space when using the blank-padded type,and a few extra CPU cycles to check the length when storing into a length-constrained column. Whilecharacter(n)has performance advantages in some other database systems,there is no such advantage in PostgreSQL; in factcharacter(n)is usually the slowest of the three because of its additional storage costs. In most situationstextorcharacter varyingshould be used instead.
通过上边的定义,我们知道为什么会这样说。
此外,长度字段前两位是标志,后30位才是长度,长度上限略小于1G的限制就是来源于此。 此类定义常见于 PG 各部分,比如块内偏移量与其他定义共用32位空间,实际它只有15位,因此限制整个块大小。以前有朋友问过,为什么PG最大支持32K的块,而更大的块能带来I/O上的提升,这就是原因。 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|