Small code improvement for btree

From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Small code improvement for btree
Date: 2017-08-04 08:27:35
Message-ID: CAD21AoBmWPeN=WBB5Jvyz_Nt3rmW1ebUyAnk3ZbJP3RMXALJog@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Attachment Content-Type Size
code_improvement_for_btree.patch application/octet-stream 866 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2017-08-04 09:11:38 scan on inheritance parent with no children in current session
Previous Message Amit Langote 2017-08-04 07:41:02 Re: UPDATE of partition key