Hi,

We just had a customer hit this issue. I kind of wonder whether this
shouldn't be backpatched: Currently the execution on the primary is
O(NBuffers * log(ndrels)) whereas it's O(NBuffers * ndrels) on the
standby - with a lot higher constants to boot.  That means it's very
easy to get into situations where the standy starts to lag behind very 
significantly.

> --- a/src/backend/access/transam/twophase.c
> +++ b/src/backend/access/transam/twophase.c
> @@ -1445,6 +1445,7 @@ FinishPreparedTransaction(const char *gid, bool 
> isCommit)
>       int                     ndelrels;
>       SharedInvalidationMessage *invalmsgs;
>       int                     i;
> +     SMgrRelation *srels = NULL;
>  
>       /*
>        * Validate the GID, and lock the GXACT to ensure that two backends do 
> not
> @@ -1534,13 +1535,16 @@ FinishPreparedTransaction(const char *gid, bool 
> isCommit)
>               delrels = abortrels;
>               ndelrels = hdr->nabortrels;
>       }
> +
> +     srels = palloc(sizeof(SMgrRelation) * ndelrels);
>       for (i = 0; i < ndelrels; i++)
> -     {
> -             SMgrRelation srel = smgropen(delrels[i], InvalidBackendId);
> +             srels[i] = smgropen(delrels[i], InvalidBackendId);
>  
> -             smgrdounlink(srel, false);
> -             smgrclose(srel);
> -     }
> +     smgrdounlinkall(srels, ndelrels, false);
> +
> +     for (i = 0; i < ndelrels; i++)
> +             smgrclose(srels[i]);
> +     pfree(srels);

This code is now duplicated three times - shouldn't we just add a
function that encapsulates dropping relations in a commit/abort record?

Greetings,

Andres Freund

Reply via email to