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-2024, 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;
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 *mcvlist, 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 
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 */
int16 AttrNumber
Definition: attnum.h:21
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:413
MVDependencies * statext_dependencies_deserialize(bytea *data)
Definition: dependencies.c:499
int multi_sort_compare_dims(int start, int end, const SortItem *a, const SortItem *b, MultiSortSupport mss)
MultiSortSupportData * MultiSortSupport
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:2048
struct DimensionInfo DimensionInfo
int multi_sort_compare_dim(int dim, const SortItem *a, const SortItem *b, MultiSortSupport mss)
bytea * statext_ndistinct_serialize(MVNDistinct *ndistinct)
Definition: mvdistinct.c:179
int compare_scalars_simple(const void *a, const void *b, void *arg)
struct SortItem SortItem
MCVList * statext_mcv_deserialize(bytea *data)
Definition: mcv.c:996
bytea * statext_dependencies_serialize(MVDependencies *dependencies)
Definition: dependencies.c:444
SortItem * build_sorted_items(StatsBuildData *data, int *nitems, MultiSortSupport mss, int numattrs, AttrNumber *attnums)
int compare_datums_simple(Datum a, Datum b, SortSupport ssup)
MVNDistinct * statext_ndistinct_deserialize(bytea *data)
Definition: mvdistinct.c:250
struct StatsBuildData StatsBuildData
Selectivity mcv_combine_selectivities(Selectivity simple_sel, Selectivity mcv_sel, Selectivity mcv_basesel, Selectivity mcv_totalsel)
Definition: mcv.c:2006
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:2126
MVNDistinct * statext_ndistinct_build(double totalrows, StatsBuildData *data)
Definition: mvdistinct.c:88
AttrNumber * build_attnums_array(Bitmapset *attrs, int nexprs, int *numattrs)
MCVList * statext_mcv_build(StatsBuildData *data, double totalrows, int stattarget)
Definition: mcv.c:180
MVDependencies * statext_dependencies_build(StatsBuildData *data)
Definition: dependencies.c:348
int multi_sort_compare(const void *a, const void *b, void *arg)
MultiSortSupport multi_sort_init(int ndims)
bytea * statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats)
Definition: mcv.c:621
struct MultiSortSupportData MultiSortSupportData
void multi_sort_add_dimension(MultiSortSupport mss, int sortdim, Oid oper, Oid collation)
bool examine_opclause_args(List *args, Node **exprp, Const **cstp, bool *expronleftp)
return str start
#define nitems(x)
Definition: indent.h:31
int b
Definition: isn.c:69
int a
Definition: isn.c:68
double Selectivity
Definition: nodes.h:250
JoinType
Definition: nodes.h:288
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:370
void * arg
const void * data
uintptr_t Datum
Definition: postgres.h:64
unsigned int Oid
Definition: postgres_ext.h:31
tree ctl root
Definition: radixtree.h:1886
Definition: pg_list.h:54
SortSupportData ssup[FLEXIBLE_ARRAY_MEMBER]
Definition: nodes.h:129
VacAttrStats ** stats
Definition: c.h:666