mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
Add relallfrozen to pg_class
Add relallfrozen, an estimate of the number of pages marked all-frozen in the visibility map. pg_class already has relallvisible, an estimate of the number of pages in the relation marked all-visible in the visibility map. This is used primarily for planning. relallfrozen, together with relallvisible, is useful for estimating the outstanding number of all-visible but not all-frozen pages in the relation for the purposes of scheduling manual VACUUMs and tuning vacuum freeze parameters. A future commit will use relallfrozen to trigger more frequent vacuums on insert-focused workloads with significant volume of frozen data. Bump catalog version Author: Melanie Plageman <melanieplageman@gmail.com> Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Reviewed-by: Robert Treat <rob@xzilla.net> Reviewed-by: Corey Huinker <corey.huinker@gmail.com> Reviewed-by: Greg Sabino Mullane <htamfids@gmail.com> Discussion: https://postgr.es/m/flat/CAAKRu_aj-P7YyBz_cPNwztz6ohP%2BvWis%3Diz3YcomkB3NpYA--w%40mail.gmail.com
This commit is contained in:
@@ -36,6 +36,7 @@ enum relation_stats_argnum
|
||||
RELPAGES_ARG,
|
||||
RELTUPLES_ARG,
|
||||
RELALLVISIBLE_ARG,
|
||||
RELALLFROZEN_ARG,
|
||||
NUM_RELATION_STATS_ARGS
|
||||
};
|
||||
|
||||
@@ -45,6 +46,7 @@ static struct StatsArgInfo relarginfo[] =
|
||||
[RELPAGES_ARG] = {"relpages", INT4OID},
|
||||
[RELTUPLES_ARG] = {"reltuples", FLOAT4OID},
|
||||
[RELALLVISIBLE_ARG] = {"relallvisible", INT4OID},
|
||||
[RELALLFROZEN_ARG] = {"relallfrozen", INT4OID},
|
||||
[NUM_RELATION_STATS_ARGS] = {0}
|
||||
};
|
||||
|
||||
@@ -65,11 +67,13 @@ relation_statistics_update(FunctionCallInfo fcinfo)
|
||||
bool update_reltuples = false;
|
||||
BlockNumber relallvisible = 0;
|
||||
bool update_relallvisible = false;
|
||||
BlockNumber relallfrozen = 0;
|
||||
bool update_relallfrozen = false;
|
||||
HeapTuple ctup;
|
||||
Form_pg_class pgcform;
|
||||
int replaces[3] = {0};
|
||||
Datum values[3] = {0};
|
||||
bool nulls[3] = {0};
|
||||
int replaces[4] = {0};
|
||||
Datum values[4] = {0};
|
||||
bool nulls[4] = {0};
|
||||
int nreplaces = 0;
|
||||
|
||||
if (!PG_ARGISNULL(RELPAGES_ARG))
|
||||
@@ -98,6 +102,12 @@ relation_statistics_update(FunctionCallInfo fcinfo)
|
||||
update_relallvisible = true;
|
||||
}
|
||||
|
||||
if (!PG_ARGISNULL(RELALLFROZEN_ARG))
|
||||
{
|
||||
relallfrozen = PG_GETARG_UINT32(RELALLFROZEN_ARG);
|
||||
update_relallfrozen = true;
|
||||
}
|
||||
|
||||
stats_check_required_arg(fcinfo, relarginfo, RELATION_ARG);
|
||||
reloid = PG_GETARG_OID(RELATION_ARG);
|
||||
|
||||
@@ -148,6 +158,13 @@ relation_statistics_update(FunctionCallInfo fcinfo)
|
||||
nreplaces++;
|
||||
}
|
||||
|
||||
if (update_relallfrozen && relallfrozen != pgcform->relallfrozen)
|
||||
{
|
||||
replaces[nreplaces] = Anum_pg_class_relallfrozen;
|
||||
values[nreplaces] = UInt32GetDatum(relallfrozen);
|
||||
nreplaces++;
|
||||
}
|
||||
|
||||
if (nreplaces > 0)
|
||||
{
|
||||
TupleDesc tupdesc = RelationGetDescr(crel);
|
||||
@@ -176,9 +193,9 @@ relation_statistics_update(FunctionCallInfo fcinfo)
|
||||
Datum
|
||||
pg_clear_relation_stats(PG_FUNCTION_ARGS)
|
||||
{
|
||||
LOCAL_FCINFO(newfcinfo, 4);
|
||||
LOCAL_FCINFO(newfcinfo, 5);
|
||||
|
||||
InitFunctionCallInfoData(*newfcinfo, NULL, 4, InvalidOid, NULL, NULL);
|
||||
InitFunctionCallInfoData(*newfcinfo, NULL, 5, InvalidOid, NULL, NULL);
|
||||
|
||||
newfcinfo->args[0].value = PG_GETARG_OID(0);
|
||||
newfcinfo->args[0].isnull = PG_ARGISNULL(0);
|
||||
@@ -188,6 +205,8 @@ pg_clear_relation_stats(PG_FUNCTION_ARGS)
|
||||
newfcinfo->args[2].isnull = false;
|
||||
newfcinfo->args[3].value = UInt32GetDatum(0);
|
||||
newfcinfo->args[3].isnull = false;
|
||||
newfcinfo->args[4].value = UInt32GetDatum(0);
|
||||
newfcinfo->args[4].isnull = false;
|
||||
|
||||
relation_statistics_update(newfcinfo);
|
||||
PG_RETURN_VOID();
|
||||
|
||||
Reference in New Issue
Block a user