40#define DEFAULT_STATATT_NULL_FRAC Float4GetDatum(0.0)
41#define DEFAULT_STATATT_AVG_WIDTH Int32GetDatum(0)
43#define DEFAULT_STATATT_N_DISTINCT Float4GetDatum(0.0)
58 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
59 errmsg(
"argument \"%s\" must not be null",
60 arginfo[argnum].argname)));
85 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
86 errmsg(
"argument \"%s\" must not be a multidimensional array",
87 arginfo[argnum].argname)));
94 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
95 errmsg(
"argument \"%s\" array must not contain null values",
96 arginfo[argnum].argname)));
114 int argnum1,
int argnum2)
121 int nullarg =
PG_ARGISNULL(argnum1) ? argnum1 : argnum2;
122 int otherarg =
PG_ARGISNULL(argnum1) ? argnum2 : argnum1;
125 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
126 errmsg(
"argument \"%s\" must be specified when argument \"%s\" is specified",
127 arginfo[nullarg].argname,
128 arginfo[otherarg].argname)));
147 Oid table_oid = relId;
157 if (relId != oldRelId &&
OidIsValid(*locked_oid))
169 if (relkind == RELKIND_INDEX ||
170 relkind == RELKIND_PARTITIONED_INDEX)
177 if (relId == oldRelId)
186 if (table_oid == relId &&
OidIsValid(*locked_oid))
188 (
errcode(ERRCODE_UNDEFINED_OBJECT),
189 errmsg(
"index \"%s\" was concurrently dropped",
201 if (table_oid != relId && table_oid != *locked_oid)
203 (
errcode(ERRCODE_UNDEFINED_OBJECT),
204 errmsg(
"index \"%s\" was concurrently created",
210 elog(
ERROR,
"cache lookup failed for OID %u", table_oid);
214 switch (form->relkind)
216 case RELKIND_RELATION:
217 case RELKIND_MATVIEW:
218 case RELKIND_FOREIGN_TABLE:
219 case RELKIND_PARTITIONED_TABLE:
223 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
224 errmsg(
"cannot modify statistics for relation \"%s\"",
229 if (form->relisshared)
231 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
232 errmsg(
"cannot modify statistics for shared relation")));
250 if (relId != oldRelId && table_oid != relId)
253 *locked_oid = table_oid;
267 for (argnum = 0; arginfo[argnum].
argname != NULL; argnum++)
272 (
errmsg(
"unrecognized argument name: \"%s\"", argname)));
283 if (argtype != expectedtype)
286 (
errmsg(
"argument \"%s\" has type %s, expected type %s",
310 if (rel->
rd_rel->relkind != RELKIND_INDEX &&
311 rel->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
317 if (index_exprs ==
NIL)
330 if (rel->
rd_index->indkey.values[
i] == 0)
333 if (indexpr_item == NULL)
334 elog(
ERROR,
"too few entries in indexprs list");
360 for (
int i = 0; arginfo[
i].
argname != NULL;
i++)
371 errmsg(
"variadic arguments must be name/value pairs"),
372 errhint(
"Provide an even number of variadic arguments that can be divided into pairs."));
379 for (
int i = 0;
i < nargs;
i += 2)
386 (
errmsg(
"name at variadic position %d is null",
i + 1)));
390 (
errmsg(
"name at variadic position %d has type %s, expected type %s",
412 arginfo[argnum].argtype))
419 positional_fcinfo->
args[argnum].
isnull =
false;
440 char *atttyptype,
Oid *atttypcoll,
455 (
errcode(ERRCODE_UNDEFINED_COLUMN),
456 errmsg(
"column %d of relation \"%s\" does not exist",
461 if (attr->attisdropped)
463 (
errcode(ERRCODE_UNDEFINED_COLUMN),
464 errmsg(
"column %d of relation \"%s\" does not exist",
477 *atttypid = attr->atttypid;
478 *atttypmod = attr->atttypmod;
479 *atttypcoll = attr->attcollation;
487 *atttypcoll = attr->attcollation;
502 *atttyptype = typcache->
typtype;
503 *eq_opr = typcache->
eq_opr;
504 *lt_opr = typcache->
lt_opr;
510 if (*atttypid == TSVECTOROID)
511 *atttypcoll = DEFAULT_COLLATION_OID;
525 Oid *elemtypid,
Oid *elem_eq_opr)
529 if (atttypid == TSVECTOROID)
535 *elemtypid = TEXTOID;
551 *elem_eq_opr = elemtypcache->
eq_opr;
569 int32 typmod,
bool *ok)
581 (
Node *) &escontext, NULL);
584 fcinfo->args[0].isnull =
false;
586 fcinfo->args[1].isnull =
false;
588 fcinfo->args[2].isnull =
false;
605 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
606 errmsg(
"\"%s\" array must not contain null values", staname)));
638 Datum stanumbers,
bool stanumbers_isnull,
639 Datum stavalues,
bool stavalues_isnull)
642 int first_empty = -1;
650 stakind_attnum = Anum_pg_statistic_stakind1 - 1 + slotidx;
652 if (first_empty < 0 &&
654 first_empty = slotidx;
660 slotidx = first_empty;
664 (
errmsg(
"maximum number of statistics slots exceeded: %d",
667 stakind_attnum = Anum_pg_statistic_stakind1 - 1 + slotidx;
668 staop_attnum = Anum_pg_statistic_staop1 - 1 + slotidx;
669 stacoll_attnum = Anum_pg_statistic_stacoll1 - 1 + slotidx;
674 replaces[stakind_attnum] =
true;
679 replaces[staop_attnum] =
true;
684 replaces[stacoll_attnum] =
true;
686 if (!stanumbers_isnull)
688 values[Anum_pg_statistic_stanumbers1 - 1 + slotidx] = stanumbers;
689 nulls[Anum_pg_statistic_stanumbers1 - 1 + slotidx] =
false;
690 replaces[Anum_pg_statistic_stanumbers1 - 1 + slotidx] =
true;
692 if (!stavalues_isnull)
694 values[Anum_pg_statistic_stavalues1 - 1 + slotidx] = stavalues;
695 nulls[Anum_pg_statistic_stavalues1 - 1 + slotidx] =
false;
696 replaces[Anum_pg_statistic_stavalues1 - 1 + slotidx] =
true;
717 memset(nulls,
true,
sizeof(
bool) * Natts_pg_statistic);
718 memset(replaces,
true,
sizeof(
bool) * Natts_pg_statistic);
722 nulls[Anum_pg_statistic_starelid - 1] =
false;
724 nulls[Anum_pg_statistic_staattnum - 1] =
false;
726 nulls[Anum_pg_statistic_stainherit - 1] =
false;
729 nulls[Anum_pg_statistic_stanullfrac - 1] =
false;
731 nulls[Anum_pg_statistic_stawidth - 1] =
false;
733 nulls[Anum_pg_statistic_stadistinct - 1] =
false;
738 values[Anum_pg_statistic_stakind1 + slotnum - 1] = (
Datum) 0;
739 nulls[Anum_pg_statistic_stakind1 + slotnum - 1] =
false;
741 nulls[Anum_pg_statistic_staop1 + slotnum - 1] =
false;
743 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)