23 #include "utils/fmgroids.h"
24 #include "utils/fmgrprotos.h"
27 #define DEFAULT_RELPAGES Int32GetDatum(0)
28 #define DEFAULT_RELTUPLES Float4GetDatum(-1.0)
29 #define DEFAULT_RELALLVISIBLE Int32GetDatum(0)
66 bool update_relpages =
false;
68 bool update_reltuples =
false;
70 bool update_relallvisible =
false;
85 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
86 errmsg(
"relpages cannot be < -1")));
90 update_relpages =
true;
100 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
101 errmsg(
"reltuples cannot be < -1.0")));
105 update_reltuples =
true;
112 if (relallvisible < 0)
115 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
116 errmsg(
"relallvisible cannot be < 0")));
120 update_relallvisible =
true;
128 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
129 errmsg(
"recovery is in progress"),
130 errhint(
"Statistics cannot be modified during recovery.")));
145 void *inplace_state = NULL;
151 &ctup, &inplace_state);
153 elog(
ERROR,
"pg_class entry for relid %u vanished while updating statistics",
157 if (update_relpages && pgcform->relpages != relpages)
159 pgcform->relpages = relpages;
162 if (update_reltuples && pgcform->reltuples != reltuples)
164 pgcform->reltuples = reltuples;
167 if (update_relallvisible && pgcform->relallvisible != relallvisible)
169 pgcform->relallvisible = relallvisible;
185 int replaces[3] = {0};
194 (
errcode(ERRCODE_OBJECT_IN_USE),
195 errmsg(
"pg_class entry for relid %u not found", reloid)));
201 if (update_relpages && relpages != pgcform->relpages)
203 replaces[nreplaces] = Anum_pg_class_relpages;
208 if (update_reltuples && reltuples != pgcform->reltuples)
210 replaces[nreplaces] = Anum_pg_class_reltuples;
215 if (update_relallvisible && relallvisible != pgcform->relallvisible)
217 replaces[nreplaces] = Anum_pg_class_relallvisible;
267 newfcinfo->args[1].isnull =
false;
269 newfcinfo->args[2].isnull =
false;
271 newfcinfo->args[3].isnull =
false;
static Datum values[MAXATTR]
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
#define LOCAL_FCINFO(name, nargs)
#define PG_GETARG_INT32(n)
#define PG_GETARG_FLOAT4(n)
#define PG_RETURN_BOOL(x)
void systable_inplace_update_cancel(void *state)
void systable_inplace_update_begin(Relation relation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, const ScanKeyData *key, HeapTuple *oldtupcopy, void **state)
void systable_inplace_update_finish(void *state, HeapTuple tuple)
HeapTuple heap_modify_tuple_by_cols(HeapTuple tuple, TupleDesc tupleDesc, int nCols, const int *replCols, const Datum *replValues, const bool *replIsnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
FormData_pg_class * Form_pg_class
static Datum Float4GetDatum(float4 X)
static Datum ObjectIdGetDatum(Oid X)
static Datum Int32GetDatum(int32 X)
#define RelationGetDescr(relation)
static struct StatsArgInfo relarginfo[]
@ NUM_RELATION_STATS_ARGS
#define DEFAULT_RELTUPLES
Datum pg_restore_relation_stats(PG_FUNCTION_ARGS)
#define DEFAULT_RELALLVISIBLE
static bool relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
Datum pg_set_relation_stats(PG_FUNCTION_ARGS)
Datum pg_clear_relation_stats(PG_FUNCTION_ARGS)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
void stats_check_required_arg(FunctionCallInfo fcinfo, struct StatsArgInfo *arginfo, int argnum)
bool stats_fill_fcinfo_from_arg_pairs(FunctionCallInfo pairs_fcinfo, FunctionCallInfo positional_fcinfo, struct StatsArgInfo *arginfo, int elevel)
void stats_lock_check_privileges(Oid reloid)
#define BTEqualStrategyNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
void CommandCounterIncrement(void)
bool RecoveryInProgress(void)