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_collation.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_statistic_ext_data.h"
#include "executor/executor.h"
#include "commands/progress.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/optimizer.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"
#include "utils/typcache.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 59 of file extended_stats.c.
Referenced by build_sorted_items().
typedef struct AnlExprData AnlExprData |
typedef struct StatExtEntry StatExtEntry |
AttrNumber* build_attnums_array | ( | Bitmapset * | attrs, |
int | nexprs, | ||
int * | numattrs | ||
) |
Definition at line 965 of file extended_stats.c.
References Assert, attnum, AttributeNumberIsValid, bms_next_member(), bms_num_members(), i, MaxAttrNumber, and palloc().
|
static |
Definition at line 2237 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 1010 of file extended_stats.c.
References Assert, attlen, attnum, StatsBuildData::attnums, VacAttrStats::attrtypid, get_typlen(), i, idx(), multi_sort_compare(), StatsBuildData::nattnums, StatsBuildData::nulls, StatsBuildData::numrows, palloc(), palloc0(), pfree(), PG_DETOAST_DATUM, PointerGetDatum, qsort_arg(), StatsBuildData::stats, toast_raw_datum_size(), value, StatsBuildData::values, values, and WIDTH_THRESHOLD.
Referenced by dependency_degree(), and statext_mcv_build().
void BuildRelationExtStatistics | ( | Relation | onerel, |
double | totalrows, | ||
int | numrows, | ||
HeapTuple * | rows, | ||
int | natts, | ||
VacAttrStats ** | vacattrstats | ||
) |
Definition at line 113 of file extended_stats.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, bms_num_members(), build_expr_data(), StatExtEntry::columns, compute_expr_stats(), CurrentMemoryContext, elog, ereport, errcode(), errmsg(), ERROR, errtable(), StatExtEntry::exprs, fetch_statentries_for_relation(), get_namespace_name(), IsAutoVacuumWorkerProcess(), lfirst, lfirst_int, list_length(), lookup_var_attr_stats(), make_build_data(), MemoryContextDelete(), MemoryContextSwitchTo(), StatExtEntry::name, NIL, pfree(), 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, StatExtEntry::schema, serialize_expr_stats(), statext_compute_stattarget(), statext_dependencies_build(), statext_mcv_build(), statext_ndistinct_build(), statext_store(), StatExtEntry::statOid, StatExtEntry::stattarget, table_close(), table_open(), StatExtEntry::types, val, and WARNING.
Referenced by do_analyze_rel().
StatisticExtInfo* choose_best_statistics | ( | List * | stats, |
char | requiredkind, | ||
Bitmapset ** | clause_attnums, | ||
List ** | clause_exprs, | ||
int | nclauses | ||
) |
Definition at line 1233 of file extended_stats.c.
References bms_add_members(), bms_free(), bms_is_subset(), bms_num_members(), StatisticExtInfo::exprs, i, 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 951 of file extended_stats.c.
References ApplySortComparator().
Referenced by compare_scalars_simple(), and statext_mcv_serialize().
int compare_scalars_simple | ( | const void * | a, |
const void * | b, | ||
void * | arg | ||
) |
Definition at line 943 of file extended_stats.c.
References compare_datums_simple().
Referenced by statext_mcv_serialize().
|
static |
Definition at line 2076 of file extended_stats.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, VacAttrStats::attr, 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(), MemoryContextResetAndDeleteChildren, MemoryContextSwitchTo(), AttributeOpts::n_distinct, palloc(), RelationGetDescr, ResetExprContext, VacAttrStats::rowstride, VacAttrStats::stadistinct, TTSOpsHeapTuple, and AnlExprData::vacattrstat.
Referenced by BuildRelationExtStatistics().
int ComputeExtStatisticsRows | ( | Relation | onerel, |
int | natts, | ||
VacAttrStats ** | vacattrstats | ||
) |
Definition at line 261 of file extended_stats.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, bms_num_members(), StatExtEntry::columns, CurrentMemoryContext, StatExtEntry::exprs, fetch_statentries_for_relation(), lfirst, lookup_var_attr_stats(), MemoryContextDelete(), MemoryContextSwitchTo(), RelationGetRelid, RowExclusiveLock, statext_compute_stattarget(), StatExtEntry::stattarget, table_close(), and table_open().
Referenced by do_analyze_rel().
|
static |
Definition at line 523 of file extended_stats.c.
References VacAttrStats::anl_context, VacAttrStats::attr, VacAttrStats::attrcollid, ATTRIBUTE_FIXED_PART_SIZE, VacAttrStats::attrtype, VacAttrStats::attrtypid, VacAttrStats::attrtypmod, 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(), VacAttrStats::tupattnum, and TYPEOID.
Referenced by lookup_var_attr_stats().
|
static |
Definition at line 607 of file extended_stats.c.
References VacAttrStats::anl_context, Assert, VacAttrStats::attr, VacAttrStats::attrcollid, ATTRIBUTE_FIXED_PART_SIZE, VacAttrStats::attrtype, VacAttrStats::attrtypid, VacAttrStats::attrtypmod, VacAttrStats::compute_stats, CurrentMemoryContext, DatumGetBool, elog, ERROR, exprCollation(), exprType(), exprTypmod(), GETSTRUCT, heap_freetuple(), HeapTupleIsValid, i, InvalidAttrNumber, InvalidOid, VacAttrStats::minrows, ObjectIdGetDatum, OidFunctionCall1, OidIsValid, palloc(), palloc0(), pfree(), PointerGetDatum, SearchSysCacheCopy1, STATISTIC_NUM_SLOTS, StatExtEntry::stattarget, VacAttrStats::statypalign, VacAttrStats::statypbyval, VacAttrStats::statypid, VacAttrStats::statyplen, std_typanalyze(), VacAttrStats::tupattnum, and TYPEOID.
Referenced by build_expr_data(), and make_build_data().
Definition at line 2021 of file extended_stats.c.
References arg, Assert, IsA, linitial, list_length(), and lsecond.
Referenced by mcv_get_match_bitmap(), and statext_is_compatible_clause_internal().
|
static |
Definition at line 2221 of file extended_stats.c.
References VacAttrStats::exprnulls, VacAttrStats::exprvals, i, and VacAttrStats::rowstride.
Referenced by compute_expr_stats().
Definition at line 418 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, 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, STATEXTOID, StatisticExtRelidIndexId, StatExtEntry::statOid, StatExtEntry::stattarget, stringToNode(), SysCacheGetAttr(), systable_beginscan(), systable_endscan(), systable_getnext(), TextDatumGetCString, and StatExtEntry::types.
Referenced by BuildRelationExtStatistics(), and ComputeExtStatisticsRows().
Definition at line 1142 of file extended_stats.c.
References StatisticExtInfo::kind, and lfirst.
Referenced by dependencies_clauselist_selectivity(), and statext_mcv_clauselist_selectivity().
|
static |
Definition at line 705 of file extended_stats.c.
References Assert, bms_next_member(), bms_num_members(), examine_attribute(), i, lfirst, list_length(), palloc(), pfree(), and VacAttrStats::tupDesc.
Referenced by BuildRelationExtStatistics(), and ComputeExtStatisticsRows().
|
static |
Definition at line 2440 of file extended_stats.c.
References Assert, StatsBuildData::attnums, bms_next_member(), bms_num_members(), StatExtEntry::columns, CreateExecutorState(), ExprContext::ecxt_scantuple, examine_expression(), ExecDropSingleTupleTableSlot(), ExecEvalExpr(), ExecPrepareExprList(), ExecStoreHeapTuple(), StatExtEntry::exprs, FreeExecutorState(), GetPerTupleExprContext, heap_getattr, i, idx(), lfirst, list_length(), MakeSingleTupleTableSlot(), MAXALIGN, NIL, StatsBuildData::nulls, palloc(), RelationGetDescr, ResetExprContext, StatsBuildData::stats, TTSOpsHeapTuple, and StatsBuildData::values.
Referenced by BuildRelationExtStatistics().
void multi_sort_add_dimension | ( | MultiSortSupport | mss, |
int | sortdim, | ||
Oid | oper, | ||
Oid | collation | ||
) |
Definition at line 875 of file extended_stats.c.
References CurrentMemoryContext, 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 889 of file extended_stats.c.
References ApplySortComparator(), 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 914 of file extended_stats.c.
References ApplySortComparator(), SortItem::isnull, MultiSortSupportData::ssup, and SortItem::values.
Referenced by dependency_degree().
int multi_sort_compare_dims | ( | int | start, |
int | end, | ||
const SortItem * | a, | ||
const SortItem * | b, | ||
MultiSortSupport | mss | ||
) |
Definition at line 923 of file extended_stats.c.
References ApplySortComparator(), SortItem::isnull, MultiSortSupportData::ssup, and SortItem::values.
Referenced by dependency_degree().
MultiSortSupport multi_sort_init | ( | int | ndims | ) |
Definition at line 856 of file extended_stats.c.
References Assert, MultiSortSupportData::ndims, offsetof, and palloc0().
Referenced by build_mss(), dependency_degree(), and ndistinct_for_combination().
|
static |
Definition at line 2262 of file extended_stats.c.
References accumArrayResult(), BoolGetDatum, construct_array(), 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 1192 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 1165 of file extended_stats.c.
References equal(), StatisticExtInfo::exprs, 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 1970 of file extended_stats.c.
References dependencies_clauselist_selectivity(), and statext_mcv_clauselist_selectivity().
Referenced by clauselist_selectivity_ext(), and clauselist_selectivity_or().
|
static |
Definition at line 343 of file extended_stats.c.
References Assert, VacAttrStats::attr, default_statistics_target, i, and StatExtEntry::stattarget.
Referenced by BuildRelationExtStatistics(), and ComputeExtStatisticsRows().
Definition at line 2394 of file extended_stats.c.
References DatumGetExpandedArray(), DatumGetHeapTupleHeader, deconstruct_expanded_array(), ExpandedArrayHeader::dvalues, elog, ERROR, heap_copytuple(), HeapTupleHeaderGetDatumLength, HeapTupleIsValid, InvalidOid, ItemPointerSetInvalid, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1(), STATEXTDATASTXOID, SysCacheGetAttr(), HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, and value.
Referenced by examine_variable().
|
static |
Definition at line 1554 of file extended_stats.c.
References ACL_SELECT, ACLCHECK_OK, ACLMASK_ALL, BoolExpr::args, attnum, bms_add_members(), bms_get_singleton_member(), bms_is_member(), bms_next_member(), RangeTblEntry::checkAsUser, RestrictInfo::clause, RestrictInfo::clause_relids, StatExtEntry::exprs, GetUserId(), InvalidAttrNumber, is_andclause(), IsA, lfirst, NIL, pg_attribute_aclcheck(), pg_attribute_aclcheck_all(), pg_class_aclcheck(), RestrictInfo::pseudoconstant, pull_varattnos(), RangeTblEntry::relid, PlannerInfo::simple_rte_array, and statext_is_compatible_clause_internal().
Referenced by statext_mcv_clauselist_selectivity().
|
static |
Definition at line 1320 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, RangeTblEntry::securityQuals, PlannerInfo::simple_rte_array, Var::varattno, Var::varlevelsup, and Var::varno.
Referenced by statext_is_compatible_clause().
Definition at line 385 of file extended_stats.c.
References attnum, elog, ERROR, and heap_attisnull().
Referenced by get_relation_statistics().
|
static |
Definition at line 1683 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(), StatExtEntry::exprs, has_stats_of_kind(), StatisticExtInfo::keys, StatisticExtInfo::kind, lappend(), lfirst, list_free(), list_length(), mcv_clause_selectivity_or(), mcv_clauselist_selectivity(), mcv_combine_selectivities(), NIL, palloc(), RelOptInfo::relid, stat, stat_covers_expressions(), statext_is_compatible_clause(), statext_mcv_load(), RelOptInfo::statlist, and StatisticExtInfo::statOid.
Referenced by statext_clauselist_selectivity().
|
static |
Definition at line 780 of file extended_stats.c.
References CatalogTupleUpdate(), elog, ERROR, StatExtEntry::exprs, heap_freetuple(), heap_modify_tuple(), HeapTupleIsValid, ObjectIdGetDatum, PointerGetDatum, RelationGetDescr, ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), statext_dependencies_serialize(), statext_mcv_serialize(), statext_ndistinct_serialize(), STATEXTDATASTXOID, HeapTupleData::t_self, table_close(), table_open(), and values.
Referenced by BuildRelationExtStatistics().