PostgreSQL Source Code git master
stat_utils.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 * stat_utils.c
3 *
4 * PostgreSQL statistics manipulation utilities.
5 *
6 * Code supporting the direct manipulation of statistics.
7 *
8 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
10 *
11 * IDENTIFICATION
12 * src/backend/statistics/stat_utils.c
13 *
14 *-------------------------------------------------------------------------
15 */
16
17#include "postgres.h"
18
19#include "access/htup_details.h"
20#include "access/relation.h"
21#include "catalog/index.h"
22#include "catalog/namespace.h"
23#include "catalog/pg_class.h"
25#include "catalog/pg_database.h"
27#include "funcapi.h"
28#include "miscadmin.h"
29#include "nodes/nodeFuncs.h"
31#include "storage/lmgr.h"
32#include "utils/acl.h"
33#include "utils/array.h"
34#include "utils/builtins.h"
35#include "utils/lsyscache.h"
36#include "utils/rel.h"
37#include "utils/syscache.h"
38
39/* Default values assigned to new pg_statistic tuples. */
40#define DEFAULT_STATATT_NULL_FRAC Float4GetDatum(0.0) /* stanullfrac */
41#define DEFAULT_STATATT_AVG_WIDTH Int32GetDatum(0) /* stawidth, same as
42 * unknown */
43#define DEFAULT_STATATT_N_DISTINCT Float4GetDatum(0.0) /* stadistinct, same as
44 * unknown */
45
47
48/*
49 * Ensure that a given argument is not null.
50 */
51void
53 struct StatsArgInfo *arginfo,
54 int argnum)
55{
56 if (PG_ARGISNULL(argnum))
58 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
59 errmsg("argument \"%s\" must not be null",
60 arginfo[argnum].argname)));
61}
62
63/*
64 * Check that argument is either NULL or a one dimensional array with no
65 * NULLs.
66 *
67 * If a problem is found, emit a WARNING, and return false. Otherwise return
68 * true.
69 */
70bool
72 struct StatsArgInfo *arginfo,
73 int argnum)
74{
75 ArrayType *arr;
76
77 if (PG_ARGISNULL(argnum))
78 return true;
79
81
82 if (ARR_NDIM(arr) != 1)
83 {
85 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
86 errmsg("argument \"%s\" must not be a multidimensional array",
87 arginfo[argnum].argname)));
88 return false;
89 }
90
91 if (array_contains_nulls(arr))
92 {
94 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
95 errmsg("argument \"%s\" array must not contain null values",
96 arginfo[argnum].argname)));
97 return false;
98 }
99
100 return true;
101}
102
103/*
104 * Enforce parameter pairs that must be specified together (or not at all) for
105 * a particular stakind, such as most_common_vals and most_common_freqs for
106 * STATISTIC_KIND_MCV.
107 *
108 * If a problem is found, emit a WARNING, and return false. Otherwise return
109 * true.
110 */
111bool
113 struct StatsArgInfo *arginfo,
114 int argnum1, int argnum2)
115{
116 if (PG_ARGISNULL(argnum1) && PG_ARGISNULL(argnum2))
117 return true;
118
119 if (PG_ARGISNULL(argnum1) || PG_ARGISNULL(argnum2))
120 {
121 int nullarg = PG_ARGISNULL(argnum1) ? argnum1 : argnum2;
122 int otherarg = PG_ARGISNULL(argnum1) ? argnum2 : argnum1;
123
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)));
129
130 return false;
131 }
132
133 return true;
134}
135
136/*
137 * A role has privileges to set statistics on the relation if any of the
138 * following are true:
139 * - the role owns the current database and the relation is not shared
140 * - the role has the MAINTAIN privilege on the relation
141 */
142void
143RangeVarCallbackForStats(const RangeVar *relation,
144 Oid relId, Oid oldRelId, void *arg)
145{
146 Oid *locked_oid = (Oid *) arg;
147 Oid table_oid = relId;
148 HeapTuple tuple;
149 Form_pg_class form;
150 char relkind;
151
152 /*
153 * If we previously locked some other index's heap, and the name we're
154 * looking up no longer refers to that relation, release the now-useless
155 * lock.
156 */
157 if (relId != oldRelId && OidIsValid(*locked_oid))
158 {
160 *locked_oid = InvalidOid;
161 }
162
163 /* If the relation does not exist, there's nothing more to do. */
164 if (!OidIsValid(relId))
165 return;
166
167 /* If the relation does exist, check whether it's an index. */
168 relkind = get_rel_relkind(relId);
169 if (relkind == RELKIND_INDEX ||
170 relkind == RELKIND_PARTITIONED_INDEX)
171 table_oid = IndexGetRelation(relId, false);
172
173 /*
174 * If retrying yields the same OID, there are a couple of extremely
175 * unlikely scenarios we need to handle.
176 */
177 if (relId == oldRelId)
178 {
179 /*
180 * If a previous lookup found an index, but the current lookup did
181 * not, the index was dropped and the OID was reused for something
182 * else between lookups. In theory, we could simply drop our lock on
183 * the index's parent table and proceed, but in the interest of
184 * avoiding complexity, we just error.
185 */
186 if (table_oid == relId && OidIsValid(*locked_oid))
188 (errcode(ERRCODE_UNDEFINED_OBJECT),
189 errmsg("index \"%s\" was concurrently dropped",
190 relation->relname)));
191
192 /*
193 * If the current lookup found an index but a previous lookup either
194 * did not find an index or found one with a different parent
195 * relation, the relation was dropped and the OID was reused for an
196 * index between lookups. RangeVarGetRelidExtended() will have
197 * already locked the index at this point, so we can't just lock the
198 * newly discovered parent table OID without risking deadlock. As
199 * above, we just error in this case.
200 */
201 if (table_oid != relId && table_oid != *locked_oid)
203 (errcode(ERRCODE_UNDEFINED_OBJECT),
204 errmsg("index \"%s\" was concurrently created",
205 relation->relname)));
206 }
207
208 tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(table_oid));
209 if (!HeapTupleIsValid(tuple))
210 elog(ERROR, "cache lookup failed for OID %u", table_oid);
211 form = (Form_pg_class) GETSTRUCT(tuple);
212
213 /* the relkinds that can be used with ANALYZE */
214 switch (form->relkind)
215 {
216 case RELKIND_RELATION:
217 case RELKIND_MATVIEW:
218 case RELKIND_FOREIGN_TABLE:
219 case RELKIND_PARTITIONED_TABLE:
220 break;
221 default:
223 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
224 errmsg("cannot modify statistics for relation \"%s\"",
225 NameStr(form->relname)),
226 errdetail_relkind_not_supported(form->relkind)));
227 }
228
229 if (form->relisshared)
231 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
232 errmsg("cannot modify statistics for shared relation")));
233
234 /* Check permissions */
235 if (!object_ownercheck(DatabaseRelationId, MyDatabaseId, GetUserId()))
236 {
237 AclResult aclresult = pg_class_aclcheck(table_oid,
238 GetUserId(),
240
241 if (aclresult != ACLCHECK_OK)
242 aclcheck_error(aclresult,
243 get_relkind_objtype(form->relkind),
244 NameStr(form->relname));
245 }
246
247 ReleaseSysCache(tuple);
248
249 /* Lock heap before index to avoid deadlock. */
250 if (relId != oldRelId && table_oid != relId)
251 {
253 *locked_oid = table_oid;
254 }
255}
256
257
258/*
259 * Find the argument number for the given argument name, returning -1 if not
260 * found.
261 */
262static int
263get_arg_by_name(const char *argname, struct StatsArgInfo *arginfo)
264{
265 int argnum;
266
267 for (argnum = 0; arginfo[argnum].argname != NULL; argnum++)
268 if (pg_strcasecmp(argname, arginfo[argnum].argname) == 0)
269 return argnum;
270
272 (errmsg("unrecognized argument name: \"%s\"", argname)));
273
274 return -1;
275}
276
277/*
278 * Ensure that a given argument matched the expected type.
279 */
280static bool
281stats_check_arg_type(const char *argname, Oid argtype, Oid expectedtype)
282{
283 if (argtype != expectedtype)
284 {
286 (errmsg("argument \"%s\" has type %s, expected type %s",
287 argname, format_type_be(argtype),
288 format_type_be(expectedtype))));
289 return false;
290 }
291
292 return true;
293}
294
295/*
296 * Check if attribute of an index is an expression, then retrieve the
297 * expression if is it the case.
298 *
299 * If the attnum specified is known to be an expression, then we must
300 * walk the list attributes up to the specified attnum to get the right
301 * expression.
302 */
303static Node *
305{
306 List *index_exprs;
307 ListCell *indexpr_item;
308
309 /* relation is not an index */
310 if (rel->rd_rel->relkind != RELKIND_INDEX &&
311 rel->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
312 return NULL;
313
314 index_exprs = RelationGetIndexExpressions(rel);
315
316 /* index has no expressions to give */
317 if (index_exprs == NIL)
318 return NULL;
319
320 /*
321 * The index's attnum points directly to a relation attnum, hence it is
322 * not an expression attribute.
323 */
324 if (rel->rd_index->indkey.values[attnum - 1] != 0)
325 return NULL;
326
327 indexpr_item = list_head(rel->rd_indexprs);
328
329 for (int i = 0; i < attnum - 1; i++)
330 if (rel->rd_index->indkey.values[i] == 0)
331 indexpr_item = lnext(rel->rd_indexprs, indexpr_item);
332
333 if (indexpr_item == NULL) /* shouldn't happen */
334 elog(ERROR, "too few entries in indexprs list");
335
336 return (Node *) lfirst(indexpr_item);
337}
338
339/*
340 * Translate variadic argument pairs from 'pairs_fcinfo' into a
341 * 'positional_fcinfo' appropriate for calling relation_statistics_update() or
342 * attribute_statistics_update() with positional arguments.
343 *
344 * Caller should have already initialized positional_fcinfo with a size
345 * appropriate for calling the intended positional function, and arginfo
346 * should also match the intended positional function.
347 */
348bool
350 FunctionCallInfo positional_fcinfo,
351 struct StatsArgInfo *arginfo)
352{
353 Datum *args;
354 bool *argnulls;
355 Oid *types;
356 int nargs;
357 bool result = true;
358
359 /* clear positional args */
360 for (int i = 0; arginfo[i].argname != NULL; i++)
361 {
362 positional_fcinfo->args[i].value = (Datum) 0;
363 positional_fcinfo->args[i].isnull = true;
364 }
365
366 nargs = extract_variadic_args(pairs_fcinfo, 0, true,
367 &args, &types, &argnulls);
368
369 if (nargs % 2 != 0)
371 errmsg("variadic arguments must be name/value pairs"),
372 errhint("Provide an even number of variadic arguments that can be divided into pairs."));
373
374 /*
375 * For each argument name/value pair, find corresponding positional
376 * argument for the argument name, and assign the argument value to
377 * positional_fcinfo.
378 */
379 for (int i = 0; i < nargs; i += 2)
380 {
381 int argnum;
382 char *argname;
383
384 if (argnulls[i])
386 (errmsg("name at variadic position %d is null", i + 1)));
387
388 if (types[i] != TEXTOID)
390 (errmsg("name at variadic position %d has type %s, expected type %s",
391 i + 1, format_type_be(types[i]),
392 format_type_be(TEXTOID))));
393
394 if (argnulls[i + 1])
395 continue;
396
397 argname = TextDatumGetCString(args[i]);
398
399 /*
400 * The 'version' argument is a special case, not handled by arginfo
401 * because it's not a valid positional argument.
402 *
403 * For now, 'version' is accepted but ignored. In the future it can be
404 * used to interpret older statistics properly.
405 */
406 if (pg_strcasecmp(argname, "version") == 0)
407 continue;
408
409 argnum = get_arg_by_name(argname, arginfo);
410
411 if (argnum < 0 || !stats_check_arg_type(argname, types[i + 1],
412 arginfo[argnum].argtype))
413 {
414 result = false;
415 continue;
416 }
417
418 positional_fcinfo->args[argnum].value = args[i + 1];
419 positional_fcinfo->args[argnum].isnull = false;
420 }
421
422 return result;
423}
424
425/*
426 * Derive type information from a relation attribute.
427 *
428 * This is needed for setting most slot statistics for all data types.
429 *
430 * This duplicates the logic in examine_attribute() but it will not skip the
431 * attribute if the attstattarget is 0.
432 *
433 * This information, retrieved from pg_attribute and pg_type with some
434 * specific handling for index expressions, is a prerequisite to calling
435 * any of the other statatt_*() functions.
436 */
437void
439 Oid *atttypid, int32 *atttypmod,
440 char *atttyptype, Oid *atttypcoll,
441 Oid *eq_opr, Oid *lt_opr)
442{
445 HeapTuple atup;
446 Node *expr;
447 TypeCacheEntry *typcache;
448
449 atup = SearchSysCache2(ATTNUM, ObjectIdGetDatum(reloid),
451
452 /* Attribute not found */
453 if (!HeapTupleIsValid(atup))
455 (errcode(ERRCODE_UNDEFINED_COLUMN),
456 errmsg("column %d of relation \"%s\" does not exist",
458
459 attr = (Form_pg_attribute) GETSTRUCT(atup);
460
461 if (attr->attisdropped)
463 (errcode(ERRCODE_UNDEFINED_COLUMN),
464 errmsg("column %d of relation \"%s\" does not exist",
466
467 expr = statatt_get_index_expr(rel, attr->attnum);
468
469 /*
470 * When analyzing an expression index, believe the expression tree's type
471 * not the column datatype --- the latter might be the opckeytype storage
472 * type of the opclass, which is not interesting for our purposes. This
473 * mimics the behavior of examine_attribute().
474 */
475 if (expr == NULL)
476 {
477 *atttypid = attr->atttypid;
478 *atttypmod = attr->atttypmod;
479 *atttypcoll = attr->attcollation;
480 }
481 else
482 {
483 *atttypid = exprType(expr);
484 *atttypmod = exprTypmod(expr);
485
486 if (OidIsValid(attr->attcollation))
487 *atttypcoll = attr->attcollation;
488 else
489 *atttypcoll = exprCollation(expr);
490 }
491 ReleaseSysCache(atup);
492
493 /*
494 * If it's a multirange, step down to the range type, as is done by
495 * multirange_typanalyze().
496 */
497 if (type_is_multirange(*atttypid))
498 *atttypid = get_multirange_range(*atttypid);
499
500 /* finds the right operators even if atttypid is a domain */
501 typcache = lookup_type_cache(*atttypid, TYPECACHE_LT_OPR | TYPECACHE_EQ_OPR);
502 *atttyptype = typcache->typtype;
503 *eq_opr = typcache->eq_opr;
504 *lt_opr = typcache->lt_opr;
505
506 /*
507 * Special case: collation for tsvector is DEFAULT_COLLATION_OID. See
508 * compute_tsvector_stats().
509 */
510 if (*atttypid == TSVECTOROID)
511 *atttypcoll = DEFAULT_COLLATION_OID;
512
514}
515
516/*
517 * Derive element type information from the attribute type. This information
518 * is needed when the given type is one that contains elements of other types.
519 *
520 * The atttypid and atttyptype should be derived from a previous call to
521 * statatt_get_type().
522 */
523bool
524statatt_get_elem_type(Oid atttypid, char atttyptype,
525 Oid *elemtypid, Oid *elem_eq_opr)
526{
527 TypeCacheEntry *elemtypcache;
528
529 if (atttypid == TSVECTOROID)
530 {
531 /*
532 * Special case: element type for tsvector is text. See
533 * compute_tsvector_stats().
534 */
535 *elemtypid = TEXTOID;
536 }
537 else
538 {
539 /* find underlying element type through any domain */
540 *elemtypid = get_base_element_type(atttypid);
541 }
542
543 if (!OidIsValid(*elemtypid))
544 return false;
545
546 /* finds the right operator even if elemtypid is a domain */
547 elemtypcache = lookup_type_cache(*elemtypid, TYPECACHE_EQ_OPR);
548 if (!OidIsValid(elemtypcache->eq_opr))
549 return false;
550
551 *elem_eq_opr = elemtypcache->eq_opr;
552
553 return true;
554}
555
556/*
557 * Build an array with element type elemtypid from a text datum, used as
558 * value of an attribute in a tuple to-be-inserted into pg_statistic.
559 *
560 * The typid and typmod should be derived from a previous call to
561 * statatt_get_type().
562 *
563 * If an error is encountered, capture it and throw a WARNING, with "ok" set
564 * to false. If the resulting array contains NULLs, raise a WARNING and
565 * set "ok" to false. When the operation succeeds, set "ok" to true.
566 */
567Datum
568statatt_build_stavalues(const char *staname, FmgrInfo *array_in, Datum d, Oid typid,
569 int32 typmod, bool *ok)
570{
571 LOCAL_FCINFO(fcinfo, 8);
572 char *s;
573 Datum result;
574 ErrorSaveContext escontext = {T_ErrorSaveContext};
575
576 escontext.details_wanted = true;
577
578 s = TextDatumGetCString(d);
579
581 (Node *) &escontext, NULL);
582
583 fcinfo->args[0].value = CStringGetDatum(s);
584 fcinfo->args[0].isnull = false;
585 fcinfo->args[1].value = ObjectIdGetDatum(typid);
586 fcinfo->args[1].isnull = false;
587 fcinfo->args[2].value = Int32GetDatum(typmod);
588 fcinfo->args[2].isnull = false;
589
590 result = FunctionCallInvoke(fcinfo);
591
592 pfree(s);
593
594 if (escontext.error_occurred)
595 {
596 escontext.error_data->elevel = WARNING;
597 ThrowErrorData(escontext.error_data);
598 *ok = false;
599 return (Datum) 0;
600 }
601
603 {
605 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
606 errmsg("\"%s\" array must not contain null values", staname)));
607 *ok = false;
608 return (Datum) 0;
609 }
610
611 *ok = true;
612
613 return result;
614}
615
616/*
617 * Find and update the slot of a stakind, or use the first empty slot.
618 *
619 * Core statistics types expect the stakind value to be one of the
620 * STATISTIC_KIND_* constants defined in pg_statistic.h, but types defined
621 * by extensions are not restricted to those values.
622 *
623 * In the case of core statistics, the required staop is determined by the
624 * stakind given and will either be a hardcoded oid, or the eq/lt operator
625 * derived from statatt_get_type(). Likewise, types defined by extensions
626 * have no such restriction.
627 *
628 * The stacoll value should be either the atttypcoll derived from
629 * statatt_get_type(), or a hardcoded value required by that particular
630 * stakind.
631 *
632 * The value/null pairs for stanumbers and stavalues should be calculated
633 * based on the stakind, using statatt_build_stavalues() or constructed arrays.
634 */
635void
636statatt_set_slot(Datum *values, bool *nulls, bool *replaces,
637 int16 stakind, Oid staop, Oid stacoll,
638 Datum stanumbers, bool stanumbers_isnull,
639 Datum stavalues, bool stavalues_isnull)
640{
641 int slotidx;
642 int first_empty = -1;
643 AttrNumber stakind_attnum;
644 AttrNumber staop_attnum;
645 AttrNumber stacoll_attnum;
646
647 /* find existing slot with given stakind */
648 for (slotidx = 0; slotidx < STATISTIC_NUM_SLOTS; slotidx++)
649 {
650 stakind_attnum = Anum_pg_statistic_stakind1 - 1 + slotidx;
651
652 if (first_empty < 0 &&
653 DatumGetInt16(values[stakind_attnum]) == 0)
654 first_empty = slotidx;
655 if (DatumGetInt16(values[stakind_attnum]) == stakind)
656 break;
657 }
658
659 if (slotidx >= STATISTIC_NUM_SLOTS && first_empty >= 0)
660 slotidx = first_empty;
661
662 if (slotidx >= STATISTIC_NUM_SLOTS)
664 (errmsg("maximum number of statistics slots exceeded: %d",
665 slotidx + 1)));
666
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;
670
671 if (DatumGetInt16(values[stakind_attnum]) != stakind)
672 {
673 values[stakind_attnum] = Int16GetDatum(stakind);
674 replaces[stakind_attnum] = true;
675 }
676 if (DatumGetObjectId(values[staop_attnum]) != staop)
677 {
678 values[staop_attnum] = ObjectIdGetDatum(staop);
679 replaces[staop_attnum] = true;
680 }
681 if (DatumGetObjectId(values[stacoll_attnum]) != stacoll)
682 {
683 values[stacoll_attnum] = ObjectIdGetDatum(stacoll);
684 replaces[stacoll_attnum] = true;
685 }
686 if (!stanumbers_isnull)
687 {
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;
691 }
692 if (!stavalues_isnull)
693 {
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;
697 }
698}
699
700/*
701 * Initialize values and nulls for a new pg_statistic tuple.
702 *
703 * The caller is responsible for allocating the arrays where the results are
704 * stored, which should be of size Natts_pg_statistic.
705 *
706 * When using this routine for a tuple inserted into pg_statistic, reloid,
707 * attnum and inherited flags should all be set.
708 *
709 * When using this routine for a tuple that is an element of a stxdexpr
710 * array inserted into pg_statistic_ext_data, reloid, attnum and inherited
711 * should be respectively set to InvalidOid, InvalidAttrNumber and false.
712 */
713void
714statatt_init_empty_tuple(Oid reloid, int16 attnum, bool inherited,
715 Datum *values, bool *nulls, bool *replaces)
716{
717 memset(nulls, true, sizeof(bool) * Natts_pg_statistic);
718 memset(replaces, true, sizeof(bool) * Natts_pg_statistic);
719
720 /* This must initialize non-NULL attributes */
721 values[Anum_pg_statistic_starelid - 1] = ObjectIdGetDatum(reloid);
722 nulls[Anum_pg_statistic_starelid - 1] = false;
723 values[Anum_pg_statistic_staattnum - 1] = Int16GetDatum(attnum);
724 nulls[Anum_pg_statistic_staattnum - 1] = false;
725 values[Anum_pg_statistic_stainherit - 1] = BoolGetDatum(inherited);
726 nulls[Anum_pg_statistic_stainherit - 1] = false;
727
728 values[Anum_pg_statistic_stanullfrac - 1] = DEFAULT_STATATT_NULL_FRAC;
729 nulls[Anum_pg_statistic_stanullfrac - 1] = false;
730 values[Anum_pg_statistic_stawidth - 1] = DEFAULT_STATATT_AVG_WIDTH;
731 nulls[Anum_pg_statistic_stawidth - 1] = false;
732 values[Anum_pg_statistic_stadistinct - 1] = DEFAULT_STATATT_N_DISTINCT;
733 nulls[Anum_pg_statistic_stadistinct - 1] = false;
734
735 /* initialize stakind, staop, and stacoll slots */
736 for (int slotnum = 0; slotnum < STATISTIC_NUM_SLOTS; slotnum++)
737 {
738 values[Anum_pg_statistic_stakind1 + slotnum - 1] = (Datum) 0;
739 nulls[Anum_pg_statistic_stakind1 + slotnum - 1] = false;
740 values[Anum_pg_statistic_staop1 + slotnum - 1] = ObjectIdGetDatum(InvalidOid);
741 nulls[Anum_pg_statistic_staop1 + slotnum - 1] = false;
742 values[Anum_pg_statistic_stacoll1 + slotnum - 1] = ObjectIdGetDatum(InvalidOid);
743 nulls[Anum_pg_statistic_stacoll1 + slotnum - 1] = false;
744 }
745}
AclResult
Definition: acl.h:182
@ ACLCHECK_OK
Definition: acl.h:183
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2654
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4090
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4039
#define ARR_NDIM(a)
Definition: array.h:290
#define DatumGetArrayTypeP(X)
Definition: array.h:261
bool array_contains_nulls(const ArrayType *array)
Definition: arrayfuncs.c:3768
Datum array_in(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:180
int16 AttrNumber
Definition: attnum.h:21
static Datum values[MAXATTR]
Definition: bootstrap.c:153
#define TextDatumGetCString(d)
Definition: builtins.h:98
#define NameStr(name)
Definition: c.h:765
int16_t int16
Definition: c.h:547
int32_t int32
Definition: c.h:548
#define OidIsValid(objectId)
Definition: c.h:788
struct typedefs * types
Definition: ecpg.c:30
int errhint(const char *fmt,...)
Definition: elog.c:1330
void ThrowErrorData(ErrorData *edata)
Definition: elog.c:1912
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define WARNING
Definition: elog.h:36
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define ereport(elevel,...)
Definition: elog.h:150
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
int extract_variadic_args(FunctionCallInfo fcinfo, int variadic_start, bool convert_unknown, Datum **args, Oid **types, bool **nulls)
Definition: funcapi.c:2005
Oid MyDatabaseId
Definition: globals.c:94
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
Oid IndexGetRelation(Oid indexId, bool missing_ok)
Definition: index.c:3581
int i
Definition: isn.c:77
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:229
void LockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:107
#define NoLock
Definition: lockdefs.h:34
#define AccessShareLock
Definition: lockdefs.h:36
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
Oid get_multirange_range(Oid multirangeOid)
Definition: lsyscache.c:3633
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:2153
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2982
bool type_is_multirange(Oid typid)
Definition: lsyscache.c:2848
void pfree(void *pointer)
Definition: mcxt.c:1616
Oid GetUserId(void)
Definition: miscinit.c:469
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:301
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:821
ObjectType get_relkind_objtype(char relkind)
#define ACL_MAINTAIN
Definition: parsenodes.h:90
int16 attnum
Definition: pg_attribute.h:74
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:202
void * arg
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
FormData_pg_class * Form_pg_class
Definition: pg_class.h:156
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
static ListCell * list_head(const List *l)
Definition: pg_list.h:128
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:343
#define STATISTIC_NUM_SLOTS
Definition: pg_statistic.h:127
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:32
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:252
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:182
static Datum BoolGetDatum(bool X)
Definition: postgres.h:112
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
uint64_t Datum
Definition: postgres.h:70
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:360
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:222
static int16 DatumGetInt16(Datum X)
Definition: postgres.h:172
#define InvalidOid
Definition: postgres_ext.h:37
unsigned int Oid
Definition: postgres_ext.h:32
#define RelationGetRelationName(relation)
Definition: rel.h:549
List * RelationGetIndexExpressions(Relation relation)
Definition: relcache.c:5092
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:47
#define DEFAULT_STATATT_NULL_FRAC
Definition: stat_utils.c:40
bool statatt_get_elem_type(Oid atttypid, char atttyptype, Oid *elemtypid, Oid *elem_eq_opr)
Definition: stat_utils.c:522
Datum statatt_build_stavalues(const char *staname, FmgrInfo *array_in, Datum d, Oid typid, int32 typmod, bool *ok)
Definition: stat_utils.c:566
bool stats_fill_fcinfo_from_arg_pairs(FunctionCallInfo pairs_fcinfo, FunctionCallInfo positional_fcinfo, struct StatsArgInfo *arginfo)
Definition: stat_utils.c:347
static int get_arg_by_name(const char *argname, struct StatsArgInfo *arginfo)
Definition: stat_utils.c:261
void RangeVarCallbackForStats(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
Definition: stat_utils.c:141
void statatt_init_empty_tuple(Oid reloid, int16 attnum, bool inherited, Datum *values, bool *nulls, bool *replaces)
Definition: stat_utils.c:712
#define DEFAULT_STATATT_AVG_WIDTH
Definition: stat_utils.c:41
static bool stats_check_arg_type(const char *argname, Oid argtype, Oid expectedtype)
Definition: stat_utils.c:279
bool stats_check_arg_array(FunctionCallInfo fcinfo, struct StatsArgInfo *arginfo, int argnum)
Definition: stat_utils.c:69
void statatt_get_type(Oid reloid, AttrNumber attnum, Oid *atttypid, int32 *atttypmod, char *atttyptype, Oid *atttypcoll, Oid *eq_opr, Oid *lt_opr)
Definition: stat_utils.c:436
void stats_check_required_arg(FunctionCallInfo fcinfo, struct StatsArgInfo *arginfo, int argnum)
Definition: stat_utils.c:50
static Node * statatt_get_index_expr(Relation rel, int attnum)
Definition: stat_utils.c:302
#define DEFAULT_STATATT_N_DISTINCT
Definition: stat_utils.c:42
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)
Definition: stat_utils.c:634
bool stats_check_arg_pair(FunctionCallInfo fcinfo, struct StatsArgInfo *arginfo, int argnum1, int argnum2)
Definition: stat_utils.c:110
int elevel
Definition: elog.h:421
bool details_wanted
Definition: miscnodes.h:48
ErrorData * error_data
Definition: miscnodes.h:49
bool error_occurred
Definition: miscnodes.h:47
Definition: fmgr.h:57
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
Definition: pg_list.h:54
Definition: nodes.h:135
Datum value
Definition: postgres.h:87
bool isnull
Definition: postgres.h:89
char * relname
Definition: primnodes.h:83
List * rd_indexprs
Definition: rel.h:212
Form_pg_index rd_index
Definition: rel.h:192
Form_pg_class rd_rel
Definition: rel.h:111
const char * argname
Definition: stat_utils.h:24
char typtype
Definition: typcache.h:43
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:220
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:230
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition: typcache.c:386
#define TYPECACHE_EQ_OPR
Definition: typcache.h:138
#define TYPECACHE_LT_OPR
Definition: typcache.h:139