On Wed, Mar 25, 2020 at 01:34:43PM +0900, Masahiko Sawada wrote: > I meant that with the patch, suppose that the table has 100 blocks and > we're truncating it to 50 blocks in RelationTruncate(), the error > context message will be "while truncating relation "aaa.bbb" to 100 > blocks", which is not correct.
> I think it should be "while truncating > relation "aaa.bbb" to 50 blocks". We can know the relation can be > truncated to 50 blocks by the result of count_nondeletable_pages(). So > if we update the arguments before it we will use the number of blocks > of relation before truncation. Hm, yea, at that point it's: |new_rel_pages = RelationGetNumberOfBlocks(onerel); ..so we can do better. > My suggestion is either that we change the error message to, for > example, "while truncating relation "aaa.bbb" having 100 blocks", or > that we change the patch so that we can use "50 blocks" in the error > context message. We could do: update_vacuum_error_cbarg(vacrelstats, VACUUM_ERRCB_PHASE_TRUNCATE, InvalidBlockNumber, NULL, false); new_rel_pages = count_nondeletable_pages(onerel, vacrelstats); vacrelstats->blkno = new_rel_pages; ... case VACUUM_ERRCB_PHASE_TRUNCATE: if (BlockNumberIsValid(cbarg->blkno)) errcontext("while truncating relation \"%s.%s\" to %u blocks", cbarg->relnamespace, cbarg->relname, cbarg->blkno); else /* Error happened before/during count_nondeletable_pages() */ errcontext("while truncating relation \"%s.%s\"", cbarg->relnamespace, cbarg->relname); break; -- Justin