mirror of
https://github.com/postgres/postgres.git
synced 2025-08-18 12:22:09 +03:00
Clean up manipulations of hash indexes' hasho_flag field.
Standardize on testing a hash index page's type by doing (opaque->hasho_flag & LH_PAGE_TYPE) == LH_xxx_PAGE Various places were taking shortcuts like opaque->hasho_flag & LH_BUCKET_PAGE which while not actually wrong, is still bad practice because it encourages use of opaque->hasho_flag & LH_UNUSED_PAGE which *is* wrong (LH_UNUSED_PAGE == 0, so the above is constant false). hash_xlog.c's hash_mask() contained such an incorrect test. This also ensures that we mask out the additional flag bits that hasho_flag has accreted since 9.6. pgstattuple's pgstat_hash_page(), for one, was failing to do that and was thus actively broken. Also fix assorted comments that hadn't been updated to reflect the extended usage of hasho_flag, and fix some macros that were testing just "(hasho_flag & bit)" to use the less dangerous, project-approved form "((hasho_flag & bit) != 0)". Coverity found the bug in hash_mask(); I noted the one in pgstat_hash_page() through code reading.
This commit is contained in:
@@ -1234,6 +1234,7 @@ hash_mask(char *pagedata, BlockNumber blkno)
|
||||
{
|
||||
Page page = (Page) pagedata;
|
||||
HashPageOpaque opaque;
|
||||
int pagetype;
|
||||
|
||||
mask_page_lsn(page);
|
||||
|
||||
@@ -1242,15 +1243,16 @@ hash_mask(char *pagedata, BlockNumber blkno)
|
||||
|
||||
opaque = (HashPageOpaque) PageGetSpecialPointer(page);
|
||||
|
||||
if (opaque->hasho_flag & LH_UNUSED_PAGE)
|
||||
pagetype = opaque->hasho_flag & LH_PAGE_TYPE;
|
||||
if (pagetype == LH_UNUSED_PAGE)
|
||||
{
|
||||
/*
|
||||
* Mask everything on a UNUSED page.
|
||||
*/
|
||||
mask_page_content(page);
|
||||
}
|
||||
else if ((opaque->hasho_flag & LH_BUCKET_PAGE) ||
|
||||
(opaque->hasho_flag & LH_OVERFLOW_PAGE))
|
||||
else if (pagetype == LH_BUCKET_PAGE ||
|
||||
pagetype == LH_OVERFLOW_PAGE)
|
||||
{
|
||||
/*
|
||||
* In hash bucket and overflow pages, it is possible to modify the
|
||||
|
@@ -168,7 +168,7 @@ _hash_addovflpage(Relation rel, Buffer metabuf, Buffer buf, bool retain_pin)
|
||||
if (retain_pin)
|
||||
{
|
||||
/* pin will be retained only for the primary bucket page */
|
||||
Assert(pageopaque->hasho_flag & LH_BUCKET_PAGE);
|
||||
Assert((pageopaque->hasho_flag & LH_PAGE_TYPE) == LH_BUCKET_PAGE);
|
||||
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
|
||||
}
|
||||
else
|
||||
|
@@ -218,8 +218,8 @@ _hash_get_totalbuckets(uint32 splitpoint_phase)
|
||||
/*
|
||||
* _hash_checkpage -- sanity checks on the format of all hash pages
|
||||
*
|
||||
* If flags is not zero, it is a bitwise OR of the acceptable values of
|
||||
* hasho_flag.
|
||||
* If flags is not zero, it is a bitwise OR of the acceptable page types
|
||||
* (values of hasho_flag & LH_PAGE_TYPE).
|
||||
*/
|
||||
void
|
||||
_hash_checkpage(Relation rel, Buffer buf, int flags)
|
||||
|
Reference in New Issue
Block a user