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-2020, 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: */
48  SortSupportData ssup[FLEXIBLE_ARRAY_MEMBER];
50 
52 
53 typedef struct SortItem
54 {
56  bool *isnull;
57  int count;
58 } SortItem;
59 
60 extern MVNDistinct *statext_ndistinct_build(double totalrows,
61  int numrows, HeapTuple *rows,
62  Bitmapset *attrs, VacAttrStats **stats);
65 
66 extern MVDependencies *statext_dependencies_build(int numrows, HeapTuple *rows,
67  Bitmapset *attrs, VacAttrStats **stats);
70 
71 extern MCVList *statext_mcv_build(int numrows, HeapTuple *rows,
72  Bitmapset *attrs, VacAttrStats **stats,
73  double totalrows, int stattarget);
74 extern bytea *statext_mcv_serialize(MCVList *mcv, VacAttrStats **stats);
76 
77 extern MultiSortSupport multi_sort_init(int ndims);
78 extern void multi_sort_add_dimension(MultiSortSupport mss, int sortdim,
79  Oid oper, Oid collation);
80 extern int multi_sort_compare(const void *a, const void *b, void *arg);
81 extern int multi_sort_compare_dim(int dim, const SortItem *a,
82  const SortItem *b, MultiSortSupport mss);
83 extern int multi_sort_compare_dims(int start, int end, const SortItem *a,
84  const SortItem *b, MultiSortSupport mss);
85 extern int compare_scalars_simple(const void *a, const void *b, void *arg);
86 extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup);
87 
88 extern void *bsearch_arg(const void *key, const void *base,
89  size_t nmemb, size_t size,
90  int (*compar) (const void *, const void *, void *),
91  void *arg);
92 
93 extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs);
94 
95 extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows,
96  TupleDesc tdesc, MultiSortSupport mss,
97  int numattrs, AttrNumber *attnums);
98 
99 extern bool examine_opclause_expression(OpExpr *expr, Var **varp,
100  Const **cstp, bool *varonleftp);
101 
104  List *clauses,
105  int varRelid,
106  JoinType jointype,
107  SpecialJoinInfo *sjinfo,
108  RelOptInfo *rel,
109  Selectivity *basesel,
110  Selectivity *totalsel);
111 
112 #endif /* EXTENDED_STATS_INTERNAL_H */
int multi_sort_compare(const void *a, const void *b, void *arg)
void * bsearch_arg(const void *key, const void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *, void *), void *arg)
void multi_sort_add_dimension(MultiSortSupport mss, int sortdim, Oid oper, Oid collation)
struct DimensionInfo DimensionInfo
MVDependencies * statext_dependencies_build(int numrows, HeapTuple *rows, Bitmapset *attrs, VacAttrStats **stats)
Definition: dependencies.c:357
double Selectivity
Definition: nodes.h:658
unsigned int Oid
Definition: postgres_ext.h:31
Definition: primnodes.h:181
int compare_scalars_simple(const void *a, const void *b, void *arg)
bytea * statext_ndistinct_serialize(MVNDistinct *ndistinct)
Definition: mvdistinct.c:171
JoinType
Definition: nodes.h:692
MVNDistinct * statext_ndistinct_build(double totalrows, int numrows, HeapTuple *rows, Bitmapset *attrs, VacAttrStats **stats)
Definition: mvdistinct.c:86
int multi_sort_compare_dims(int start, int end, const SortItem *a, const SortItem *b, MultiSortSupport mss)
AttrNumber * build_attnums_array(Bitmapset *attrs, int *numattrs)
bytea * statext_mcv_serialize(MCVList *mcv, VacAttrStats **stats)
Definition: mcv.c:618
MCVList * statext_mcv_deserialize(bytea *data)
Definition: mcv.c:992
MVNDistinct * statext_ndistinct_deserialize(bytea *data)
Definition: mvdistinct.c:249
bytea * statext_dependencies_serialize(MVDependencies *dependencies)
Definition: dependencies.c:446
#define stat(a, b)
Definition: win32_port.h:255
MCVList * statext_mcv_build(int numrows, HeapTuple *rows, Bitmapset *attrs, VacAttrStats **stats, double totalrows, int stattarget)
Definition: mcv.c:183
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:1794
uintptr_t Datum
Definition: postgres.h:367
struct SortItem SortItem
MVDependencies * statext_dependencies_deserialize(bytea *data)
Definition: dependencies.c:501
int compare_datums_simple(Datum a, Datum b, SortSupport ssup)
struct MultiSortSupportData MultiSortSupportData
int multi_sort_compare_dim(int dim, const SortItem *a, const SortItem *b, MultiSortSupport mss)
MultiSortSupport multi_sort_init(int ndims)
bool examine_opclause_expression(OpExpr *expr, Var **varp, Const **cstp, bool *varonleftp)
void * arg
SortItem * build_sorted_items(int numrows, int *nitems, HeapTuple *rows, TupleDesc tdesc, MultiSortSupport mss, int numattrs, AttrNumber *attnums)
Definition: c.h:556
MultiSortSupportData * MultiSortSupport
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:377
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21