Re: Small code improvement for btree
Alvaro Herrera <alvherre@2ndquadrant.com>
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Masahiko Sawada <sawada.mshk@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2017-08-04T18:12:33Z
Lists: pgsql-hackers
Masahiko Sawada wrote: > 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; Interesting. We learned elsewhere that it's better to integrate the "!= 0" test as part of the macro definition; so a better formulation of this patch would be to change the P_INCOMPLETE_SPLIT macro and omit the comparison in the Assert. (See commit 594e61a1de03 for an example). > - LockBuffer(hbuffer, BUFFER_LOCK_SHARE); > + LockBuffer(hbuffer, BT_READ); I think BT_READ and BT_WRITE are useless, and I'd rather get rid of them ... -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Commits
-
Minor code-cleanliness improvements for btree.
- eb5c404b1775 11.0 landed
-
Change some test macros to return true booleans
- 594e61a1de03 10.0 cited