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

Add functions pg_set_attribute_stats() and pg_clear_attribute_stats().

Enable manipulation of attribute statistics. Only superficial
validation is performed, so it's possible to add nonsense, and it's up
to the planner (or other users of statistics) to behave reasonably in
that case.

Bump catalog version.

Author: Corey Huinker
Discussion: https://postgr.es/m/CADkLM=eErgzn7ECDpwFcptJKOk9SxZEk5Pot4d94eVTZsvj3gw@mail.gmail.com
This commit is contained in:
Jeff Davis
2024-10-22 15:06:55 -07:00
parent dbe6bd4343
commit ce207d2a79
11 changed files with 2263 additions and 2 deletions

View File

@@ -40,6 +40,79 @@ stats_check_required_arg(FunctionCallInfo fcinfo,
arginfo[argnum].argname)));
}
/*
* Check that argument is either NULL or a one dimensional array with no
* NULLs.
*
* If a problem is found, emit at elevel, and return false. Otherwise return
* true.
*/
bool
stats_check_arg_array(FunctionCallInfo fcinfo,
struct StatsArgInfo *arginfo,
int argnum, int elevel)
{
ArrayType *arr;
if (PG_ARGISNULL(argnum))
return true;
arr = DatumGetArrayTypeP(PG_GETARG_DATUM(argnum));
if (ARR_NDIM(arr) != 1)
{
ereport(elevel,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("\"%s\" cannot be a multidimensional array",
arginfo[argnum].argname)));
return false;
}
if (array_contains_nulls(arr))
{
ereport(elevel,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("\"%s\" array cannot contain NULL values",
arginfo[argnum].argname)));
return false;
}
return true;
}
/*
* Enforce parameter pairs that must be specified together (or not at all) for
* a particular stakind, such as most_common_vals and most_common_freqs for
* STATISTIC_KIND_MCV.
*
* If a problem is found, emit at elevel, and return false. Otherwise return
* true.
*/
bool
stats_check_arg_pair(FunctionCallInfo fcinfo,
struct StatsArgInfo *arginfo,
int argnum1, int argnum2, int elevel)
{
if (PG_ARGISNULL(argnum1) && PG_ARGISNULL(argnum2))
return true;
if (PG_ARGISNULL(argnum1) || PG_ARGISNULL(argnum2))
{
int nullarg = PG_ARGISNULL(argnum1) ? argnum1 : argnum2;
int otherarg = PG_ARGISNULL(argnum1) ? argnum2 : argnum1;
ereport(elevel,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("\"%s\" must be specified when \"%s\" is specified",
arginfo[nullarg].argname,
arginfo[otherarg].argname)));
return false;
}
return true;
}
/*
* Lock relation in ShareUpdateExclusive mode, check privileges, and close the
* relation (but retain the lock).