postgresql/src/backend/access
Andres Freund 558a9165e0 Compute XID horizon for page level index vacuum on primary.
Previously the xid horizon was only computed during WAL replay. That
had two major problems:
1) It relied on knowing what the table pointed to looks like. That was
   easy enough before the introducing of tableam (we knew it had to be
   heap, although some trickery around logging the heap relfilenodes
   was required). But to properly handle table AMs we need
   per-database catalog access to look up the AM handler, which
   recovery doesn't allow.
2) Not knowing the xid horizon also makes it hard to support logical
   decoding on standbys. When on a catalog table, we need to be able
   to conflict with slots that have an xid horizon that's too old. But
   computing the horizon by visiting the heap only works once
   consistency is reached, but we always need to be able to detect
   conflicts.

There's also a secondary problem, in that the current method performs
redundant work on every standby. But that's counterbalanced by
potentially computing the value when not necessary (either because
there's no standby, or because there's no connected backends).

Solve 1) and 2) by moving computation of the xid horizon to the
primary and by involving tableam in the computation of the horizon.

To address the potentially increased overhead, increase the efficiency
of the xid horizon computation for heap by sorting the tids, and
eliminating redundant buffer accesses. When prefetching is available,
additionally perform prefetching of buffers.  As this is more of a
maintenance task, rather than something routinely done in every read
only query, we add an arbitrary 10 to the effective concurrency -
thereby using IO concurrency, when not globally enabled.  That's
possibly not the perfect formula, but seems good enough for now.

Bumps WAL format, as latestRemovedXid is now part of the records, and
the heap's relfilenode isn't anymore.

Author: Andres Freund, Amit Khandekar, Robert Haas
Reviewed-By: Robert Haas
Discussion:
    https://postgr.es/m/20181212204154.nsxf3gzqv3gesl32@alap3.anarazel.de
    https://postgr.es/m/20181214014235.dal5ogljs3bmlq44@alap3.anarazel.de
    https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
2019-03-26 16:52:54 -07:00
..
brin More unconstify use 2019-02-13 11:50:16 +01:00
common Fix oversight in data-type change for autovacuum_vacuum_cost_delay. 2019-03-26 13:32:38 -04:00
gin Fix misc typos in comments. 2019-01-23 13:39:00 +02:00
gist Fix bug in the GiST vacuum's 2nd stage. 2019-03-22 14:11:46 +02:00
hash Compute XID horizon for page level index vacuum on primary. 2019-03-26 16:52:54 -07:00
heap Compute XID horizon for page level index vacuum on primary. 2019-03-26 16:52:54 -07:00
index Compute XID horizon for page level index vacuum on primary. 2019-03-26 16:52:54 -07:00
nbtree Compute XID horizon for page level index vacuum on primary. 2019-03-26 16:52:54 -07:00
rmgrdesc Compute XID horizon for page level index vacuum on primary. 2019-03-26 16:52:54 -07:00
spgist Collations with nondeterministic comparison 2019-03-22 12:12:43 +01:00
table tableam: Add helper for indexes to check if a corresponding table tuples exist. 2019-03-25 16:52:55 -07:00
tablesample tableam: Add and use scan APIs. 2019-03-11 12:46:41 -07:00
transam Transaction chaining 2019-03-24 11:33:02 +01:00
Makefile Introduce access/{table.h, relation.h}, for generic functions from heapam.h. 2019-01-21 10:51:36 -08:00