Hi, I spotted this issue with TAM while working on patch [1].
Looking at the code:
```
uint64
table_block_relation_size(Relation rel, ForkNumber forkNumber)
{
uint64 nblocks = 0;
/* InvalidForkNumber indicates returning the size for all forks */
if (forkNumber == InvalidForkNumber)
{
for (int i = 0; i < MAX_FORKNUM; i++)
nblocks += smgrnblocks(RelationGetSmgr(rel), i);
}
```
When forkNumber is InvalidForkNumber, the comment clearly says to return the
size for all forks. But the code uses i < MAX_FORKNUM, and MAX_FORKNUM is
defined as:
```
#define MAX_FORKNUM INIT_FORKNUM
```
Thus, INIT_FORKNUM is excluded.
As a comparison, calculate_toast_table_size() in dbsize.c includes MAX_FORKNUM:
```
/* toast heap size, including FSM and VM size */
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
size += calculate_relation_size(&(toastRel->rd_locator),
toastRel->rd_backend, forkNum);
```
This trivial patch only changes "i < MAX_FORKNUM" to "i <= MAX_FORKNUM", so
that INIT_FORKNUM is included.
This doesn't affect current in-tree callers, because the current source tree
has no call site that passes InvalidForkNumber to table_block_relation_size().
So, maybe it’s okay to fix this only on master.
[1]
https://www.postgresql.org/message-id/DE69B65E-4621-4AF4-9A00-6A042E565C90%40gmail.com
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
v1-0001-Fix-exclusion-of-the-init-fork-in-table_block_rel.patch
Description: Binary data
