Hi! I found it weird that CLUSTER/VACUUM FULL don't write visibility map. Attached patch implements writing visibility map in heapam_relation_copy_for_cluster().
I've studied previous attempt to implement this [1]. The main problem of that attempt was usage of existing heap_page_is_all_visible() and visibilitymap_set() functions. These functions works through buffer manager, while heap rewriting is made bypass buffer manager. In my patch visibility map pages are handled in the same way as heap pages are. RewriteStateData holds contents of single VM page. Once heap page is finished, corresponding bits are set to VM page etc. VM pages are flushed one-by-one to smgr. This patch have to implement its own check if tuple is allvisible. But it appears to be possible to simplify this check assuming that all tuples already past HeapTupleSatisfiesVacuum(), which sets hint bits. Links 1. https://www.postgresql.org/message-id/flat/20131203162556.GC27105%40momjian.us#90e4a6e77d92076650dcf1d96b32ba38 ------ Alexander Korotkov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company
0001-write-vm-during-cluster-1.patch
Description: Binary data