diff options
author | Tom Lane | 2017-04-14 21:04:25 +0000 |
---|---|---|
committer | Tom Lane | 2017-04-14 21:04:25 +0000 |
commit | 2040bb4a0b50ef0434a1a723f00d040ab4f1c06f (patch) | |
tree | cc6feca5b13b82793004108cedc54972891b40ea /contrib | |
parent | 1dffabed49054a81b6005a363ab2da4aee0aab9e (diff) |
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.
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/pageinspect/hashfuncs.c | 12 | ||||
-rw-r--r-- | contrib/pgstattuple/pgstattuple.c | 2 |
2 files changed, 8 insertions, 6 deletions
diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c index dd00aaa81a6..6e52969fd34 100644 --- a/contrib/pageinspect/hashfuncs.c +++ b/contrib/pageinspect/hashfuncs.c @@ -184,7 +184,8 @@ hash_page_type(PG_FUNCTION_ARGS) bytea *raw_page = PG_GETARG_BYTEA_P(0); Page page; HashPageOpaque opaque; - char *type; + int pagetype; + const char *type; if (!superuser()) ereport(ERROR, @@ -200,13 +201,14 @@ hash_page_type(PG_FUNCTION_ARGS) opaque = (HashPageOpaque) PageGetSpecialPointer(page); /* page type (flags) */ - if (opaque->hasho_flag & LH_META_PAGE) + pagetype = opaque->hasho_flag & LH_PAGE_TYPE; + if (pagetype == LH_META_PAGE) type = "metapage"; - else if (opaque->hasho_flag & LH_OVERFLOW_PAGE) + else if (pagetype == LH_OVERFLOW_PAGE) type = "overflow"; - else if (opaque->hasho_flag & LH_BUCKET_PAGE) + else if (pagetype == LH_BUCKET_PAGE) type = "bucket"; - else if (opaque->hasho_flag & LH_BITMAP_PAGE) + else if (pagetype == LH_BITMAP_PAGE) type = "bitmap"; else type = "unused"; diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c index 44f90cd0d37..eb02ec5b890 100644 --- a/contrib/pgstattuple/pgstattuple.c +++ b/contrib/pgstattuple/pgstattuple.c @@ -453,7 +453,7 @@ pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno, HashPageOpaque opaque; opaque = (HashPageOpaque) PageGetSpecialPointer(page); - switch (opaque->hasho_flag) + switch (opaque->hasho_flag & LH_PAGE_TYPE) { case LH_UNUSED_PAGE: stat->free_space += BLCKSZ; |