1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-21 10:42:50 +03:00

Allow pg_class xid & multixid horizons to not be set.

This allows table AMs that don't need these horizons. This was already
documented in the tableam relation_set_new_filenode callback, but an
assert prevented if from actually working (the test AM code contained
the change itself). Defang the asserts in the general code, and move
the stronger ones into heap AM.

Relatedly, after CLUSTER/VACUUM, we'd always assign a relfrozenxid /
relminmxid. Change the table_relation_copy_for_cluster() interface to
allow the AM to overwrite the horizons that get set on the pg_class
entry.  This'd also in the future allow AMs like heap to compute a
relfrozenxid during rewrite that's the table's actual minimum rather
than a pre-determined value.  Arguably it'd have been better to move
the whole computation / setting of those values into the callback, but
it seems likely that for other reasons it'd be better to be able to
use one value to vacuum/cluster multiple tables (e.g. a toast's
horizon shouldn't be different than the table's).

Reported-By: Heikki Linnakangas
Author: Andres Freund
Discussion: https://postgr.es/m/9a7fb9cc-2419-5db7-8840-ddc10c93f122@iki.fi
This commit is contained in:
Andres Freund
2019-04-23 21:42:12 -07:00
parent 7ad1cd31bf
commit fdc7efcc30
6 changed files with 83 additions and 45 deletions

View File

@@ -452,8 +452,8 @@ typedef struct TableAmRoutine
Relation OldIndex,
bool use_sort,
TransactionId OldestXmin,
TransactionId FreezeXid,
MultiXactId MultiXactCutoff,
TransactionId *xid_cutoff,
MultiXactId *multi_cutoff,
double *num_tuples,
double *tups_vacuumed,
double *tups_recently_dead);
@@ -1297,32 +1297,37 @@ table_relation_copy_data(Relation rel, RelFileNode newrnode)
* Copy data from `OldHeap` into `NewHeap`, as part of a CLUSTER or VACUUM
* FULL.
*
* If `use_sort` is true, the table contents are sorted appropriate for
* `OldIndex`; if use_sort is false and OldIndex is not InvalidOid, the data
* is copied in that index's order; if use_sort is false and OidIndex is
* InvalidOid, no sorting is performed.
* Additional Input parameters:
* - use_sort - if true, the table contents are sorted appropriate for
* `OldIndex`; if false and OldIndex is not InvalidOid, the data is copied
* in that index's order; if false and OidIndex is InvalidOid, no sorting is
* performed
* - OidIndex - see use_sort
* - OldestXmin - computed by vacuum_set_xid_limits(), even when
* not needed for the relation's AM
* - *xid_cutoff - dito
* - *multi_cutoff - dito
*
* OldestXmin, FreezeXid, MultiXactCutoff must be currently valid values for
* the table.
*
* *num_tuples, *tups_vacuumed, *tups_recently_dead will contain statistics
* computed while copying for the relation. Not all might make sense for every
* AM.
* Output parameters:
* - *xid_cutoff - rel's new relfrozenxid value, may be invalid
* - *multi_cutoff - rel's new relminmxid value, may be invalid
* - *tups_vacuumed - stats, for logging, if appropriate for AM
* - *tups_recently_dead - stats, for logging, if appropriate for AM
*/
static inline void
table_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
Relation OldIndex,
bool use_sort,
TransactionId OldestXmin,
TransactionId FreezeXid,
MultiXactId MultiXactCutoff,
TransactionId *xid_cutoff,
MultiXactId *multi_cutoff,
double *num_tuples,
double *tups_vacuumed,
double *tups_recently_dead)
{
OldHeap->rd_tableam->relation_copy_for_cluster(OldHeap, NewHeap, OldIndex,
use_sort, OldestXmin,
FreezeXid, MultiXactCutoff,
xid_cutoff, multi_cutoff,
num_tuples, tups_vacuumed,
tups_recently_dead);
}