src/backend/access/hash/hashpage.c
static bool
_hash_alloc_buckets(Relation rel, BlockNumber firstblock, uint32 nblocks)
{
	BlockNumber lastblock;
	char		zerobuf[BLCKSZ];

	lastblock = firstblock + nblocks - 1;

	/*
	 * Check for overflow in block number calculation; if so, we cannot extend
	 * the index anymore.
	 */
	if (lastblock < firstblock || lastblock == InvalidBlockNumber)
		return false;

	MemSet(zerobuf, 0, sizeof(zerobuf));

	RelationOpenSmgr(rel);
	smgrextend(rel->rd_smgr, MAIN_FORKNUM, lastblock, zerobuf, false);

	return true;
}
/*
 * _hash_alloc_buckets -- allocate a new splitpoint's worth of bucket pages
 *
 * This does not need to initialize the new bucket pages; we'll do that as
 * each one is used by _hash_expandtable().  But we have to extend the logical
 * EOF to the end of the splitpoint; this keeps smgr's idea of the EOF in
 * sync with ours, so that we don't get complaints from smgr.
 *
 * We do this by writing a page of zeroes at the end of the splitpoint range.
 * We expect that the filesystem will ensure that the intervening pages read
 * as zeroes too.  On many filesystems this "hole" will not be allocated
 * immediately, which means that the index file may end up more fragmented
 * than if we forced it all to be allocated now; but since we don't scan
 * hash indexes sequentially anyway, that probably doesn't matter.
 *
 * XXX It's annoying that this code is executed with the metapage lock held.
 * We need to interlock against _hash_getovflpage() adding a new overflow page
 * concurrently, but it'd likely be better to use LockRelationForExtension
 * for the purpose.  OTOH, adding a splitpoint is a very infrequent operation,
 * so it may not be worth worrying about.
 *
 * Returns TRUE if successful, or FALSE if allocation failed due to
 * BlockNumber overflow.
 */
- allocate a new splitpoint's worth of bucket pages
This does not need to initialize the new bucket pages; we'll do that as
each one is used by _hash_expandtable().  But we have to extend the logical
EOF to the end of the splitpoint; this keeps smgr's idea of the EOF in
sync with ours, so that we don't get complaints from smgr.

We do this by writing a page of zeroes at the end of the splitpoint range.
We expect that the filesystem will ensure that the intervening pages read
as zeroes too.  On many filesystems this "hole" will not be allocated
immediately, which means that the index file may end up more fragmented
than if we forced it all to be allocated now; but since we don't scan
hash indexes sequentially anyway, that probably doesn't matter.

XXX It's annoying that this code is executed with the metapage lock held.
We need to interlock against _hash_getovflpage() adding a new overflow page
concurrently, but it'd likely be better to use LockRelationForExtension
for the purpose.  OTOH, adding a splitpoint is a very infrequent operation,
so it may not be worth worrying about.

Returns TRUE if successful, or FALSE if allocation failed due to
BlockNumber overflow.
- allocate a new splitpoint ' s worth of bucket pages This does not need to initialize the new bucket pages ; we ' ll do that as each one is used by _hash_expandtable () . But we have to extend the logical EOF to the end of the splitpoint ; this keeps smgr ' s idea of the EOF in sync with ours so that we don ' t get complaints from smgr . We do this by writing a page of zeroes at the end of the splitpoint range . We expect that the filesystem will ensure that the intervening pages read as zeroes too . On many filesystems this " hole " will not be allocated immediately which means that the index file may end up more fragmented than if we forced it all to be allocated now ; but since we don ' t scan hash indexes sequentially anyway that probably doesn ' t matter . XXX It ' s annoying that this code is executed with the metapage lock held . We need to interlock against _hash_getovflpage () adding a new overflow page concurrently but it ' d likely be better to use LockRelationForExtension for the purpose . OTOH adding a splitpoint is a very infrequent operation so it may not be worth worrying about . Returns TRUE if successful or FALSE if allocation failed due to BlockNumber overflow .
static bool
_hash_alloc_buckets(Relation rel, BlockNumber firstblock, uint32 nblocks)
{
	BlockNumber lastblock;
	char		zerobuf[BLCKSZ];
	lastblock = firstblock + nblocks - 1;
	if (lastblock < firstblock || lastblock == InvalidBlockNumber)
		return false;
	MemSet(zerobuf, 0, sizeof(zerobuf));
	RelationOpenSmgr(rel);
	smgrextend(rel->rd_smgr, MAIN_FORKNUM, lastblock, zerobuf, false);
	return true;
}
static bool _hash_alloc_buckets ( Relation rel , BlockNumber firstblock , uint32 nblocks ) { BlockNumber lastblock ; char zerobuf [ BLCKSZ ] ; lastblock = firstblock + nblocks - 1 ; if ( lastblock < firstblock || lastblock == InvalidBlockNumber ) return false ; MemSet ( zerobuf , 0 , sizeof ( zerobuf ) ) ; RelationOpenSmgr ( rel ) ; smgrextend ( rel -> rd_smgr , MAIN_FORKNUM , lastblock , zerobuf , false ) ; return true ; }
_hash_alloc_buckets -- allocate a new splitpoint's worth of bucket pages
 This does not need to initialize the new bucket pages; we'll do that as
 each one is used by _hash_expandtable().
_hash_alloc_buckets -- allocate a new splitpoint ' s worth of bucket pages This does not need to initialize the new bucket pages ; we ' ll do that as each one is used by _hash_expandtable () .
/*
	 * Check for overflow in block number calculation; if so, we cannot extend
	 * the index anymore.
	 */