PostgreSQL Source Code git master
|
#include "postgres.h"
#include <math.h>
#include "access/htup_details.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_statistic_ext_data.h"
#include "fmgr.h"
#include "funcapi.h"
#include "nodes/nodeFuncs.h"
#include "statistics/extended_stats_internal.h"
#include "statistics/statistics.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/fmgrprotos.h"
#include "utils/lsyscache.h"
#include "utils/selfuncs.h"
#include "utils/syscache.h"
#include "utils/typcache.h"
Go to the source code of this file.
Macros | |
#define | ITEM_SIZE(ndims) ((ndims) * (sizeof(uint16) + sizeof(bool)) + 2 * sizeof(double)) |
#define | MinSizeOfMCVList (VARHDRSZ + sizeof(uint32) * 3 + sizeof(AttrNumber)) |
#define | SizeOfMCVList(ndims, nitems) |
#define | RESULT_MERGE(value, is_or, match) ((is_or) ? ((value) || (match)) : ((value) && (match))) |
#define | RESULT_IS_FINAL(value, is_or) ((is_or) ? (value) : (!(value))) |
#define ITEM_SIZE | ( | ndims | ) | ((ndims) * (sizeof(uint16) + sizeof(bool)) + 2 * sizeof(double)) |
#define MinSizeOfMCVList (VARHDRSZ + sizeof(uint32) * 3 + sizeof(AttrNumber)) |
#define SizeOfMCVList | ( | ndims, | |
nitems | |||
) |
|
static |
Definition at line 490 of file mcv.c.
References Assert, SortItem::count, i, SortItem::isnull, MAXALIGN, MultiSortSupportData::ndims, palloc(), qsort_interruptible(), sort_item_compare(), MultiSortSupportData::ssup, and SortItem::values.
Referenced by statext_mcv_build().
|
static |
Definition at line 424 of file mcv.c.
References Assert, compare_sort_item_count(), SortItem::count, count_distinct_groups(), i, items, j, multi_sort_compare(), palloc(), and qsort_interruptible().
Referenced by statext_mcv_build().
|
static |
Definition at line 347 of file mcv.c.
References VacAttrStats::attrcollid, VacAttrStats::attrtypid, data, elog, ERROR, i, InvalidOid, lookup_type_cache(), multi_sort_add_dimension(), multi_sort_init(), type, and TYPECACHE_LT_OPR.
Referenced by statext_mcv_build().
|
static |
Definition at line 403 of file mcv.c.
References a, b, and SortItem::count.
Referenced by build_distinct_groups().
|
static |
Definition at line 379 of file mcv.c.
References Assert, i, items, and multi_sort_compare().
Referenced by build_distinct_groups().
|
static |
Definition at line 148 of file mcv.c.
Referenced by statext_mcv_build().
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 | ||
) |
Definition at line 2126 of file mcv.c.
References MCVItem::base_frequency, MCVItem::frequency, i, MCVList::items, list_make1, mcv_get_match_bitmap(), MCVList::nitems, palloc0(), pfree(), and root.
Referenced by statext_mcv_clauselist_selectivity().
Selectivity mcv_clauselist_selectivity | ( | PlannerInfo * | root, |
StatisticExtInfo * | stat, | ||
List * | clauses, | ||
int | varRelid, | ||
JoinType | jointype, | ||
SpecialJoinInfo * | sjinfo, | ||
RelOptInfo * | rel, | ||
Selectivity * | basesel, | ||
Selectivity * | totalsel | ||
) |
Definition at line 2048 of file mcv.c.
References MCVItem::base_frequency, MCVItem::frequency, i, RangeTblEntry::inh, MCVList::items, mcv_get_match_bitmap(), MCVList::nitems, RelOptInfo::relid, root, and statext_mcv_load().
Referenced by statext_mcv_clauselist_selectivity().
Selectivity mcv_combine_selectivities | ( | Selectivity | simple_sel, |
Selectivity | mcv_sel, | ||
Selectivity | mcv_basesel, | ||
Selectivity | mcv_totalsel | ||
) |
Definition at line 2006 of file mcv.c.
References CLAMP_PROBABILITY.
Referenced by statext_mcv_clauselist_selectivity().
|
static |
Definition at line 1599 of file mcv.c.
References NullTest::arg, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, ARR_ELEMTYPE, Assert, bms_member_index(), collid, DatumGetArrayTypeP, DatumGetBool(), deconstruct_array(), elog, ERROR, examine_opclause_args(), fmgr_info(), FunctionCall2Coll(), get_opcode(), get_typlenbyvalalign(), i, idx(), is_andclause(), IS_NOT_NULL, is_notclause(), IS_NULL, is_opclause(), is_orclause(), IsA, MCVItem::isnull, MCVList::items, j, lfirst, list_length(), mcv_get_match_bitmap(), mcv_match_expression(), NIL, MCVList::nitems, NullTest::nulltesttype, OpExpr::opno, ScalarArrayOpExpr::opno, palloc(), pfree(), RESULT_IS_FINAL, RESULT_MERGE, root, STATS_MCVLIST_MAX_ITEMS, ScalarArrayOpExpr::useOr, MCVItem::values, and Var::varattno.
Referenced by mcv_clause_selectivity_or(), mcv_clauselist_selectivity(), and mcv_get_match_bitmap().
|
static |
Definition at line 1535 of file mcv.c.
References bms_member_index(), bms_num_members(), collid, elog, equal(), ERROR, exprCollation(), idx(), IsA, lfirst, and Var::varattno.
Referenced by mcv_get_match_bitmap().
Datum pg_mcv_list_in | ( | PG_FUNCTION_ARGS | ) |
Datum pg_mcv_list_out | ( | PG_FUNCTION_ARGS | ) |
Datum pg_mcv_list_recv | ( | PG_FUNCTION_ARGS | ) |
Datum pg_mcv_list_send | ( | PG_FUNCTION_ARGS | ) |
Datum pg_stats_ext_mcvlist_items | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1338 of file mcv.c.
References accumArrayResult(), Assert, FuncCallContext::attinmeta, MCVItem::base_frequency, BlessTupleDesc(), BoolGetDatum(), FuncCallContext::call_cntr, cstring_to_text(), CurrentMemoryContext, DatumGetPointer(), ereport, errcode(), errmsg(), ERROR, Float8GetDatum(), fmgr_info(), MCVItem::frequency, FunctionCall1, get_call_result_type(), getTypeOutputInfo(), heap_form_tuple(), HeapTupleGetDatum(), i, Int32GetDatum(), MCVItem::isnull, MCVList::items, makeArrayResult(), FuncCallContext::max_calls, MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, MCVList::ndimensions, MCVList::nitems, PG_GETARG_BYTEA_P, PointerGetDatum(), SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, statext_mcv_deserialize(), AttInMetadata::tupdesc, TupleDescGetAttInMetadata(), TYPEFUNC_COMPOSITE, MCVList::types, FuncCallContext::user_fctx, val, values, and MCVItem::values.
|
static |
Definition at line 465 of file mcv.c.
References a, ApplySortComparator(), arg, b, SortItem::isnull, and SortItem::values.
Referenced by build_column_frequencies().
MCVList * statext_mcv_build | ( | StatsBuildData * | data, |
double | totalrows, | ||
int | stattarget | ||
) |
Definition at line 180 of file mcv.c.
References Assert, MCVItem::base_frequency, bsearch_arg(), build_column_frequencies(), build_distinct_groups(), build_mss(), build_sorted_items(), SortItem::count, data, for(), MCVItem::frequency, get_mincount_for_mcv_list(), i, SortItem::isnull, MCVItem::isnull, MCVList::items, items, j, sort-test::key, MCVList::magic, multi_sort_compare(), MCVList::ndimensions, MultiSortSupportData::ndims, MCVList::nitems, nitems, palloc(), palloc0(), pfree(), MultiSortSupportData::ssup, STATS_MCV_MAGIC, STATS_MCV_TYPE_BASIC, MCVList::type, MCVList::types, SortItem::values, and MCVItem::values.
Referenced by BuildRelationExtStatistics().
Definition at line 996 of file mcv.c.
References Assert, MCVItem::base_frequency, data, elog, ERROR, fetch_att(), MCVItem::frequency, i, MCVItem::isnull, MCVList::items, items, len, MCVList::magic, MAXALIGN, MinSizeOfMCVList, DimensionInfo::nbytes, DimensionInfo::nbytes_aligned, MCVList::ndimensions, MCVList::nitems, nitems, DimensionInfo::nvalues, palloc(), palloc0(), pfree(), PG_USED_FOR_ASSERTS_ONLY, PointerGetDatum(), repalloc(), SET_VARSIZE, SizeOfMCVList, start, STATS_MAX_DIMENSIONS, STATS_MCV_MAGIC, STATS_MCV_TYPE_BASIC, STATS_MCVLIST_MAX_ITEMS, MCVList::type, MCVList::types, DimensionInfo::typlen, MCVItem::values, VARDATA, VARDATA_ANY, VARHDRSZ, and VARSIZE_ANY.
Referenced by pg_stats_ext_mcvlist_items(), and statext_mcv_load().
Definition at line 558 of file mcv.c.
References BoolGetDatum(), DatumGetByteaP, elog, ERROR, HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache2(), statext_mcv_deserialize(), and SysCacheGetAttr().
Referenced by mcv_clauselist_selectivity(), and statext_mcv_clauselist_selectivity().
bytea * statext_mcv_serialize | ( | MCVList * | mcvlist, |
VacAttrStats ** | stats | ||
) |
Definition at line 621 of file mcv.c.
References Assert, VacAttrStats::attrcollid, VacAttrStats::attrtype, MCVItem::base_frequency, bsearch_arg(), compare_datums_simple(), compare_scalars_simple(), CurrentMemoryContext, DatumGetCString(), DatumGetPointer(), MCVItem::frequency, i, MCVItem::isnull, ITEM_SIZE, MCVList::items, len, lookup_type_cache(), TypeCacheEntry::lt_opr, MCVList::magic, MAXALIGN, DimensionInfo::nbytes, DimensionInfo::nbytes_aligned, MCVList::ndimensions, MCVList::nitems, DimensionInfo::nvalues, palloc0(), pfree(), PG_DETOAST_DATUM, PG_UINT16_MAX, PG_USED_FOR_ASSERTS_ONLY, PointerGetDatum(), PrepareSortSupportFromOrderingOp(), qsort_interruptible(), SET_VARSIZE, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, SortSupportData::ssup_nulls_first, start, store_att_byval(), DimensionInfo::typbyval, MCVList::type, TYPECACHE_LT_OPR, MCVList::types, DimensionInfo::typlen, value, values, MCVItem::values, VARDATA, VARDATA_ANY, VARHDRSZ, and VARSIZE_ANY_EXHDR.
Referenced by statext_store().