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

Attachment: code_improvement_for_btree.patch
Description: Binary data

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

Reply via email to