24#include "utils/fmgroids.h"
32#define SizeOfHeader (3 * sizeof(uint32))
35#define SizeOfItem(natts) \
36 (sizeof(double) + sizeof(AttrNumber) * (1 + (natts)))
39#define MinSizeOfItem SizeOfItem(2)
42#define MinSizeOfItems(ndeps) \
43 (SizeOfHeader + (ndeps) * MinSizeOfItem)
143 state->ndependencies++;
171 Assert((n >= k) && (k > 0));
177 state->ndependencies = 0;
241 for (
i = 0;
i < k;
i++)
258 for (
i = 0;
i < k;
i++)
265 elog(
ERROR,
"cache lookup failed for ordering operator for type %u",
355 "dependency_degree cxt",
364 for (k = 2; k <=
data->nattnums; k++)
399 for (
i = 0;
i < k;
i++)
403 if (dependencies ==
NULL)
409 dependencies->
ndeps = 0;
412 dependencies->
ndeps++;
417 dependencies->
deps[dependencies->
ndeps - 1] = d;
448 for (
i = 0;
i < dependencies->
ndeps;
i++)
465 for (
i = 0;
i < dependencies->
ndeps;
i++)
503 elog(
ERROR,
"invalid MVDependencies size %zu (expected at least %zu)",
521 elog(
ERROR,
"invalid dependency magic %d (expected %d)",
525 elog(
ERROR,
"invalid dependency type %d (expected %d)",
528 if (dependencies->
ndeps == 0)
529 elog(
ERROR,
"invalid zero-length item array in MVDependencies");
535 elog(
ERROR,
"invalid dependencies size %zu (expected at least %zu)",
542 for (
i = 0;
i < dependencies->
ndeps;
i++)
549 memcpy(°ree, tmp,
sizeof(
double));
570 dependencies->
deps[
i] = d;
588 for (
int i = 0;
i < dependencies->
ndeps;
i++)
613 for (
int i = 0;
i < dependencies->
ndeps;
i++)
621 for (
int j = 0;
j <
dep->nattributes;
j++)
629 for (
int k = 0; k <
stxkeys->dim1; k++)
648 errmsg(
"could not validate \"%s\" object: invalid attribute number %d found",
649 "pg_dependencies",
attnum)));
699 elog(
ERROR,
"cache lookup failed for statistics object %u",
mvoid);
705 "requested statistics kind \"%c\" is not yet built for statistics object %u",
735 if (rinfo->pseudoconstant)
881 if (var->
varno != relid)
928 for (
i = 0;
i < ndependencies;
i++)
930 for (
j = 0;
j < dependencies[
i]->
ndeps;
j++)
1022 for (
i = 0;
i < ndependencies;
i++)
1060 jointype, sjinfo,
false);
1088 for (
i = ndependencies - 1;
i >= 0;
i--)
1132 for (
i = 0;
i < nattrs;
i++)
1163 if (rinfo->pseudoconstant)
1303 foreach(
lc, statlist)
1562 if (
stat->inherit !=
rte->inh)
1649 for (
j = 0;
j <
dep->nattributes;
j++)
1739 deps->
ndeps = ndeps;
1746 if (deps->
ndeps > 0)
1783 dependencies[ndependencies++] = dependency;
1794 if (ndependencies != 0)
1796 sjinfo, dependencies, ndependencies,
1803 pfree(dependencies);
Datum idx(PG_FUNCTION_ARGS)
#define AttributeNumberIsValid(attributeNumber)
#define AttrNumberIsForUserDefinedAttr(attributeNumber)
#define InvalidAttrNumber
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_del_member(Bitmapset *a, int x)
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)
BMS_Membership bms_membership(const Bitmapset *a)
int bms_member_index(Bitmapset *a, int x)
#define Assert(condition)
bool is_pseudo_constant_clause(Node *clause)
Selectivity clauselist_selectivity_ext(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, bool use_extended_stats)
static void generate_dependencies(DependencyGenerator state)
MVDependencies * statext_dependencies_deserialize(bytea *data)
MVDependencies * statext_dependencies_load(Oid mvoid, bool inh)
static bool dependency_is_compatible_expression(Node *clause, Index relid, List *statlist, Node **expr)
static AttrNumber * DependencyGenerator_next(DependencyGenerator state)
MVDependencies * statext_dependencies_build(StatsBuildData *data)
static bool dependency_is_compatible_clause(Node *clause, Index relid, AttrNumber *attnum)
bool statext_dependencies_validate(const MVDependencies *dependencies, const int2vector *stxkeys, int numexprs, int elevel)
static bool dependency_is_fully_matched(MVDependency *dependency, Bitmapset *attnums)
bytea * statext_dependencies_serialize(MVDependencies *dependencies)
void statext_dependencies_free(MVDependencies *dependencies)
static void DependencyGenerator_free(DependencyGenerator state)
static Selectivity clauselist_apply_dependencies(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, MVDependency **dependencies, int ndependencies, AttrNumber *list_attnums, Bitmapset **estimatedclauses)
static DependencyGenerator DependencyGenerator_init(int n, int k)
#define SizeOfItem(natts)
Selectivity dependencies_clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, RelOptInfo *rel, Bitmapset **estimatedclauses)
static double dependency_degree(StatsBuildData *data, int k, AttrNumber *dependency)
static void generate_dependencies_recurse(DependencyGenerator state, int index, AttrNumber start, AttrNumber *current)
DependencyGeneratorData * DependencyGenerator
static MVDependency * find_strongest_dependency(MVDependencies **dependencies, int ndependencies, Bitmapset *attnums)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
bool has_stats_of_kind(List *stats, char requiredkind)
int multi_sort_compare_dims(int start, int end, const SortItem *a, const SortItem *b, MultiSortSupport mss)
int multi_sort_compare_dim(int dim, const SortItem *a, const SortItem *b, MultiSortSupport mss)
SortItem * build_sorted_items(StatsBuildData *data, int *nitems, MultiSortSupport mss, int numattrs, AttrNumber *attnums)
MultiSortSupport multi_sort_init(int ndims)
void multi_sort_add_dimension(MultiSortSupport mss, int sortdim, Oid oper, Oid collation)
#define palloc_array(type, count)
#define palloc0_array(type, count)
#define palloc0_object(type)
#define DatumGetByteaPP(X)
#define HeapTupleIsValid(tuple)
#define MaxHeapAttributeNumber
List * lappend(List *list, void *datum)
RegProcedure get_oprrest(Oid opno)
void MemoryContextReset(MemoryContext context)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
static bool is_orclause(const void *clause)
static bool is_opclause(const void *clause)
static bool is_notclause(const void *clause)
static Expr * get_notclausearg(const void *notclause)
#define IsA(nodeptr, _type_)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define planner_rt_fetch(rti, root)
static const struct exclude_list_item skip[]
static int list_length(const List *l)
static void * list_nth(const List *list, int n)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
#define CLAMP_PROBABILITY(p)
#define STATS_MAX_DIMENSIONS
#define STATS_DEPS_TYPE_BASIC
AttrNumber * dependencies
MVDependency * deps[FLEXIBLE_ARRAY_MEMBER]
AttrNumber attributes[FLEXIBLE_ARRAY_MEMBER]
void ReleaseSysCache(HeapTuple tuple)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
static Size VARSIZE_ANY(const void *PTR)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static char * VARDATA(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)