Skip to content

Commit 4b565a1

Browse files
Make visibilitymap_set() return previous state of vmbits
It can be useful to know the state of a relation page's VM bits before visibilitymap_set(). visibilitymap_set() has the old value on hand, so returning it is simple. This commit does not use visibilitymap_set()'s new return value. Author: Melanie Plageman Reviewed-by: Masahiko Sawada, Andres Freund, Nitin Jadhav, Bilal Yavuz Discussion: https://postgr.es/m/flat/CAAKRu_ZQe26xdvAqo4weHLR%3DivQ8J4xrSfDDD8uXnh-O-6P6Lg%40mail.gmail.com#6d8d2b4219394f774889509bf3bdc13d, https://postgr.es/m/ctdjzroezaxmiyah3gwbwm67defsrwj2b5fpfs4ku6msfpxeia%40mwjyqlhwr2wu
1 parent f020baa commit 4b565a1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/backend/access/heap/visibilitymap.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,10 @@ visibilitymap_pin_ok(BlockNumber heapBlk, Buffer vmbuf)
239239
* You must pass a buffer containing the correct map page to this function.
240240
* Call visibilitymap_pin first to pin the right one. This function doesn't do
241241
* any I/O.
242+
*
243+
* Returns the state of the page's VM bits before setting flags.
242244
*/
243-
void
245+
uint8
244246
visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
245247
XLogRecPtr recptr, Buffer vmBuf, TransactionId cutoff_xid,
246248
uint8 flags)
@@ -250,6 +252,7 @@ visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
250252
uint8 mapOffset = HEAPBLK_TO_OFFSET(heapBlk);
251253
Page page;
252254
uint8 *map;
255+
uint8 status;
253256

254257
#ifdef TRACE_VISIBILITYMAP
255258
elog(DEBUG1, "vm_set %s %d", RelationGetRelationName(rel), heapBlk);
@@ -274,7 +277,8 @@ visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
274277
map = (uint8 *) PageGetContents(page);
275278
LockBuffer(vmBuf, BUFFER_LOCK_EXCLUSIVE);
276279

277-
if (flags != (map[mapByte] >> mapOffset & VISIBILITYMAP_VALID_BITS))
280+
status = (map[mapByte] >> mapOffset) & VISIBILITYMAP_VALID_BITS;
281+
if (flags != status)
278282
{
279283
START_CRIT_SECTION();
280284

@@ -311,6 +315,7 @@ visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
311315
}
312316

313317
LockBuffer(vmBuf, BUFFER_LOCK_UNLOCK);
318+
return status;
314319
}
315320

316321
/*

src/include/access/visibilitymap.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ extern bool visibilitymap_clear(Relation rel, BlockNumber heapBlk,
3131
extern void visibilitymap_pin(Relation rel, BlockNumber heapBlk,
3232
Buffer *vmbuf);
3333
extern bool visibilitymap_pin_ok(BlockNumber heapBlk, Buffer vmbuf);
34-
extern void visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
35-
XLogRecPtr recptr, Buffer vmBuf, TransactionId cutoff_xid,
36-
uint8 flags);
34+
extern uint8 visibilitymap_set(Relation rel,
35+
BlockNumber heapBlk, Buffer heapBuf,
36+
XLogRecPtr recptr,
37+
Buffer vmBuf,
38+
TransactionId cutoff_xid,
39+
uint8 flags);
3740
extern uint8 visibilitymap_get_status(Relation rel, BlockNumber heapBlk, Buffer *vmbuf);
3841
extern void visibilitymap_count(Relation rel, BlockNumber *all_visible, BlockNumber *all_frozen);
3942
extern BlockNumber visibilitymap_prepare_truncate(Relation rel,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy