Add data for WAL in pg_stat_io and backend statistics
[pgsql.git] / src / include / statistics / extended_stats_internal.h
blobefcb7dc35461e6c6e028678fbdccd55d04c6c102
1 /*-------------------------------------------------------------------------
3 * extended_stats_internal.h
4 * POSTGRES extended statistics internal declarations
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * IDENTIFICATION
10 * src/include/statistics/extended_stats_internal.h
12 *-------------------------------------------------------------------------
14 #ifndef EXTENDED_STATS_INTERNAL_H
15 #define EXTENDED_STATS_INTERNAL_H
17 #include "statistics/statistics.h"
18 #include "utils/sortsupport.h"
20 typedef struct
22 Oid eqopr; /* '=' operator for datatype, if any */
23 Oid eqfunc; /* and associated function */
24 Oid ltopr; /* '<' operator for datatype, if any */
25 } StdAnalyzeData;
27 typedef struct
29 Datum value; /* a data value */
30 int tupno; /* position index for tuple it came from */
31 } ScalarItem;
33 /* (de)serialization info */
34 typedef struct DimensionInfo
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 */
41 } DimensionInfo;
43 /* multi-sort */
44 typedef struct MultiSortSupportData
46 int ndims; /* number of dimensions */
47 /* sort support data for each dimension: */
48 SortSupportData ssup[FLEXIBLE_ARRAY_MEMBER];
49 } MultiSortSupportData;
51 typedef MultiSortSupportData *MultiSortSupport;
53 typedef struct SortItem
55 Datum *values;
56 bool *isnull;
57 int count;
58 } SortItem;
60 /* a unified representation of the data the statistics is built on */
61 typedef struct StatsBuildData
63 int numrows;
64 int nattnums;
65 AttrNumber *attnums;
66 VacAttrStats **stats;
67 Datum **values;
68 bool **nulls;
69 } StatsBuildData;
72 extern MVNDistinct *statext_ndistinct_build(double totalrows, StatsBuildData *data);
73 extern bytea *statext_ndistinct_serialize(MVNDistinct *ndistinct);
74 extern MVNDistinct *statext_ndistinct_deserialize(bytea *data);
76 extern MVDependencies *statext_dependencies_build(StatsBuildData *data);
77 extern bytea *statext_dependencies_serialize(MVDependencies *dependencies);
78 extern MVDependencies *statext_dependencies_deserialize(bytea *data);
80 extern MCVList *statext_mcv_build(StatsBuildData *data,
81 double totalrows, int stattarget);
82 extern bytea *statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats);
83 extern MCVList *statext_mcv_deserialize(bytea *data);
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);
96 extern AttrNumber *build_attnums_array(Bitmapset *attrs, int nexprs, int *numattrs);
98 extern SortItem *build_sorted_items(StatsBuildData *data, int *nitems,
99 MultiSortSupport mss,
100 int numattrs, AttrNumber *attnums);
102 extern bool examine_opclause_args(List *args, Node **exprp,
103 Const **cstp, bool *expronleftp);
105 extern Selectivity mcv_combine_selectivities(Selectivity simple_sel,
106 Selectivity mcv_sel,
107 Selectivity mcv_basesel,
108 Selectivity mcv_totalsel);
110 extern Selectivity mcv_clauselist_selectivity(PlannerInfo *root,
111 StatisticExtInfo *stat,
112 List *clauses,
113 int varRelid,
114 JoinType jointype,
115 SpecialJoinInfo *sjinfo,
116 RelOptInfo *rel,
117 Selectivity *basesel,
118 Selectivity *totalsel);
120 extern Selectivity mcv_clause_selectivity_or(PlannerInfo *root,
121 StatisticExtInfo *stat,
122 MCVList *mcv,
123 Node *clause,
124 bool **or_matches,
125 Selectivity *basesel,
126 Selectivity *overlap_mcvsel,
127 Selectivity *overlap_basesel,
128 Selectivity *totalsel);
130 #endif /* EXTENDED_STATS_INTERNAL_H */