Skip to content

Commit eb5c404

Browse files
committed
Minor code-cleanliness improvements for btree.
Make the btree page-flags test macros (P_ISLEAF and friends) return clean boolean values, rather than values that might not fit in a bool. Use them in a few places that were randomly referencing the flag bits directly. In passing, change access/nbtree/'s only direct use of BUFFER_LOCK_SHARE to BT_READ. (Some think we should go the other way, but as long as we have BT_READ/BT_WRITE, let's use them consistently.) Masahiko Sawada, reviewed by Doug Doole Discussion: https://postgr.es/m/CAD21AoBmWPeN=WBB5Jvyz_Nt3rmW1ebUyAnk3ZbJP3RMXALJog@mail.gmail.com
1 parent 66917bf commit eb5c404

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

contrib/amcheck/verify_nbtree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ palloc_btree_page(BtreeCheckState *state, BlockNumber blocknum)
11951195

11961196
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
11971197

1198-
if (opaque->btpo_flags & BTP_META && blocknum != BTREE_METAPAGE)
1198+
if (P_ISMETA(opaque) && blocknum != BTREE_METAPAGE)
11991199
ereport(ERROR,
12001200
(errcode(ERRCODE_INDEX_CORRUPTED),
12011201
errmsg("invalid meta page found at block %u in index \"%s\"",
@@ -1206,7 +1206,7 @@ palloc_btree_page(BtreeCheckState *state, BlockNumber blocknum)
12061206
{
12071207
BTMetaPageData *metad = BTPageGetMeta(page);
12081208

1209-
if (!(opaque->btpo_flags & BTP_META) ||
1209+
if (!P_ISMETA(opaque) ||
12101210
metad->btm_magic != BTREE_MAGIC)
12111211
ereport(ERROR,
12121212
(errcode(ERRCODE_INDEX_CORRUPTED),

contrib/pgstattuple/pgstattuple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno,
416416
BTPageOpaque opaque;
417417

418418
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
419-
if (opaque->btpo_flags & (BTP_DELETED | BTP_HALF_DEAD))
419+
if (P_IGNORE(opaque))
420420
{
421421
/* recyclable page */
422422
stat->free_space += BLCKSZ;

src/backend/access/nbtree/nbtpage.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ _bt_getroot(Relation rel, int access)
162162
metad = BTPageGetMeta(metapg);
163163

164164
/* sanity-check the metapage */
165-
if (!(metaopaque->btpo_flags & BTP_META) ||
165+
if (!P_ISMETA(metaopaque) ||
166166
metad->btm_magic != BTREE_MAGIC)
167167
ereport(ERROR,
168168
(errcode(ERRCODE_INDEX_CORRUPTED),
@@ -365,7 +365,7 @@ _bt_gettrueroot(Relation rel)
365365
metaopaque = (BTPageOpaque) PageGetSpecialPointer(metapg);
366366
metad = BTPageGetMeta(metapg);
367367

368-
if (!(metaopaque->btpo_flags & BTP_META) ||
368+
if (!P_ISMETA(metaopaque) ||
369369
metad->btm_magic != BTREE_MAGIC)
370370
ereport(ERROR,
371371
(errcode(ERRCODE_INDEX_CORRUPTED),
@@ -452,7 +452,7 @@ _bt_getrootheight(Relation rel)
452452
metad = BTPageGetMeta(metapg);
453453

454454
/* sanity-check the metapage */
455-
if (!(metaopaque->btpo_flags & BTP_META) ||
455+
if (!P_ISMETA(metaopaque) ||
456456
metad->btm_magic != BTREE_MAGIC)
457457
ereport(ERROR,
458458
(errcode(ERRCODE_INDEX_CORRUPTED),

src/backend/access/nbtree/nbtxlog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ _bt_clear_incomplete_split(XLogReaderState *record, uint8 block_id)
135135
Page page = (Page) BufferGetPage(buf);
136136
BTPageOpaque pageop = (BTPageOpaque) PageGetSpecialPointer(page);
137137

138-
Assert((pageop->btpo_flags & BTP_INCOMPLETE_SPLIT) != 0);
138+
Assert(P_INCOMPLETE_SPLIT(pageop));
139139
pageop->btpo_flags &= ~BTP_INCOMPLETE_SPLIT;
140140

141141
PageSetLSN(page, lsn);
@@ -598,7 +598,7 @@ btree_xlog_delete_get_latestRemovedXid(XLogReaderState *record)
598598
UnlockReleaseBuffer(ibuffer);
599599
return InvalidTransactionId;
600600
}
601-
LockBuffer(hbuffer, BUFFER_LOCK_SHARE);
601+
LockBuffer(hbuffer, BT_READ);
602602
hpage = (Page) BufferGetPage(hbuffer);
603603

604604
/*

src/include/access/nbtree.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ typedef struct BTMetaPageData
173173
*/
174174
#define P_LEFTMOST(opaque) ((opaque)->btpo_prev == P_NONE)
175175
#define P_RIGHTMOST(opaque) ((opaque)->btpo_next == P_NONE)
176-
#define P_ISLEAF(opaque) ((opaque)->btpo_flags & BTP_LEAF)
177-
#define P_ISROOT(opaque) ((opaque)->btpo_flags & BTP_ROOT)
178-
#define P_ISDELETED(opaque) ((opaque)->btpo_flags & BTP_DELETED)
179-
#define P_ISMETA(opaque) ((opaque)->btpo_flags & BTP_META)
180-
#define P_ISHALFDEAD(opaque) ((opaque)->btpo_flags & BTP_HALF_DEAD)
181-
#define P_IGNORE(opaque) ((opaque)->btpo_flags & (BTP_DELETED|BTP_HALF_DEAD))
182-
#define P_HAS_GARBAGE(opaque) ((opaque)->btpo_flags & BTP_HAS_GARBAGE)
183-
#define P_INCOMPLETE_SPLIT(opaque) ((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT)
176+
#define P_ISLEAF(opaque) (((opaque)->btpo_flags & BTP_LEAF) != 0)
177+
#define P_ISROOT(opaque) (((opaque)->btpo_flags & BTP_ROOT) != 0)
178+
#define P_ISDELETED(opaque) (((opaque)->btpo_flags & BTP_DELETED) != 0)
179+
#define P_ISMETA(opaque) (((opaque)->btpo_flags & BTP_META) != 0)
180+
#define P_ISHALFDEAD(opaque) (((opaque)->btpo_flags & BTP_HALF_DEAD) != 0)
181+
#define P_IGNORE(opaque) (((opaque)->btpo_flags & (BTP_DELETED|BTP_HALF_DEAD)) != 0)
182+
#define P_HAS_GARBAGE(opaque) (((opaque)->btpo_flags & BTP_HAS_GARBAGE) != 0)
183+
#define P_INCOMPLETE_SPLIT(opaque) (((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT) != 0)
184184

185185
/*
186186
* Lehman and Yao's algorithm requires a ``high key'' on every non-rightmost

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy