Hi, When AV worker items where introduced 4 years ago, i was suggested that it could be used for other things like cleaning the pending list of GIN index when it reaches gin_pending_list_limit instead of making user visible operation pay the price.
That never happened though. So, here is a little patch for that. Should I add an entry for this on next commitfest? -- Jaime Casanova Director de Servicios Profesionales SystemGuards - Consultores de PostgreSQL
diff --git a/src/backend/access/gin/ginfast.c b/src/backend/access/gin/ginfast.c index e0d9940946..305326119c 100644 --- a/src/backend/access/gin/ginfast.c +++ b/src/backend/access/gin/ginfast.c @@ -459,7 +459,17 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector) * pending list not forcibly. */ if (needCleanup) - ginInsertCleanup(ginstate, false, true, false, NULL); + { + bool recorded; + + recorded = AutoVacuumRequestWork(AVW_GINCleanPendingList, + RelationGetRelid(ginstate->index), InvalidBlockNumber); + if (!recorded) + ereport(LOG, + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("request for GIN clean pending list for index \"%s\" was not recorded", + RelationGetRelationName(ginstate->index)))); + } } /* diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 23ef23c13e..ee981640e3 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -2680,6 +2680,10 @@ perform_work_item(AutoVacuumWorkItem *workitem) ObjectIdGetDatum(workitem->avw_relation), Int64GetDatum((int64) workitem->avw_blockNumber)); break; + case AVW_GINCleanPendingList: + DirectFunctionCall1(gin_clean_pending_list, + ObjectIdGetDatum(workitem->avw_relation)); + break; default: elog(WARNING, "unrecognized work item found: type %d", workitem->avw_type); @@ -3291,6 +3295,10 @@ autovac_report_workitem(AutoVacuumWorkItem *workitem, snprintf(activity, MAX_AUTOVAC_ACTIV_LEN, "autovacuum: BRIN summarize"); break; + case AVW_GINCleanPendingList: + snprintf(activity, MAX_AUTOVAC_ACTIV_LEN, + "autovacuum: GIN pending list cleanup"); + break; } /* diff --git a/src/include/postmaster/autovacuum.h b/src/include/postmaster/autovacuum.h index aacdd0f575..2cbdde41c4 100644 --- a/src/include/postmaster/autovacuum.h +++ b/src/include/postmaster/autovacuum.h @@ -22,7 +22,8 @@ */ typedef enum { - AVW_BRINSummarizeRange + AVW_BRINSummarizeRange, + AVW_GINCleanPendingList } AutoVacuumWorkItemType;