PostgreSQL Source Code  git master
extended_stats_internal.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * extended_stats_internal.h
4  * POSTGRES extended statistics internal declarations
5  *
6  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * IDENTIFICATION
10  * src/include/statistics/extended_stats_internal.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef EXTENDED_STATS_INTERNAL_H
15 #define EXTENDED_STATS_INTERNAL_H
16 
17 #include "statistics/statistics.h"
18 #include "utils/sortsupport.h"
19 
20 typedef struct
21 {
22  Oid eqopr; /* '=' operator for datatype, if any */
23  Oid eqfunc; /* and associated function */
24  Oid ltopr; /* '<' operator for datatype, if any */
26 
27 typedef struct
28 {
29  Datum value; /* a data value */
30  int tupno; /* position index for tuple it came from */
31 } ScalarItem;
32 
33 /* (de)serialization info */
34 typedef struct DimensionInfo
35 {
36  int nvalues; /* number of deduplicated values */
37  int nbytes; /* number of bytes (serialized) */
38  int nbytes_aligned; /* size of deserialized data with alignment */
39  int typlen; /* pg_type.typlen */
40  bool typbyval; /* pg_type.typbyval */
42 
43 /* multi-sort */
44 typedef struct MultiSortSupportData
45 {
46  int ndims; /* number of dimensions */
47  /* sort support data for each dimension: */
50 
52 
53 typedef struct SortItem
54 {
56  bool *isnull;
57  int count;
58 } SortItem;
59 
60 /* a unified representation of the data the statistics is built on */
61 typedef struct StatsBuildData
62 {
63  int numrows;
64  int nattnums;
68  bool **nulls;
70 
71 
72 extern MVNDistinct *statext_ndistinct_build(double totalrows, StatsBuildData *data);
75 
79 
81  double totalrows, int stattarget);
82 extern bytea *statext_mcv_serialize(MCVList *mcv, VacAttrStats **stats);
84 
85 extern MultiSortSupport multi_sort_init(int ndims);
86 extern void multi_sort_add_dimension(MultiSortSupport mss, int sortdim,
87  Oid oper, Oid collation);
88 extern int multi_sort_compare(const void *a, const void *b, void *arg);
89 extern int multi_sort_compare_dim(int dim, const SortItem *a,
90  const SortItem *b, MultiSortSupport mss);
91 extern int multi_sort_compare_dims(int start, int end, const SortItem *a,
92  const SortItem *b, MultiSortSupport mss);
93 extern int compare_scalars_simple(const void *a, const void *b, void *arg);
94 extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup);
95 
96 extern AttrNumber *build_attnums_array(Bitmapset *attrs, int nexprs, int *numattrs);
97 
98 extern SortItem *build_sorted_items(StatsBuildData *data, int *nitems,
99  MultiSortSupport mss,
100  int numattrs, AttrNumber *attnums);
101 
102 extern bool examine_opclause_args(List *args, Node **exprp,
103  Const **cstp, bool *expronleftp);
104 
106  Selectivity mcv_sel,
107  Selectivity mcv_basesel,
108  Selectivity mcv_totalsel);
109 
112  List *clauses,
113  int varRelid,
114  JoinType jointype,
115  SpecialJoinInfo *sjinfo,
116  RelOptInfo *rel,
117  Selectivity *basesel,
118  Selectivity *totalsel);
119 
122  MCVList *mcv,
123  Node *clause,
124  bool **or_matches,
125  Selectivity *basesel,
126  Selectivity *overlap_mcvsel,
127  Selectivity *overlap_basesel,
128  Selectivity *totalsel);
129 
130 #endif /* EXTENDED_STATS_INTERNAL_H */
int multi_sort_compare(const void *a, const void *b, void *arg)
void multi_sort_add_dimension(MultiSortSupport mss, int sortdim, Oid oper, Oid collation)
SortItem * build_sorted_items(StatsBuildData *data, int *nitems, MultiSortSupport mss, int numattrs, AttrNumber *attnums)
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:350
Definition: nodes.h:536
struct DimensionInfo DimensionInfo
double Selectivity
Definition: nodes.h:669
unsigned int Oid
Definition: postgres_ext.h:31
MVDependencies * statext_dependencies_build(StatsBuildData *data)
Definition: dependencies.c:355
int compare_scalars_simple(const void *a, const void *b, void *arg)
bytea * statext_ndistinct_serialize(MVNDistinct *ndistinct)
Definition: mvdistinct.c:179
JoinType
Definition: nodes.h:704
AttrNumber * build_attnums_array(Bitmapset *attrs, int nexprs, int *numattrs)
int multi_sort_compare_dims(int start, int end, const SortItem *a, const SortItem *b, MultiSortSupport mss)
bytea * statext_mcv_serialize(MCVList *mcv, VacAttrStats **stats)
Definition: mcv.c:624
Selectivity mcv_combine_selectivities(Selectivity simple_sel, Selectivity mcv_sel, Selectivity mcv_basesel, Selectivity mcv_totalsel)
Definition: mcv.c:1991
MCVList * statext_mcv_deserialize(bytea *data)
Definition: mcv.c:999
MVNDistinct * statext_ndistinct_deserialize(bytea *data)
Definition: mvdistinct.c:250
bytea * statext_dependencies_serialize(MVDependencies *dependencies)
Definition: dependencies.c:436
struct StatsBuildData StatsBuildData
bool examine_opclause_args(List *args, Node **exprp, Const **cstp, bool *expronleftp)
MVNDistinct * statext_ndistinct_build(double totalrows, StatsBuildData *data)
Definition: mvdistinct.c:89
Selectivity mcv_clauselist_selectivity(PlannerInfo *root, StatisticExtInfo *stat, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, RelOptInfo *rel, Selectivity *basesel, Selectivity *totalsel)
Definition: mcv.c:2033
uintptr_t Datum
Definition: postgres.h:411
struct SortItem SortItem
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: mcv.c:2110
MVDependencies * statext_dependencies_deserialize(bytea *data)
Definition: dependencies.c:491
int compare_datums_simple(Datum a, Datum b, SortSupport ssup)
VacAttrStats ** stats
MCVList * statext_mcv_build(StatsBuildData *data, double totalrows, int stattarget)
Definition: mcv.c:184
struct MultiSortSupportData MultiSortSupportData
int multi_sort_compare_dim(int dim, const SortItem *a, const SortItem *b, MultiSortSupport mss)
MultiSortSupport multi_sort_init(int ndims)
void * arg
Definition: c.h:621
MultiSortSupportData * MultiSortSupport
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:382
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21