PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/detoast.h"
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "catalog/indexing.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_statistic_ext_data.h"
#include "commands/defrem.h"
#include "commands/progress.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/optimizer.h"
#include "parser/parsetree.h"
#include "pgstat.h"
#include "postmaster/autovacuum.h"
#include "statistics/extended_stats_internal.h"
#include "statistics/statistics.h"
#include "utils/acl.h"
#include "utils/array.h"
#include "utils/attoptcache.h"
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/selfuncs.h"
#include "utils/syscache.h"
Go to the source code of this file.
Data Structures | |
struct | StatExtEntry |
struct | AnlExprData |
Macros | |
#define | WIDTH_THRESHOLD 1024 |
Typedefs | |
typedef struct StatExtEntry | StatExtEntry |
typedef struct AnlExprData | AnlExprData |
#define WIDTH_THRESHOLD 1024 |
Definition at line 58 of file extended_stats.c.
typedef struct AnlExprData AnlExprData |
typedef struct StatExtEntry StatExtEntry |
AttrNumber* build_attnums_array | ( | Bitmapset * | attrs, |
int | nexprs, | ||
int * | numattrs | ||
) |
Definition at line 941 of file extended_stats.c.
References Assert, attnum, AttributeNumberIsValid, bms_next_member(), bms_num_members(), i, j, MaxAttrNumber, and palloc().
|
static |
Definition at line 2270 of file extended_stats.c.
References examine_expression(), AnlExprData::expr, idx(), lfirst, list_length(), palloc0(), and AnlExprData::vacattrstat.
Referenced by BuildRelationExtStatistics().
SortItem* build_sorted_items | ( | StatsBuildData * | data, |
int * | nitems, | ||
MultiSortSupport | mss, | ||
int | numattrs, | ||
AttrNumber * | attnums | ||
) |
Definition at line 986 of file extended_stats.c.
References Assert, attlen, attnum, data, get_typlen(), i, idx(), items, j, len, multi_sort_compare(), nitems, palloc(), palloc0(), pfree(), PG_DETOAST_DATUM, PointerGetDatum(), qsort_interruptible(), toast_raw_datum_size(), value, values, and WIDTH_THRESHOLD.
Referenced by dependency_degree(), and statext_mcv_build().
void BuildRelationExtStatistics | ( | Relation | onerel, |
bool | inh, | ||
double | totalrows, | ||
int | numrows, | ||
HeapTuple * | rows, | ||
int | natts, | ||
VacAttrStats ** | vacattrstats | ||
) |
Definition at line 112 of file extended_stats.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, AmAutoVacuumWorkerProcess, bms_num_members(), build_expr_data(), compute_expr_stats(), CurrentMemoryContext, data, elog, ereport, errcode(), errmsg(), ERROR, errtable(), fetch_statentries_for_relation(), get_namespace_name(), lfirst, lfirst_int, list_free(), list_length(), lookup_var_attr_stats(), make_build_data(), MemoryContextDelete(), MemoryContextReset(), MemoryContextSwitchTo(), NIL, pgstat_progress_update_multi_param(), pgstat_progress_update_param(), PROGRESS_ANALYZE_EXT_STATS_COMPUTED, PROGRESS_ANALYZE_EXT_STATS_TOTAL, PROGRESS_ANALYZE_PHASE, PROGRESS_ANALYZE_PHASE_COMPUTE_EXT_STATS, RelationData::rd_rel, RelationGetRelationName, RelationGetRelid, RowExclusiveLock, serialize_expr_stats(), statext_compute_stattarget(), statext_dependencies_build(), statext_mcv_build(), statext_ndistinct_build(), statext_store(), table_close(), table_open(), val, and WARNING.
Referenced by do_analyze_rel().
StatisticExtInfo* choose_best_statistics | ( | List * | stats, |
char | requiredkind, | ||
bool | inh, | ||
Bitmapset ** | clause_attnums, | ||
List ** | clause_exprs, | ||
int | nclauses | ||
) |
Definition at line 1209 of file extended_stats.c.
References bms_add_members(), bms_free(), bms_is_subset(), bms_num_members(), StatisticExtInfo::exprs, i, StatisticExtInfo::inherit, StatisticExtInfo::keys, StatisticExtInfo::kind, lfirst, list_length(), stat_covers_expressions(), and STATS_MAX_DIMENSIONS.
Referenced by statext_mcv_clauselist_selectivity().
int compare_datums_simple | ( | Datum | a, |
Datum | b, | ||
SortSupport | ssup | ||
) |
Definition at line 927 of file extended_stats.c.
References a, ApplySortComparator(), and b.
Referenced by compare_scalars_simple(), and statext_mcv_serialize().
int compare_scalars_simple | ( | const void * | a, |
const void * | b, | ||
void * | arg | ||
) |
Definition at line 919 of file extended_stats.c.
References a, arg, b, and compare_datums_simple().
Referenced by statext_mcv_serialize().
|
static |
Definition at line 2110 of file extended_stats.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, VacAttrStats::attrtype, VacAttrStats::compute_stats, CreateExecutorState(), CurrentMemoryContext, datumCopy(), ExprContext::ecxt_scantuple, ExecDropSingleTupleTableSlot(), ExecEvalExprSwitchContext(), ExecPrepareExpr(), ExecStoreHeapTuple(), AnlExprData::expr, expr_fetch_func(), VacAttrStats::exprnulls, VacAttrStats::exprvals, FreeExecutorState(), get_attribute_options(), GetPerTupleExprContext, i, MakeSingleTupleTableSlot(), MemoryContextDelete(), MemoryContextReset(), MemoryContextSwitchTo(), AttributeOpts::n_distinct, palloc(), RelationData::rd_id, RelationGetDescr, ResetExprContext, VacAttrStats::rowstride, VacAttrStats::stadistinct, TTSOpsHeapTuple, VacAttrStats::tupattnum, and AnlExprData::vacattrstat.
Referenced by BuildRelationExtStatistics().
int ComputeExtStatisticsRows | ( | Relation | onerel, |
int | natts, | ||
VacAttrStats ** | vacattrstats | ||
) |
Definition at line 265 of file extended_stats.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, bms_num_members(), CurrentMemoryContext, fetch_statentries_for_relation(), lfirst, lookup_var_attr_stats(), MemoryContextDelete(), MemoryContextSwitchTo(), RelationGetRelid, RowExclusiveLock, statext_compute_stattarget(), table_close(), and table_open().
Referenced by do_analyze_rel().
|
static |
Definition at line 528 of file extended_stats.c.
References VacAttrStats::anl_context, VacAttrStats::attrcollid, VacAttrStats::attrtype, VacAttrStats::attrtypid, VacAttrStats::attrtypmod, VacAttrStats::attstattarget, VacAttrStats::compute_stats, DatumGetBool(), elog, ERROR, exprCollation(), exprType(), exprTypmod(), GETSTRUCT, heap_freetuple(), HeapTupleIsValid, i, InvalidAttrNumber, VacAttrStats::minrows, ObjectIdGetDatum(), OidFunctionCall1, OidIsValid, palloc0(), pfree(), PointerGetDatum(), SearchSysCacheCopy1, STATISTIC_NUM_SLOTS, VacAttrStats::statypalign, VacAttrStats::statypbyval, VacAttrStats::statypid, VacAttrStats::statyplen, std_typanalyze(), and VacAttrStats::tupattnum.
Referenced by lookup_var_attr_stats().
|
static |
Definition at line 607 of file extended_stats.c.
References VacAttrStats::anl_context, Assert, VacAttrStats::attrcollid, VacAttrStats::attrtype, VacAttrStats::attrtypid, VacAttrStats::attrtypmod, VacAttrStats::attstattarget, VacAttrStats::compute_stats, CurrentMemoryContext, DatumGetBool(), elog, ERROR, exprCollation(), exprType(), exprTypmod(), GETSTRUCT, heap_freetuple(), HeapTupleIsValid, i, InvalidAttrNumber, VacAttrStats::minrows, ObjectIdGetDatum(), OidFunctionCall1, OidIsValid, palloc0(), pfree(), PointerGetDatum(), SearchSysCacheCopy1, STATISTIC_NUM_SLOTS, VacAttrStats::statypalign, VacAttrStats::statypbyval, VacAttrStats::statypid, VacAttrStats::statyplen, std_typanalyze(), and VacAttrStats::tupattnum.
Referenced by build_expr_data(), and make_build_data().
Definition at line 2055 of file extended_stats.c.
References arg, generate_unaccent_rules::args, Assert, IsA, linitial, list_length(), and lsecond.
Referenced by mcv_get_match_bitmap(), and statext_is_compatible_clause_internal().
|
static |
Definition at line 2254 of file extended_stats.c.
References VacAttrStats::exprnulls, VacAttrStats::exprvals, i, and VacAttrStats::rowstride.
Referenced by compute_expr_stats().
Definition at line 422 of file extended_stats.c.
References ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, Assert, bms_add_member(), BTEqualStrategyNumber, StatExtEntry::columns, DatumGetArrayTypeP, DatumGetInt16(), elog, ERROR, eval_const_expressions(), StatExtEntry::exprs, fix_opfuncids(), get_namespace_name(), GETSTRUCT, HeapTupleIsValid, i, lappend(), lappend_int(), StatExtEntry::name, NameStr, NIL, ObjectIdGetDatum(), palloc0(), pfree(), pstrdup(), ScanKeyInit(), StatExtEntry::schema, StatExtEntry::statOid, StatExtEntry::stattarget, stringToNode(), SysCacheGetAttr(), SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), TextDatumGetCString, and StatExtEntry::types.
Referenced by BuildRelationExtStatistics(), and ComputeExtStatisticsRows().
Definition at line 1118 of file extended_stats.c.
References lfirst.
Referenced by dependencies_clauselist_selectivity(), and statext_mcv_clauselist_selectivity().
|
static |
Definition at line 693 of file extended_stats.c.
References bms_next_member(), bms_num_members(), examine_attribute(), i, j, lfirst, list_length(), palloc(), pfree(), VacAttrStats::tupDesc, and x.
Referenced by BuildRelationExtStatistics(), and ComputeExtStatisticsRows().
|
static |
Definition at line 2472 of file extended_stats.c.
References Assert, StatsBuildData::attnums, bms_next_member(), bms_num_members(), CreateExecutorState(), ExprContext::ecxt_scantuple, examine_expression(), ExecDropSingleTupleTableSlot(), ExecEvalExpr(), ExecPrepareExprList(), ExecStoreHeapTuple(), FreeExecutorState(), GetPerTupleExprContext, heap_getattr(), i, idx(), len, lfirst, list_length(), MakeSingleTupleTableSlot(), MAXALIGN, StatsBuildData::nattnums, NIL, StatsBuildData::nulls, StatsBuildData::numrows, palloc(), RelationGetDescr, ResetExprContext, StatsBuildData::stats, TTSOpsHeapTuple, VacAttrStats::tupDesc, and StatsBuildData::values.
Referenced by BuildRelationExtStatistics().
void multi_sort_add_dimension | ( | MultiSortSupport | mss, |
int | sortdim, | ||
Oid | oper, | ||
Oid | collation | ||
) |
Definition at line 851 of file extended_stats.c.
References CurrentMemoryContext, oper(), PrepareSortSupportFromOrderingOp(), MultiSortSupportData::ssup, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, and SortSupportData::ssup_nulls_first.
Referenced by build_mss(), dependency_degree(), and ndistinct_for_combination().
int multi_sort_compare | ( | const void * | a, |
const void * | b, | ||
void * | arg | ||
) |
Definition at line 865 of file extended_stats.c.
References a, ApplySortComparator(), arg, b, compare(), i, SortItem::isnull, MultiSortSupportData::ndims, MultiSortSupportData::ssup, and SortItem::values.
Referenced by build_distinct_groups(), build_sorted_items(), count_distinct_groups(), ndistinct_for_combination(), and statext_mcv_build().
int multi_sort_compare_dim | ( | int | dim, |
const SortItem * | a, | ||
const SortItem * | b, | ||
MultiSortSupport | mss | ||
) |
Definition at line 890 of file extended_stats.c.
References a, ApplySortComparator(), b, and MultiSortSupportData::ssup.
Referenced by dependency_degree().
int multi_sort_compare_dims | ( | int | start, |
int | end, | ||
const SortItem * | a, | ||
const SortItem * | b, | ||
MultiSortSupport | mss | ||
) |
Definition at line 899 of file extended_stats.c.
References a, ApplySortComparator(), b, MultiSortSupportData::ssup, and start.
Referenced by dependency_degree().
MultiSortSupport multi_sort_init | ( | int | ndims | ) |
Definition at line 832 of file extended_stats.c.
References Assert, MultiSortSupportData::ndims, and palloc0().
Referenced by build_mss(), dependency_degree(), and ndistinct_for_combination().
|
static |
Definition at line 2295 of file extended_stats.c.
References accumArrayResult(), BoolGetDatum(), construct_array(), construct_array_builtin(), CurrentMemoryContext, ereport, errcode(), errmsg(), ERROR, Float4GetDatum(), get_rel_type_id(), heap_copy_tuple_as_datum(), heap_form_tuple(), i, Int16GetDatum(), Int32GetDatum(), InvalidAttrNumber, InvalidOid, makeArrayResult(), VacAttrStats::numnumbers, VacAttrStats::numvalues, ObjectIdGetDatum(), OidIsValid, palloc(), PointerGetDatum(), RelationGetDescr, RowExclusiveLock, VacAttrStats::stacoll, VacAttrStats::stadistinct, VacAttrStats::stakind, VacAttrStats::stanullfrac, VacAttrStats::stanumbers, VacAttrStats::staop, STATISTIC_NUM_SLOTS, VacAttrStats::stats_valid, VacAttrStats::statypalign, VacAttrStats::statypbyval, VacAttrStats::statypid, VacAttrStats::statyplen, VacAttrStats::stavalues, VacAttrStats::stawidth, table_close(), table_open(), AnlExprData::vacattrstat, and values.
Referenced by BuildRelationExtStatistics().
|
static |
Definition at line 1168 of file extended_stats.c.
References bms_add_member(), lfirst, and stat_find_expression().
Referenced by choose_best_statistics(), and statext_mcv_clauselist_selectivity().
|
static |
Definition at line 1141 of file extended_stats.c.
References equal(), idx(), and lfirst.
Referenced by stat_covers_expressions().
Selectivity statext_clauselist_selectivity | ( | PlannerInfo * | root, |
List * | clauses, | ||
int | varRelid, | ||
JoinType | jointype, | ||
SpecialJoinInfo * | sjinfo, | ||
RelOptInfo * | rel, | ||
Bitmapset ** | estimatedclauses, | ||
bool | is_or | ||
) |
Definition at line 2004 of file extended_stats.c.
References dependencies_clauselist_selectivity(), root, and statext_mcv_clauselist_selectivity().
Referenced by clauselist_selectivity_ext(), and clauselist_selectivity_or().
|
static |
Definition at line 347 of file extended_stats.c.
References Assert, VacAttrStats::attstattarget, default_statistics_target, i, and MAX_STATISTICS_TARGET.
Referenced by BuildRelationExtStatistics(), and ComputeExtStatisticsRows().
Definition at line 2425 of file extended_stats.c.
References BoolGetDatum(), DatumGetExpandedArray(), DatumGetHeapTupleHeader, deconstruct_expanded_array(), ExpandedArrayHeader::dvalues, elog, ERROR, heap_copytuple(), HeapTupleHeaderGetDatumLength, HeapTupleIsValid, idx(), InvalidOid, ItemPointerSetInvalid(), ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache2(), SysCacheGetAttr(), HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, and value.
Referenced by examine_variable().
|
static |
Definition at line 1572 of file extended_stats.c.
References ACL_SELECT, ACLCHECK_OK, ACLMASK_ALL, BoolExpr::args, attnum, bms_add_member(), bms_get_singleton_member(), bms_next_member(), RestrictInfo::clause, FirstLowInvalidHeapAttributeNumber, GetUserId(), InvalidAttrNumber, is_andclause(), IsA, lfirst, NIL, OidIsValid, pg_attribute_aclcheck(), pg_attribute_aclcheck_all(), pg_class_aclcheck(), pull_varattnos(), RangeTblEntry::relid, root, statext_is_compatible_clause_internal(), and RelOptInfo::userid.
Referenced by statext_mcv_clauselist_selectivity().
|
static |
Definition at line 1328 of file extended_stats.c.
References arg, NullTest::arg, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, AttrNumberIsForUserDefinedAttr, bms_add_member(), examine_opclause_args(), get_func_leakproof(), get_opcode(), get_oprrest(), is_andclause(), is_notclause(), is_opclause(), is_orclause(), IsA, lappend(), lfirst, list_length(), NIL, OpExpr::opno, ScalarArrayOpExpr::opno, root, Var::varattno, Var::varlevelsup, and Var::varno.
Referenced by statext_is_compatible_clause().
Definition at line 389 of file extended_stats.c.
References attnum, elog, ERROR, heap_attisnull(), and type.
Referenced by get_relation_statistics_worker().
|
static |
Definition at line 1716 of file extended_stats.c.
References Assert, bms_add_member(), bms_free(), bms_is_member(), bms_is_subset(), bms_membership(), BMS_SINGLETON, choose_best_statistics(), CLAMP_PROBABILITY, clause_selectivity_ext(), clauselist_selectivity_ext(), has_stats_of_kind(), RangeTblEntry::inh, lappend(), lfirst, list_free(), list_length(), mcv_clause_selectivity_or(), mcv_clauselist_selectivity(), mcv_combine_selectivities(), NIL, palloc(), planner_rt_fetch, RelOptInfo::relid, root, stat, stat_covers_expressions(), statext_is_compatible_clause(), statext_mcv_load(), and RelOptInfo::statlist.
Referenced by statext_clauselist_selectivity().
|
static |
Definition at line 762 of file extended_stats.c.
References BoolGetDatum(), CatalogTupleInsert(), data, heap_form_tuple(), heap_freetuple(), ObjectIdGetDatum(), PointerGetDatum(), RelationGetDescr, RemoveStatisticsDataById(), RowExclusiveLock, statext_dependencies_serialize(), statext_mcv_serialize(), statext_ndistinct_serialize(), table_close(), table_open(), and values.
Referenced by BuildRelationExtStatistics().