[HACKERS] Small code improvement for btree - Mailing list pgsql-hackers

From Masahiko Sawada
Subject [HACKERS] Small code improvement for btree
Date
Msg-id CAD21AoBmWPeN=WBB5Jvyz_Nt3rmW1ebUyAnk3ZbJP3RMXALJog@mail.gmail.com
Whole thread Raw
Responses Re: [HACKERS] Small code improvement for btree
List pgsql-hackers
Hi,

While hacking the btree code I found two points we can improve in nbtxlog.c.

@@ -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) != 0);
                pageop->btpo_flags &= ~BTP_INCOMPLETE_SPLIT;

                PageSetLSN(page, lsn);

We can use P_INCOMPLETE_SPLIT() instead here.

---
@@ -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);

                /*

We should use BT_READ here rather than BUFFER_LOCK_SHARE.

I think that since such codes are sometimes hard to be found easily by
grep, so could be a cause of bugs when changing the code.
Attached small patch fixes these issues.

Regards,

--
Masahiko Sawada
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachment

pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: [HACKERS] UPDATE of partition key
Next
From: Ashutosh Bapat
Date:
Subject: [HACKERS] scan on inheritance parent with no children in current session