创建表时,可以通过WITH子句指定storage_parameter,这个存储参数指什么?在代码中如何实现?
1、storage_parameter参数说明参考:https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS
2、代码中如何实现?
在Relation结构体的rd_options成员变量指定,以fillfactor为例,在插入时,如何判断该页的填充量:
heap_insert->
buffer = RelationGetBufferForTuple(relation, heaptup->t_len,
| InvalidBuffer, options, bistate,&vmbuffer, NULL);
|-- saveFreeSpace = RelationGetTargetPageFreeSpace(relation,
| HEAP_DEFAULT_FILLFACTOR);
RelationPutHeapTuple(relation, buffer, heaptup,
(options & HEAP_INSERT_SPECULATIVE) != 0);
插入时,heap_insert调用RelationGetBufferForTuple对记录进行插入,而调用RelationGetTargetPageFreeSpace根据指定的填充度判断这个页预留空间多少。
#define RelationGetTargetPageFreeSpace(relation, defaultff) \
(BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100)
#define RelationGetFillFactor(relation, defaultff) \
((relation)->rd_options ? \
((StdRdOptions *) (relation)->rd_options)->fillfactor : (defaultff))
如果创建表时,指定了填充度,则使用指定的值((StdRdOptions *) (relation)->rd_options)->fillfactor,否则使用默认值HEAP_DEFAULT_FILLFACTOR即填充度100%