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 */ |
26 | } StdAnalyzeData; |
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 */ |
42 | } DimensionInfo; |
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]; |
50 | } MultiSortSupportData; |
51 | |
52 | typedef MultiSortSupportData *MultiSortSupport; |
53 | |
54 | typedef struct SortItem |
55 | { |
56 | Datum *values; |
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); |
64 | extern bytea *statext_ndistinct_serialize(MVNDistinct *ndistinct); |
65 | extern MVNDistinct *statext_ndistinct_deserialize(bytea *data); |
66 | |
67 | extern MVDependencies *statext_dependencies_build(int numrows, HeapTuple *rows, |
68 | Bitmapset *attrs, VacAttrStats **stats); |
69 | extern bytea *statext_dependencies_serialize(MVDependencies *dependencies); |
70 | extern MVDependencies *statext_dependencies_deserialize(bytea *data); |
71 | |
72 | extern MCVList *statext_mcv_build(int numrows, HeapTuple *rows, |
73 | Bitmapset *attrs, VacAttrStats **stats, |
74 | double totalrows); |
75 | extern bytea *statext_mcv_serialize(MCVList *mcv, VacAttrStats **stats); |
76 | extern MCVList *statext_mcv_deserialize(bytea *data); |
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 | |
103 | extern Selectivity mcv_clauselist_selectivity(PlannerInfo *root, |
104 | StatisticExtInfo *stat, |
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 */ |
114 | |