mirror of
https://github.com/postgres/postgres.git
synced 2025-08-21 10:42:50 +03:00
Change the format of the VM fork to add a second bit per page.
The new bit indicates whether every tuple on the page is already frozen. It is cleared only when the all-visible bit is cleared, and it can be set only when we vacuum a page and find that every tuple on that page is both visible to every transaction and in no need of any future vacuuming. A future commit will use this new bit to optimize away full-table scans that would otherwise be triggered by XID wraparound considerations. A page which is merely all-visible must still be scanned in that case, but a page which is all-frozen need not be. This commit does not attempt that optimization, although that optimization is the goal here. It seems better to get the basic infrastructure in place first. Per discussion, it's very desirable for pg_upgrade to automatically migrate existing VM forks from the old format to the new format. That, too, will be handled in a follow-on patch. Masahiko Sawada, reviewed by Kyotaro Horiguchi, Fujii Masao, Amit Kapila, Simon Riggs, Andres Freund, and others, and substantially revised by me.
This commit is contained in:
@@ -19,15 +19,30 @@
|
||||
#include "storage/buf.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
#define BITS_PER_HEAPBLOCK 2
|
||||
#define HEAPBLOCKS_PER_BYTE (BITS_PER_BYTE / BITS_PER_HEAPBLOCK)
|
||||
|
||||
/* Flags for bit map */
|
||||
#define VISIBILITYMAP_ALL_VISIBLE 0x01
|
||||
#define VISIBILITYMAP_ALL_FROZEN 0x02
|
||||
#define VISIBILITYMAP_VALID_BITS 0x03 /* OR of all valid visiblitymap flags bits */
|
||||
|
||||
/* Macros for visibilitymap test */
|
||||
#define VM_ALL_VISIBLE(r, b, v) \
|
||||
((visibilitymap_get_status((r), (b), (v)) & VISIBILITYMAP_ALL_VISIBLE) != 0)
|
||||
#define VM_ALL_FROZEN(r, b, v) \
|
||||
((visibilitymap_get_status((r), (b), (v)) & VISIBILITYMAP_ALL_FROZEN) != 0)
|
||||
|
||||
extern void visibilitymap_clear(Relation rel, BlockNumber heapBlk,
|
||||
Buffer vmbuf);
|
||||
extern void visibilitymap_pin(Relation rel, BlockNumber heapBlk,
|
||||
Buffer *vmbuf);
|
||||
extern bool visibilitymap_pin_ok(BlockNumber heapBlk, Buffer vmbuf);
|
||||
extern void visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
|
||||
XLogRecPtr recptr, Buffer vmBuf, TransactionId cutoff_xid);
|
||||
extern bool visibilitymap_test(Relation rel, BlockNumber heapBlk, Buffer *vmbuf);
|
||||
extern BlockNumber visibilitymap_count(Relation rel);
|
||||
XLogRecPtr recptr, Buffer vmBuf, TransactionId cutoff_xid,
|
||||
uint8 flags);
|
||||
extern uint8 visibilitymap_get_status(Relation rel, BlockNumber heapBlk, Buffer *vmbuf);
|
||||
extern void visibilitymap_count(Relation rel, BlockNumber *all_visible, BlockNumber *all_frozen);
|
||||
extern void visibilitymap_truncate(Relation rel, BlockNumber nheapblocks);
|
||||
|
||||
#endif /* VISIBILITYMAP_H */
|
||||
|
Reference in New Issue
Block a user