pgsql: Refactor how VACUUM passes around its XID cutoffs. - Mailing list pgsql-committers

From Peter Geoghegan
Subject pgsql: Refactor how VACUUM passes around its XID cutoffs.
Date
Msg-id E1p8PXC-004u6I-Tm@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Refactor how VACUUM passes around its XID cutoffs.

Use a dedicated struct for the XID/MXID cutoffs used by VACUUM, such as
FreezeLimit and OldestXmin.  This state is initialized in vacuum.c, and
then passed around by code from vacuumlazy.c to heapam.c freezing
related routines.  The new convention is that everybody works off of the
same cutoff state, which is passed around via pointers to const.

Also simplify some of the logic for dealing with frozen xmin in
heap_prepare_freeze_tuple: add dedicated "xmin_already_frozen" state to
clearly distinguish xmin XIDs that we're going to freeze from those that
were already frozen from before.  That way the routine's xmin handling
code is symmetrical with the existing xmax handling code.  This is
preparation for an upcoming commit that will add page level freezing.

Also refactor the control flow within FreezeMultiXactId(), while adding
stricter sanity checks.  We now test OldestXmin directly, instead of
using FreezeLimit as an inexact proxy for OldestXmin.  This is further
preparation for the page level freezing work, which will make the
function's caller cede control of page level freezing to the function
where appropriate (where heap_prepare_freeze_tuple sees a tuple that
happens to contain a MultiXactId in its xmax).

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: Jeff Davis <pgsql@j-davis.com>
Discussion: https://postgr.es/m/CAH2-WznS9TxXmz2_=SY+SyJyDFbiOftKofM9=aDo68BbXNBUMA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4ce3afb82ecfbf64d4f6247e725004e1da30f47c

Modified Files
--------------
src/backend/access/heap/heapam.c       | 478 ++++++++++++++++-----------------
src/backend/access/heap/vacuumlazy.c   | 196 ++++++--------
src/backend/access/transam/multixact.c |   9 +-
src/backend/commands/cluster.c         |  25 +-
src/backend/commands/vacuum.c          | 120 ++++-----
src/include/access/heapam.h            |  10 +-
src/include/access/tableam.h           |   2 +-
src/include/commands/vacuum.h          |  49 +++-
8 files changed, 431 insertions(+), 458 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Avoid O(N^2) cost when pulling up lots of UNION ALL subqueries.
Next
From: Peter Geoghegan
Date:
Subject: pgsql: Use scanned_pages to decide when to failsafe check.