On Fri, Mar 9, 2018 at 8:43 AM, Alexander Korotkov <a.korot...@postgrespro.ru> wrote: > Hi! >
Sorry for my late reply. > I'd like to propose a revised patch based on various ideas upthread. Thank you for proposing the patch! > > This patch works as following. > > 1) B-tree meta page is extended with 2 additional parameters: > * btm_oldest_btpo_xact – oldest btpo_xact among of deleted pages, > * btm_last_cleanup_num_heap_tuples – number of heap tuples during last > cleanup scan. > > 2) These parameters are reset during btbulkdelete() and set during > btvacuumcleanup(). Can't we set these parameters even during btbulkdelete()? By keeping them up to date, we will able to avoid an unnecessary cleanup vacuums even after index bulk-delete. > > 3) Index scans during second and subsequent btvacuumcleanup() happen only if > btm_oldest_btpo_xact is older than RecentGlobalXmin > OR num_heap_tuples >= btm_last_cleanup_num_heap_tuples(1 + > vacuum_cleanup_index_scale_factor). > > In other words btvacuumcleanup() scans the index only if there are > recyclable pages, > or index statistics is stalled (inserted more than > vacuum_cleanup_index_scale_factor > since last index statistics collection). > > 4) vacuum_cleanup_index_scale_factor can be set either by GUC or reloption. > Default value is 0.1. So, by default cleanup scan is triggered after > increasing of > table size by 10%. > > 5) Since new fields are added to the metapage, BTREE_VERSION is bumped. > In order to support pg_upgrade, read of previous metapage version is > supported. > On metapage rewrite, it's upgraded to the new version. > > So, since we don't skip scan of recyclable pages, there is no risk of xid > wraparound. > Risk of stalled statistics is also small, because > vacuum_cleanup_index_scale_factor > default value is quite low. User can increase > vacuum_cleanup_index_scale_factor > on his own risk and have less load of B-tree cleanup scan bought by more gap > in > index statistics. Agreed. I've not reviewed the code deeply yet but the regression test of this patch seems to wrongly pass the regression tests and bt_metap() function of pageinspect needs to be updated. Attached an updated patch fixed these issue. Will review the patch again. Regards, -- Masahiko Sawada NIPPON TELEGRAPH AND TELEPHONE CORPORATION NTT Open Source Software Center
0001-lazy-btree-cleanup-4.patch
Description: Binary data