43#include "utils/fmgroids.h"
59#define WIDTH_THRESHOLD 1024
133 "BuildRelationExtStatistics",
140 const int index[] = {
170 natts, vacattrstats);
176 errmsg(
"statistics object \"%s.%s\" could not be computed for relation \"%s.%s\"",
218 elog(
ERROR,
"requested expression stats, but there are no expressions");
231 ndistinct, dependencies, mcv,
exprstats, stats);
312 "ComputeExtStatisticsRows",
332 natts, vacattrstats);
395 for (
i = 0;
i < nattrs;
i++)
398 if (stats[
i]->attstattarget > stattarget)
444 elog(
ERROR,
"unexpected statistics type requested: %d",
type);
506 elog(
ERROR,
"stxkind is not a 1-D char array");
547 entry->
exprs = exprs;
782 if (stats[
i] ==
NULL)
819 memset(nulls,
true,
sizeof(nulls));
833 if (ndistinct !=
NULL)
841 if (dependencies !=
NULL)
855 if (exprs != (
Datum) 0)
918 for (
i = 0;
i <
mss->ndims;
i++)
923 ib->values[
i],
ib->isnull[
i],
940 b->values[dim],
b->isnull[dim],
951 for (dim =
start; dim <= end; dim++)
954 b->values[dim],
b->isnull[dim],
1049 nvalues * (
sizeof(
Datum) +
sizeof(
bool));
1061 ptr += nvalues *
sizeof(
Datum);
1063 isnull = (
bool *) ptr;
1064 ptr += nvalues *
sizeof(
bool);
1071 for (
i = 0;
i <
data->numrows;
i++)
1081 for (
i = 0;
i <
data->nattnums;
i++)
1085 for (
i = 0;
i <
data->numrows;
i++)
1121 if ((!isnull) && (
attlen == -1))
1133 items[nrows].isnull[
j] = isnull;
1389 Var *var = (
Var *) clause;
1392 if (var->
varno != relid)
1551 relid, attnums, exprs,
1580 *exprs =
lappend(*exprs, clause);
1629 relid, attnums, exprs))
1642 if (rinfo->pseudoconstant)
1656 relid, attnums, exprs,
1927 jointype, sjinfo,
false);
2007 varRelid, jointype, sjinfo,
2062 jointype, sjinfo, rel,
2145 "Analyze Expression",
2185 exprnulls = (
bool *)
palloc(numrows *
sizeof(
bool));
2188 for (
i = 0;
i < numrows;
i++)
2213 exprnulls[
tcnt] =
true;
2223 exprnulls[
tcnt] =
false;
2335 errmsg(
"relation \"%s\" does not have a composite type",
2398 for (n = 0; n <
nnum; n++)
2472 "requested statistics kind \"%c\" is not yet built for statistics object %u",
2557 result->nulls = (
bool **) ptr;
2558 ptr +=
MAXALIGN(
sizeof(
bool *) * nkeys);
2560 for (
i = 0;
i < nkeys;
i++)
2565 result->nulls[
i] = (
bool *) ptr;
2566 ptr +=
MAXALIGN(
sizeof(
bool) * numrows);
2572 result->nattnums = nkeys;
2573 result->numrows = numrows;
2599 for (
i = 0;
i < numrows;
i++)
2627 for (
i = 0;
i < numrows;
i++)
2639 foreach(
lc, exprstates)
Datum idx(PG_FUNCTION_ARGS)
#define DatumGetArrayTypeP(X)
void deconstruct_expanded_array(ExpandedArrayHeader *eah)
ExpandedArrayHeader * DatumGetExpandedArray(Datum d)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
#define AttributeNumberIsValid(attributeNumber)
#define AttrNumberIsForUserDefinedAttr(attributeNumber)
#define InvalidAttrNumber
AttributeOpts * get_attribute_options(Oid attrelid, int attnum)
void pgstat_progress_update_param(int index, int64 val)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
void bms_free(Bitmapset *a)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
BMS_Membership bms_membership(const Bitmapset *a)
bool bms_get_singleton_member(const Bitmapset *a, int *member)
static Datum values[MAXATTR]
#define TextDatumGetCString(d)
#define Assert(condition)
#define OidIsValid(objectId)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Selectivity clause_selectivity_ext(PlannerInfo *root, Node *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, bool use_extended_stats)
Selectivity clauselist_selectivity_ext(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, bool use_extended_stats)
int default_statistics_target
bool std_typanalyze(VacAttrStats *stats)
Datum datumCopy(Datum value, bool typByVal, int typLen)
MVDependencies * statext_dependencies_build(StatsBuildData *data)
bytea * statext_dependencies_serialize(MVDependencies *dependencies)
Selectivity dependencies_clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, RelOptInfo *rel, Bitmapset **estimatedclauses)
Size toast_raw_datum_size(Datum value)
int errcode(int sqlerrcode)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
ExprState * ExecPrepareExpr(Expr *node, EState *estate)
List * ExecPrepareExprList(List *nodes, EState *estate)
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
const TupleTableSlotOps TTSOpsHeapTuple
TupleTableSlot * ExecStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
void FreeExecutorState(EState *estate)
EState * CreateExecutorState(void)
#define GetPerTupleExprContext(estate)
#define ResetExprContext(econtext)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
bool has_stats_of_kind(List *stats, char requiredkind)
static AnlExprData * build_expr_data(List *exprs, int stattarget)
static VacAttrStats ** lookup_var_attr_stats(Bitmapset *attrs, List *exprs, int nvacatts, VacAttrStats **vacatts)
int multi_sort_compare_dims(int start, int end, const SortItem *a, const SortItem *b, MultiSortSupport mss)
static bool stat_covers_expressions(StatisticExtInfo *stat, List *exprs, Bitmapset **expr_idxs)
static List * fetch_statentries_for_relation(Relation pg_statext, Relation rel)
static Datum expr_fetch_func(VacAttrStatsP stats, int rownum, bool *isNull)
static Selectivity statext_mcv_clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, RelOptInfo *rel, Bitmapset **estimatedclauses, bool is_or)
int multi_sort_compare_dim(int dim, const SortItem *a, const SortItem *b, MultiSortSupport mss)
static VacAttrStats * examine_attribute(Node *expr)
StatisticExtInfo * choose_best_statistics(List *stats, char requiredkind, bool inh, Bitmapset **clause_attnums, List **clause_exprs, int nclauses)
int compare_scalars_simple(const void *a, const void *b, void *arg)
int ComputeExtStatisticsRows(Relation onerel, int natts, VacAttrStats **vacattrstats)
static StatsBuildData * make_build_data(Relation rel, StatExtEntry *stat, int numrows, HeapTuple *rows, VacAttrStats **stats, int stattarget)
static bool statext_is_compatible_clause_internal(PlannerInfo *root, Node *clause, Index relid, Bitmapset **attnums, List **exprs, bool *leakproof)
AttrNumber * build_attnums_array(Bitmapset *attrs, int nexprs, int *numattrs)
bool HasRelationExtStatistics(Relation onerel)
int compare_datums_simple(Datum a, Datum b, SortSupport ssup)
static bool statext_is_compatible_clause(PlannerInfo *root, Node *clause, Index relid, Bitmapset **attnums, List **exprs)
static void statext_store(Oid statOid, bool inh, MVNDistinct *ndistinct, MVDependencies *dependencies, MCVList *mcv, Datum exprs, VacAttrStats **stats)
bool statext_is_kind_built(HeapTuple htup, char type)
static VacAttrStats * examine_expression(Node *expr, int stattarget)
void BuildRelationExtStatistics(Relation onerel, bool inh, double totalrows, int numrows, HeapTuple *rows, int natts, VacAttrStats **vacattrstats)
Selectivity statext_clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, RelOptInfo *rel, Bitmapset **estimatedclauses, bool is_or)
SortItem * build_sorted_items(StatsBuildData *data, int *nitems, MultiSortSupport mss, int numattrs, AttrNumber *attnums)
static int stat_find_expression(StatisticExtInfo *stat, Node *expr)
static int statext_compute_stattarget(int stattarget, int nattrs, VacAttrStats **stats)
static void compute_expr_stats(Relation onerel, AnlExprData *exprdata, int nexprs, HeapTuple *rows, int numrows)
int multi_sort_compare(const void *a, const void *b, void *arg)
MultiSortSupport multi_sort_init(int ndims)
HeapTuple statext_expressions_load(Oid stxoid, bool inh, int idx)
static Datum serialize_expr_stats(AnlExprData *exprdata, int nexprs)
void multi_sort_add_dimension(MultiSortSupport mss, int sortdim, Oid oper, Oid collation)
bool examine_opclause_args(List *args, Node **exprp, Const **cstp, bool *expronleftp)
MultiSortSupportData * MultiSortSupport
#define palloc_array(type, count)
#define palloc0_object(type)
#define OidFunctionCall1(functionId, arg1)
#define DatumGetHeapTupleHeader(X)
#define PG_DETOAST_DATUM(datum)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
static int compare(const void *arg1, const void *arg2)
HeapTuple heap_copytuple(HeapTuple tuple)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
static void * GETSTRUCT(const HeapTupleData *tuple)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
void list_free(List *list)
RegProcedure get_oprrest(Oid opno)
RegProcedure get_opcode(Oid opno)
Oid get_rel_type_id(Oid relid)
bool get_func_leakproof(Oid funcid)
int16 get_typlen(Oid typid)
char * get_namespace_name(Oid nspid)
Selectivity mcv_clauselist_selectivity(PlannerInfo *root, StatisticExtInfo *stat, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, RelOptInfo *rel, Selectivity *basesel, Selectivity *totalsel)
MCVList * statext_mcv_load(Oid mvoid, bool inh)
Selectivity mcv_combine_selectivities(Selectivity simple_sel, Selectivity mcv_sel, Selectivity mcv_basesel, Selectivity mcv_totalsel)
Selectivity mcv_clause_selectivity_or(PlannerInfo *root, StatisticExtInfo *stat, MCVList *mcv, Node *clause, bool **or_matches, Selectivity *basesel, Selectivity *overlap_mcvsel, Selectivity *overlap_basesel, Selectivity *totalsel)
MCVList * statext_mcv_build(StatsBuildData *data, double totalrows, int stattarget)
bytea * statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats)
void MemoryContextReset(MemoryContext context)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define AmAutoVacuumWorkerProcess()
bytea * statext_ndistinct_serialize(MVNDistinct *ndistinct)
MVNDistinct * statext_ndistinct_build(double totalrows, StatsBuildData *data)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
void fix_opfuncids(Node *node)
static bool is_andclause(const void *clause)
static bool is_orclause(const void *clause)
static bool is_opclause(const void *clause)
static bool is_notclause(const void *clause)
#define IsA(nodeptr, _type_)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
#define planner_rt_fetch(rti, root)
static int list_length(const List *l)
#define STATISTIC_NUM_SLOTS
END_CATALOG_STRUCT typedef FormData_pg_statistic_ext * Form_pg_statistic_ext
END_CATALOG_STRUCT typedef FormData_pg_type * Form_pg_type
void qsort_interruptible(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Datum Float4GetDatum(float4 X)
static Datum Int16GetDatum(int16 X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum Int32GetDatum(int32 X)
static int16 DatumGetInt16(Datum X)
#define PROGRESS_ANALYZE_EXT_STATS_COMPUTED
#define PROGRESS_ANALYZE_PHASE
#define PROGRESS_ANALYZE_PHASE_COMPUTE_EXT_STATS
#define PROGRESS_ANALYZE_EXT_STATS_TOTAL
void * stringToNode(const char *str)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
int errtable(Relation rel)
Node * expand_generated_columns_in_expr(Node *node, Relation rel, int rt_index)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
bool all_rows_selectable(PlannerInfo *root, Index varno, Bitmapset *varattnos)
#define CLAMP_PROBABILITY(p)
void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
static int ApplySortComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup)
#define STATS_MAX_DIMENSIONS
void RemoveStatisticsDataById(Oid statsOid, bool inh)
#define BTEqualStrategyNumber
VacAttrStats * vacattrstat
TupleTableSlot * ecxt_scantuple
int16 stakind[STATISTIC_NUM_SLOTS]
MemoryContext anl_context
Oid statypid[STATISTIC_NUM_SLOTS]
Oid staop[STATISTIC_NUM_SLOTS]
Oid stacoll[STATISTIC_NUM_SLOTS]
char statypalign[STATISTIC_NUM_SLOTS]
float4 * stanumbers[STATISTIC_NUM_SLOTS]
bool statypbyval[STATISTIC_NUM_SLOTS]
int16 statyplen[STATISTIC_NUM_SLOTS]
int numvalues[STATISTIC_NUM_SLOTS]
Datum * stavalues[STATISTIC_NUM_SLOTS]
int numnumbers[STATISTIC_NUM_SLOTS]
AnalyzeAttrComputeStatsFunc compute_stats
#define FirstLowInvalidHeapAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
#define SearchSysCacheCopy1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
#define MAX_STATISTICS_TARGET
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)