mirror of https://github.com/postgres/postgres
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
This commit is contained in:
parent
66917bfaa7
commit
eb5c404b17
|
@ -1195,7 +1195,7 @@ palloc_btree_page(BtreeCheckState *state, BlockNumber blocknum)
|
|||
|
||||
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
|
||||
|
||||
if (opaque->btpo_flags & BTP_META && blocknum != BTREE_METAPAGE)
|
||||
if (P_ISMETA(opaque) && blocknum != BTREE_METAPAGE)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INDEX_CORRUPTED),
|
||||
errmsg("invalid meta page found at block %u in index \"%s\"",
|
||||
|
@ -1206,7 +1206,7 @@ palloc_btree_page(BtreeCheckState *state, BlockNumber blocknum)
|
|||
{
|
||||
BTMetaPageData *metad = BTPageGetMeta(page);
|
||||
|
||||
if (!(opaque->btpo_flags & BTP_META) ||
|
||||
if (!P_ISMETA(opaque) ||
|
||||
metad->btm_magic != BTREE_MAGIC)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INDEX_CORRUPTED),
|
||||
|
|
|
@ -416,7 +416,7 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno,
|
|||
BTPageOpaque opaque;
|
||||
|
||||
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
|
||||
if (opaque->btpo_flags & (BTP_DELETED | BTP_HALF_DEAD))
|
||||
if (P_IGNORE(opaque))
|
||||
{
|
||||
/* recyclable page */
|
||||
stat->free_space += BLCKSZ;
|
||||
|
|
|
@ -162,7 +162,7 @@ _bt_getroot(Relation rel, int access)
|
|||
metad = BTPageGetMeta(metapg);
|
||||
|
||||
/* sanity-check the metapage */
|
||||
if (!(metaopaque->btpo_flags & BTP_META) ||
|
||||
if (!P_ISMETA(metaopaque) ||
|
||||
metad->btm_magic != BTREE_MAGIC)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INDEX_CORRUPTED),
|
||||
|
@ -365,7 +365,7 @@ _bt_gettrueroot(Relation rel)
|
|||
metaopaque = (BTPageOpaque) PageGetSpecialPointer(metapg);
|
||||
metad = BTPageGetMeta(metapg);
|
||||
|
||||
if (!(metaopaque->btpo_flags & BTP_META) ||
|
||||
if (!P_ISMETA(metaopaque) ||
|
||||
metad->btm_magic != BTREE_MAGIC)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INDEX_CORRUPTED),
|
||||
|
@ -452,7 +452,7 @@ _bt_getrootheight(Relation rel)
|
|||
metad = BTPageGetMeta(metapg);
|
||||
|
||||
/* sanity-check the metapage */
|
||||
if (!(metaopaque->btpo_flags & BTP_META) ||
|
||||
if (!P_ISMETA(metaopaque) ||
|
||||
metad->btm_magic != BTREE_MAGIC)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INDEX_CORRUPTED),
|
||||
|
|
|
@ -135,7 +135,7 @@ _bt_clear_incomplete_split(XLogReaderState *record, uint8 block_id)
|
|||
Page page = (Page) BufferGetPage(buf);
|
||||
BTPageOpaque pageop = (BTPageOpaque) PageGetSpecialPointer(page);
|
||||
|
||||
Assert((pageop->btpo_flags & BTP_INCOMPLETE_SPLIT) != 0);
|
||||
Assert(P_INCOMPLETE_SPLIT(pageop));
|
||||
pageop->btpo_flags &= ~BTP_INCOMPLETE_SPLIT;
|
||||
|
||||
PageSetLSN(page, lsn);
|
||||
|
@ -598,7 +598,7 @@ btree_xlog_delete_get_latestRemovedXid(XLogReaderState *record)
|
|||
UnlockReleaseBuffer(ibuffer);
|
||||
return InvalidTransactionId;
|
||||
}
|
||||
LockBuffer(hbuffer, BUFFER_LOCK_SHARE);
|
||||
LockBuffer(hbuffer, BT_READ);
|
||||
hpage = (Page) BufferGetPage(hbuffer);
|
||||
|
||||
/*
|
||||
|
|
|
@ -173,14 +173,14 @@ typedef struct BTMetaPageData
|
|||
*/
|
||||
#define P_LEFTMOST(opaque) ((opaque)->btpo_prev == P_NONE)
|
||||
#define P_RIGHTMOST(opaque) ((opaque)->btpo_next == P_NONE)
|
||||
#define P_ISLEAF(opaque) ((opaque)->btpo_flags & BTP_LEAF)
|
||||
#define P_ISROOT(opaque) ((opaque)->btpo_flags & BTP_ROOT)
|
||||
#define P_ISDELETED(opaque) ((opaque)->btpo_flags & BTP_DELETED)
|
||||
#define P_ISMETA(opaque) ((opaque)->btpo_flags & BTP_META)
|
||||
#define P_ISHALFDEAD(opaque) ((opaque)->btpo_flags & BTP_HALF_DEAD)
|
||||
#define P_IGNORE(opaque) ((opaque)->btpo_flags & (BTP_DELETED|BTP_HALF_DEAD))
|
||||
#define P_HAS_GARBAGE(opaque) ((opaque)->btpo_flags & BTP_HAS_GARBAGE)
|
||||
#define P_INCOMPLETE_SPLIT(opaque) ((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT)
|
||||
#define P_ISLEAF(opaque) (((opaque)->btpo_flags & BTP_LEAF) != 0)
|
||||
#define P_ISROOT(opaque) (((opaque)->btpo_flags & BTP_ROOT) != 0)
|
||||
#define P_ISDELETED(opaque) (((opaque)->btpo_flags & BTP_DELETED) != 0)
|
||||
#define P_ISMETA(opaque) (((opaque)->btpo_flags & BTP_META) != 0)
|
||||
#define P_ISHALFDEAD(opaque) (((opaque)->btpo_flags & BTP_HALF_DEAD) != 0)
|
||||
#define P_IGNORE(opaque) (((opaque)->btpo_flags & (BTP_DELETED|BTP_HALF_DEAD)) != 0)
|
||||
#define P_HAS_GARBAGE(opaque) (((opaque)->btpo_flags & BTP_HAS_GARBAGE) != 0)
|
||||
#define P_INCOMPLETE_SPLIT(opaque) (((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT) != 0)
|
||||
|
||||
/*
|
||||
* Lehman and Yao's algorithm requires a ``high key'' on every non-rightmost
|
||||
|
|
Loading…
Reference in New Issue