41#define DEFAULT_STATATT_NULL_FRAC Float4GetDatum(0.0)
42#define DEFAULT_STATATT_AVG_WIDTH Int32GetDatum(0)
44#define DEFAULT_STATATT_N_DISTINCT Float4GetDatum(0.0)
59 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
60 errmsg(
"argument \"%s\" must not be null",
61 arginfo[argnum].argname)));
86 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
87 errmsg(
"argument \"%s\" must not be a multidimensional array",
88 arginfo[argnum].argname)));
95 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
96 errmsg(
"argument \"%s\" array must not contain null values",
97 arginfo[argnum].argname)));
115 int argnum1,
int argnum2)
122 int nullarg =
PG_ARGISNULL(argnum1) ? argnum1 : argnum2;
123 int otherarg =
PG_ARGISNULL(argnum1) ? argnum2 : argnum1;
126 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
127 errmsg(
"argument \"%s\" must be specified when argument \"%s\" is specified",
128 arginfo[nullarg].argname,
129 arginfo[otherarg].argname)));
148 Oid table_oid = relId;
158 if (relId != oldRelId &&
OidIsValid(*locked_oid))
170 if (relkind == RELKIND_INDEX ||
171 relkind == RELKIND_PARTITIONED_INDEX)
178 if (relId == oldRelId)
187 if (table_oid == relId &&
OidIsValid(*locked_oid))
189 (
errcode(ERRCODE_UNDEFINED_OBJECT),
190 errmsg(
"index \"%s\" was concurrently dropped",
202 if (table_oid != relId && table_oid != *locked_oid)
204 (
errcode(ERRCODE_UNDEFINED_OBJECT),
205 errmsg(
"index \"%s\" was concurrently created",
211 elog(
ERROR,
"cache lookup failed for OID %u", table_oid);
215 switch (form->relkind)
217 case RELKIND_RELATION:
218 case RELKIND_MATVIEW:
219 case RELKIND_FOREIGN_TABLE:
220 case RELKIND_PARTITIONED_TABLE:
224 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
225 errmsg(
"cannot modify statistics for relation \"%s\"",
230 if (form->relisshared)
232 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
233 errmsg(
"cannot modify statistics for shared relation")));
251 if (relId != oldRelId && table_oid != relId)
254 *locked_oid = table_oid;
268 for (argnum = 0; arginfo[argnum].
argname != NULL; argnum++)
273 (
errmsg(
"unrecognized argument name: \"%s\"", argname)));
284 if (argtype != expectedtype)
287 (
errmsg(
"argument \"%s\" has type %s, expected type %s",
311 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
312 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
318 if (index_exprs ==
NIL)
331 if (rel->
rd_index->indkey.values[
i] == 0)
334 if (indexpr_item == NULL)
335 elog(
ERROR,
"too few entries in indexprs list");
361 for (
int i = 0; arginfo[
i].
argname != NULL;
i++)
372 errmsg(
"variadic arguments must be name/value pairs"),
373 errhint(
"Provide an even number of variadic arguments that can be divided into pairs."));
380 for (
int i = 0;
i < nargs;
i += 2)
387 (
errmsg(
"name at variadic position %d is null",
i + 1)));
391 (
errmsg(
"name at variadic position %d has type %s, expected type %s",
413 arginfo[argnum].argtype))
420 positional_fcinfo->
args[argnum].
isnull =
false;
441 char *atttyptype,
Oid *atttypcoll,
456 (
errcode(ERRCODE_UNDEFINED_COLUMN),
457 errmsg(
"column %d of relation \"%s\" does not exist",
462 if (attr->attisdropped)
464 (
errcode(ERRCODE_UNDEFINED_COLUMN),
465 errmsg(
"column %d of relation \"%s\" does not exist",
478 *atttypid = attr->atttypid;
479 *atttypmod = attr->atttypmod;
480 *atttypcoll = attr->attcollation;
488 *atttypcoll = attr->attcollation;
503 *atttyptype = typcache->
typtype;
504 *eq_opr = typcache->
eq_opr;
505 *lt_opr = typcache->
lt_opr;
511 if (*atttypid == TSVECTOROID)
512 *atttypcoll = DEFAULT_COLLATION_OID;
526 Oid *elemtypid,
Oid *elem_eq_opr)
530 if (atttypid == TSVECTOROID)
536 *elemtypid = TEXTOID;
552 *elem_eq_opr = elemtypcache->
eq_opr;
570 int32 typmod,
bool *ok)
582 (
Node *) &escontext, NULL);
585 fcinfo->args[0].isnull =
false;
587 fcinfo->args[1].isnull =
false;
589 fcinfo->args[2].isnull =
false;
606 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
607 errmsg(
"\"%s\" array must not contain null values", staname)));
639 Datum stanumbers,
bool stanumbers_isnull,
640 Datum stavalues,
bool stavalues_isnull)
643 int first_empty = -1;
651 stakind_attnum = Anum_pg_statistic_stakind1 - 1 + slotidx;
653 if (first_empty < 0 &&
655 first_empty = slotidx;
661 slotidx = first_empty;
665 (
errmsg(
"maximum number of statistics slots exceeded: %d",
668 stakind_attnum = Anum_pg_statistic_stakind1 - 1 + slotidx;
669 staop_attnum = Anum_pg_statistic_staop1 - 1 + slotidx;
670 stacoll_attnum = Anum_pg_statistic_stacoll1 - 1 + slotidx;
675 replaces[stakind_attnum] =
true;
680 replaces[staop_attnum] =
true;
685 replaces[stacoll_attnum] =
true;
687 if (!stanumbers_isnull)
689 values[Anum_pg_statistic_stanumbers1 - 1 + slotidx] = stanumbers;
690 nulls[Anum_pg_statistic_stanumbers1 - 1 + slotidx] =
false;
691 replaces[Anum_pg_statistic_stanumbers1 - 1 + slotidx] =
true;
693 if (!stavalues_isnull)
695 values[Anum_pg_statistic_stavalues1 - 1 + slotidx] = stavalues;
696 nulls[Anum_pg_statistic_stavalues1 - 1 + slotidx] =
false;
697 replaces[Anum_pg_statistic_stavalues1 - 1 + slotidx] =
true;
718 memset(nulls,
true,
sizeof(
bool) * Natts_pg_statistic);
719 memset(replaces,
true,
sizeof(
bool) * Natts_pg_statistic);
723 nulls[Anum_pg_statistic_starelid - 1] =
false;
725 nulls[Anum_pg_statistic_staattnum - 1] =
false;
727 nulls[Anum_pg_statistic_stainherit - 1] =
false;
730 nulls[Anum_pg_statistic_stanullfrac - 1] =
false;
732 nulls[Anum_pg_statistic_stawidth - 1] =
false;
734 nulls[Anum_pg_statistic_stadistinct - 1] =
false;
739 values[Anum_pg_statistic_stakind1 + slotnum - 1] = (
Datum) 0;
740 nulls[Anum_pg_statistic_stakind1 + slotnum - 1] =
false;
742 nulls[Anum_pg_statistic_staop1 + slotnum - 1] =
false;
744 nulls[Anum_pg_statistic_stacoll1 + slotnum - 1] =
false;
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
#define DatumGetArrayTypeP(X)
bool array_contains_nulls(const ArrayType *array)
Datum array_in(PG_FUNCTION_ARGS)
static Datum values[MAXATTR]
#define TextDatumGetCString(d)
#define OidIsValid(objectId)
int errhint(const char *fmt,...)
void ThrowErrorData(ErrorData *edata)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
#define PG_GETARG_DATUM(n)
#define LOCAL_FCINFO(name, nargs)
#define FunctionCallInvoke(fcinfo)
int extract_variadic_args(FunctionCallInfo fcinfo, int variadic_start, bool convert_unknown, Datum **args, Oid **types, bool **nulls)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
Oid IndexGetRelation(Oid indexId, bool missing_ok)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
#define ShareUpdateExclusiveLock
Oid get_multirange_range(Oid multirangeOid)
char get_rel_relkind(Oid relid)
Oid get_base_element_type(Oid typid)
bool type_is_multirange(Oid typid)
void pfree(void *pointer)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
ObjectType get_relkind_objtype(char relkind)
FormData_pg_attribute * Form_pg_attribute
int errdetail_relkind_not_supported(char relkind)
FormData_pg_class * Form_pg_class
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
#define STATISTIC_NUM_SLOTS
int pg_strcasecmp(const char *s1, const char *s2)
static Oid DatumGetObjectId(Datum X)
static Datum Int16GetDatum(int16 X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static int16 DatumGetInt16(Datum X)
#define RelationGetRelationName(relation)
List * RelationGetIndexExpressions(Relation relation)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
#define DEFAULT_STATATT_NULL_FRAC
bool statatt_get_elem_type(Oid atttypid, char atttyptype, Oid *elemtypid, Oid *elem_eq_opr)
Datum statatt_build_stavalues(const char *staname, FmgrInfo *array_in, Datum d, Oid typid, int32 typmod, bool *ok)
bool stats_fill_fcinfo_from_arg_pairs(FunctionCallInfo pairs_fcinfo, FunctionCallInfo positional_fcinfo, struct StatsArgInfo *arginfo)
static int get_arg_by_name(const char *argname, struct StatsArgInfo *arginfo)
void RangeVarCallbackForStats(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
void statatt_init_empty_tuple(Oid reloid, int16 attnum, bool inherited, Datum *values, bool *nulls, bool *replaces)
#define DEFAULT_STATATT_AVG_WIDTH
static bool stats_check_arg_type(const char *argname, Oid argtype, Oid expectedtype)
bool stats_check_arg_array(FunctionCallInfo fcinfo, struct StatsArgInfo *arginfo, int argnum)
void statatt_get_type(Oid reloid, AttrNumber attnum, Oid *atttypid, int32 *atttypmod, char *atttyptype, Oid *atttypcoll, Oid *eq_opr, Oid *lt_opr)
void stats_check_required_arg(FunctionCallInfo fcinfo, struct StatsArgInfo *arginfo, int argnum)
static Node * statatt_get_index_expr(Relation rel, int attnum)
#define DEFAULT_STATATT_N_DISTINCT
void statatt_set_slot(Datum *values, bool *nulls, bool *replaces, int16 stakind, Oid staop, Oid stacoll, Datum stanumbers, bool stanumbers_isnull, Datum stavalues, bool stavalues_isnull)
bool stats_check_arg_pair(FunctionCallInfo fcinfo, struct StatsArgInfo *arginfo, int argnum1, int argnum2)
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)