Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b6335a3

Browse filesBrowse files
committed
Demote some sanity checks in BufferIsValid() to assertions.
Testing reveals that this macro is a hot-spot for index-only-scans. Per discussion with Tom Lane.
1 parent deb1580 commit b6335a3
Copy full SHA for b6335a3

File tree

Expand file treeCollapse file tree

1 file changed

+10
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-6
lines changed

‎src/include/storage/bufmgr.h

Copy file name to clipboardExpand all lines: src/include/storage/bufmgr.h
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,24 @@ extern PGDLLIMPORT int32 *LocalRefCount;
7878
* True iff the given buffer number is valid (either as a shared
7979
* or local buffer).
8080
*
81-
* This is not quite the inverse of the BufferIsInvalid() macro, since this
82-
* adds sanity rangechecks on the buffer number.
83-
*
8481
* Note: For a long time this was defined the same as BufferIsPinned,
8582
* that is it would say False if you didn't hold a pin on the buffer.
8683
* I believe this was bogus and served only to mask logic errors.
8784
* Code should always know whether it has a buffer reference,
8885
* independently of the pin state.
86+
*
87+
* Note: For a further long time this was not quite the inverse of the
88+
* BufferIsInvalid() macro, in that it also did sanity checks to verify
89+
* that the buffer number was in range. Most likely, this macro was
90+
* originally intended only to be used in assertions, but its use has
91+
* since expanded quite a bit, and the overhead of making those checks
92+
* even in non-assert-enabled builds can be significant. Thus, we've
93+
* now demoted the range checks to assertions within the macro itself.
8994
*/
9095
#define BufferIsValid(bufnum) \
9196
( \
92-
(bufnum) != InvalidBuffer && \
93-
(bufnum) >= -NLocBuffer && \
94-
(bufnum) <= NBuffers \
97+
AssertMacro((bufnum) <= NBuffers && (bufnum) >= -NLocBuffer), \
98+
(bufnum) != InvalidBuffer \
9599
)
96100

97101
/*

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.