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-2019, 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 "utils/sortsupport.h"
18 #include "statistics/statistics.h"
19 
20 
21 typedef struct
22 {
23  Oid eqopr; /* '=' operator for datatype, if any */
24  Oid eqfunc; /* and associated function */
25  Oid ltopr; /* '<' operator for datatype, if any */
27 
28 typedef struct
29 {
30  Datum value; /* a data value */
31  int tupno; /* position index for tuple it came from */
32 } ScalarItem;
33 
34 /* (de)serialization info */
35 typedef struct DimensionInfo
36 {
37  int nvalues; /* number of deduplicated values */
38  int nbytes; /* number of bytes (serialized) */
39  int nbytes_aligned; /* size of deserialized data with alignment */
40  int typlen; /* pg_type.typlen */
41  bool typbyval; /* pg_type.typbyval */
43 
44 /* multi-sort */
45 typedef struct MultiSortSupportData
46 {
47  int ndims; /* number of dimensions */
48  /* sort support data for each dimension: */
49  SortSupportData ssup[FLEXIBLE_ARRAY_MEMBER];
51 
53 
54 typedef struct SortItem
55 {
57  bool *isnull;
58  int count;
59 } SortItem;
60 
61 extern MVNDistinct *statext_ndistinct_build(double totalrows,
62  int numrows, HeapTuple *rows,
63  Bitmapset *attrs, VacAttrStats **stats);
66 
67 extern MVDependencies *statext_dependencies_build(int numrows, HeapTuple *rows,
68  Bitmapset *attrs, VacAttrStats **stats);
71 
72 extern MCVList *statext_mcv_build(int numrows, HeapTuple *rows,
73  Bitmapset *attrs, VacAttrStats **stats,
74  double totalrows, int stattarget);
75 extern bytea *statext_mcv_serialize(MCVList *mcv, VacAttrStats **stats);
77 
78 extern MultiSortSupport multi_sort_init(int ndims);
79 extern void multi_sort_add_dimension(MultiSortSupport mss, int sortdim,
80  Oid oper, Oid collation);
81 extern int multi_sort_compare(const void *a, const void *b, void *arg);
82 extern int multi_sort_compare_dim(int dim, const SortItem *a,
83  const SortItem *b, MultiSortSupport mss);
84 extern int multi_sort_compare_dims(int start, int end, const SortItem *a,
85  const SortItem *b, MultiSortSupport mss);
86 extern int compare_scalars_simple(const void *a, const void *b, void *arg);
87 extern int compare_datums_simple(Datum a, Datum b, SortSupport ssup);
88 
89 extern void *bsearch_arg(const void *key, const void *base,
90  size_t nmemb, size_t size,
91  int (*compar) (const void *, const void *, void *),
92  void *arg);
93 
94 extern AttrNumber *build_attnums_array(Bitmapset *attrs, int *numattrs);
95 
96 extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows,
97  TupleDesc tdesc, MultiSortSupport mss,
98  int numattrs, AttrNumber *attnums);
99 
100 extern bool examine_opclause_expression(OpExpr *expr, Var **varp,
101  Const **cstp, bool *varonleftp);
102 
105  List *clauses,
106  int varRelid,
107  JoinType jointype,
108  SpecialJoinInfo *sjinfo,
109  RelOptInfo *rel,
110  Selectivity *basesel,
111  Selectivity *totalsel);
112 
113 #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:167
int compare_scalars_simple(const void *a, const void *b, void *arg)
bytea * statext_ndistinct_serialize(MVNDistinct *ndistinct)
Definition: mvdistinct.c:172
JoinType
Definition: nodes.h:692
MVNDistinct * statext_ndistinct_build(double totalrows, int numrows, HeapTuple *rows, Bitmapset *attrs, VacAttrStats **stats)
Definition: mvdistinct.c:87
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:250
bytea * statext_dependencies_serialize(MVDependencies *dependencies)
Definition: dependencies.c:446
#define stat(a, b)
Definition: win32_port.h:264
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:549
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