Thanks for detailed reproducible steps, I can see the reported issue and proposed patch fixes the same.
Thanks for the review!
The deleted code you moved to mdtruncate() should be kept where it was. We cannot ensure that every extension using this interface will adhere to that requirement what the comment describes.
Yeah, I've overlooked the case of extensions. I've moved back the InvalidBlockNumber assignment.
Furthermore, an extension's routine might miss updating
smgr_cached_nblocks. To ensure that updates smgr_cached_nblocks
properly, we should also add an assertion after the call, like this:
/* * Ensure that the local smgr_cached_nblocks value is updated. */ Assert(reln->smgr_cached_nblocks[forknum[i]] != InvalidBlockNumber);
Good point. I've added the assertion.
I wonder how critical it is to have an up to date value of smgr_cached_nblocks after smgr_truncate. Leaving InvalidBlockNumber was also an option as the next user will ask the kernel for the real size. There are some functions like DropRelationBuffers which rely only on the cached value, so it's probably safer to keep the same behaviour.
Чтобы сделать работу с сайтом удобнее, мы используем cookie и аналитический сервис «Яндекс.Метрика». Продолжая пользоваться сайтом, вы соглашаетесь с их использованием.