/* *Ensurethatagivenargumentisnotnull.
*/ void
stats_check_required_arg(FunctionCallInfo fcinfo, struct StatsArgInfo *arginfo, int argnum)
{ if (PG_ARGISNULL(argnum))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument \"%s\" must not be null",
arginfo[argnum].argname)));
}
if (ARR_NDIM(arr) != 1)
{
ereport(WARNING,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument \"%s\" must not be a multidimensional array",
arginfo[argnum].argname))); returnfalse;
}
if (array_contains_nulls(arr))
{
ereport(WARNING,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument \"%s\" array must not contain null values",
arginfo[argnum].argname))); returnfalse;
}
returntrue;
}
/* *Enforceparameterpairsthatmustbespecifiedtogether(ornotatall)for *aparticularstakind,suchasmost_common_valsandmost_common_freqsfor *STATISTIC_KIND_MCV. * *Ifaproblemisfound,emitaWARNING,andreturnfalse.Otherwisereturn *true.
*/ bool
stats_check_arg_pair(FunctionCallInfo fcinfo, struct StatsArgInfo *arginfo, int argnum1, int argnum2)
{ if (PG_ARGISNULL(argnum1) && PG_ARGISNULL(argnum2)) returntrue;
if (PG_ARGISNULL(argnum1) || PG_ARGISNULL(argnum2))
{ int nullarg = PG_ARGISNULL(argnum1) ? argnum1 : argnum2; int otherarg = PG_ARGISNULL(argnum1) ? argnum2 : argnum1;
ereport(WARNING,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument \"%s\" must be specified when argument \"%s\" is specified",
arginfo[nullarg].argname,
arginfo[otherarg].argname)));
returnfalse;
}
returntrue;
}
/* *Arolehasprivilegestosetstatisticsontherelationifanyofthe *followingaretrue: *-theroleownsthecurrentdatabaseandtherelationisnotshared *-therolehastheMAINTAINprivilegeontherelation
*/ void
RangeVarCallbackForStats(const RangeVar *relation,
Oid relId, Oid oldRelId, void *arg)
{
Oid *locked_oid = (Oid *) arg;
Oid table_oid = relId;
HeapTuple tuple;
Form_pg_class form; char relkind;
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(table_oid)); if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for OID %u", table_oid);
form = (Form_pg_class) GETSTRUCT(tuple);
/* the relkinds that can be used with ANALYZE */ switch (form->relkind)
{ case RELKIND_RELATION: case RELKIND_MATVIEW: case RELKIND_FOREIGN_TABLE: case RELKIND_PARTITIONED_TABLE: break; default:
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot modify statistics for relation \"%s\"",
NameStr(form->relname)),
errdetail_relkind_not_supported(form->relkind)));
}
if (form->relisshared)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot modify statistics for shared relation")));
/* *Ensurethatagivenargumentmatchedtheexpectedtype.
*/ staticbool
stats_check_arg_type(constchar *argname, Oid argtype, Oid expectedtype)
{ if (argtype != expectedtype)
{
ereport(WARNING,
(errmsg("argument \"%s\" has type %s, expected type %s",
argname, format_type_be(argtype),
format_type_be(expectedtype)))); returnfalse;
}
returntrue;
}
/* *Translatevariadicargumentpairsfrom'pairs_fcinfo'intoa *'positional_fcinfo'appropriateforcallingrelation_statistics_update()or *attribute_statistics_update()withpositionalarguments. * *Callershouldhavealreadyinitializedpositional_fcinfowithasize *appropriateforcallingtheintendedpositionalfunction,andarginfo *shouldalsomatchtheintendedpositionalfunction.
*/ bool
stats_fill_fcinfo_from_arg_pairs(FunctionCallInfo pairs_fcinfo,
FunctionCallInfo positional_fcinfo, struct StatsArgInfo *arginfo)
{
Datum *args; bool *argnulls;
Oid *types; int nargs; bool result = true;
if (nargs % 2 != 0)
ereport(ERROR,
errmsg("variadic arguments must be name/value pairs"),
errhint("Provide an even number of variadic arguments that can be divided into pairs."));
/* *Foreachargumentname/valuepair,findcorrespondingpositional *argumentfortheargumentname,andassigntheargumentvalueto *positional_fcinfo.
*/ for (int i = 0; i < nargs; i += 2)
{ int argnum; char *argname;
if (argnulls[i])
ereport(ERROR,
(errmsg("name at variadic position %d is null", i + 1)));
if (types[i] != TEXTOID)
ereport(ERROR,
(errmsg("name at variadic position %d has type %s, expected type %s",
i + 1, format_type_be(types[i]),
format_type_be(TEXTOID))));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.