PostgreSQL Source Code  git master
pg_aggregate.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_aggregate.h
4  * definition of the "aggregate" system catalog (pg_aggregate)
5  *
6  *
7  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/catalog/pg_aggregate.h
11  *
12  * NOTES
13  * The Catalog.pm module reads this file and derives schema
14  * information.
15  *
16  *-------------------------------------------------------------------------
17  */
18 #ifndef PG_AGGREGATE_H
19 #define PG_AGGREGATE_H
20 
21 #include "catalog/genbki.h"
22 #include "catalog/pg_aggregate_d.h"
23 
24 #include "catalog/objectaddress.h"
25 #include "nodes/pg_list.h"
26 
27 /* ----------------------------------------------------------------
28  * pg_aggregate definition.
29  * cpp turns this into typedef struct FormData_pg_aggregate
30  * ----------------------------------------------------------------
31  */
32 CATALOG(pg_aggregate,2600,AggregateRelationId)
33 {
34  /* pg_proc OID of the aggregate itself */
35  regproc aggfnoid BKI_LOOKUP(pg_proc);
36 
37  /* aggregate kind, see AGGKIND_ categories below */
38  char aggkind BKI_DEFAULT(n);
39 
40  /* number of arguments that are "direct" arguments */
41  int16 aggnumdirectargs BKI_DEFAULT(0);
42 
43  /* transition function */
44  regproc aggtransfn BKI_LOOKUP(pg_proc);
45 
46  /* final function (0 if none) */
47  regproc aggfinalfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
48 
49  /* combine function (0 if none) */
50  regproc aggcombinefn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
51 
52  /* function to convert transtype to bytea (0 if none) */
53  regproc aggserialfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
54 
55  /* function to convert bytea to transtype (0 if none) */
56  regproc aggdeserialfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
57 
58  /* forward function for moving-aggregate mode (0 if none) */
59  regproc aggmtransfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
60 
61  /* inverse function for moving-aggregate mode (0 if none) */
62  regproc aggminvtransfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
63 
64  /* final function for moving-aggregate mode (0 if none) */
65  regproc aggmfinalfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
66 
67  /* true to pass extra dummy arguments to aggfinalfn */
68  bool aggfinalextra BKI_DEFAULT(f);
69 
70  /* true to pass extra dummy arguments to aggmfinalfn */
71  bool aggmfinalextra BKI_DEFAULT(f);
72 
73  /* tells whether aggfinalfn modifies transition state */
74  char aggfinalmodify BKI_DEFAULT(r);
75 
76  /* tells whether aggmfinalfn modifies transition state */
77  char aggmfinalmodify BKI_DEFAULT(r);
78 
79  /* associated sort operator (0 if none) */
80  Oid aggsortop BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_operator);
81 
82  /* type of aggregate's transition (state) data */
83  Oid aggtranstype BKI_LOOKUP(pg_type);
84 
85  /* estimated size of state data (0 for default estimate) */
86  int32 aggtransspace BKI_DEFAULT(0);
87 
88  /* type of moving-aggregate state data (0 if none) */
89  Oid aggmtranstype BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_type);
90 
91  /* estimated size of moving-agg state (0 for default est) */
92  int32 aggmtransspace BKI_DEFAULT(0);
93 
94 #ifdef CATALOG_VARLEN /* variable-length fields start here */
95 
96  /* initial value for transition state (can be NULL) */
97  text agginitval BKI_DEFAULT(_null_);
98 
99  /* initial value for moving-agg state (can be NULL) */
100  text aggminitval BKI_DEFAULT(_null_);
101 #endif
103 
104 /* ----------------
105  * Form_pg_aggregate corresponds to a pointer to a tuple with
106  * the format of pg_aggregate relation.
107  * ----------------
108  */
110 
111 DECLARE_TOAST(pg_aggregate, 4159, 4160);
112 
113 DECLARE_UNIQUE_INDEX_PKEY(pg_aggregate_fnoid_index, 2650, AggregateFnoidIndexId, on pg_aggregate using btree(aggfnoid oid_ops));
114 
115 #ifdef EXPOSE_TO_CLIENT_CODE
116 
117 /*
118  * Symbolic values for aggkind column. We distinguish normal aggregates
119  * from ordered-set aggregates (which have two sets of arguments, namely
120  * direct and aggregated arguments) and from hypothetical-set aggregates
121  * (which are a subclass of ordered-set aggregates in which the last
122  * direct arguments have to match up in number and datatypes with the
123  * aggregated arguments).
124  */
125 #define AGGKIND_NORMAL 'n'
126 #define AGGKIND_ORDERED_SET 'o'
127 #define AGGKIND_HYPOTHETICAL 'h'
128 
129 /* Use this macro to test for "ordered-set agg including hypothetical case" */
130 #define AGGKIND_IS_ORDERED_SET(kind) ((kind) != AGGKIND_NORMAL)
131 
132 /*
133  * Symbolic values for aggfinalmodify and aggmfinalmodify columns.
134  * Preferably, finalfns do not modify the transition state value at all,
135  * but in some cases that would cost too much performance. We distinguish
136  * "pure read only" and "trashes it arbitrarily" cases, as well as the
137  * intermediate case where multiple finalfn calls are allowed but the
138  * transfn cannot be applied anymore after the first finalfn call.
139  */
140 #define AGGMODIFY_READ_ONLY 'r'
141 #define AGGMODIFY_SHAREABLE 's'
142 #define AGGMODIFY_READ_WRITE 'w'
143 
144 #endif /* EXPOSE_TO_CLIENT_CODE */
145 
146 
147 extern ObjectAddress AggregateCreate(const char *aggName,
148  Oid aggNamespace,
149  bool replace,
150  char aggKind,
151  int numArgs,
152  int numDirectArgs,
153  oidvector *parameterTypes,
154  Datum allParameterTypes,
155  Datum parameterModes,
156  Datum parameterNames,
157  List *parameterDefaults,
158  Oid variadicArgType,
159  List *aggtransfnName,
160  List *aggfinalfnName,
161  List *aggcombinefnName,
162  List *aggserialfnName,
163  List *aggdeserialfnName,
164  List *aggmtransfnName,
165  List *aggminvtransfnName,
166  List *aggmfinalfnName,
167  bool finalfnExtraArgs,
168  bool mfinalfnExtraArgs,
169  char finalfnModify,
170  char mfinalfnModify,
171  List *aggsortopName,
172  Oid aggTransType,
173  int32 aggTransSpace,
174  Oid aggmTransType,
175  int32 aggmTransSpace,
176  const char *agginitval,
177  const char *aggminitval,
178  char proparallel);
179 
180 #endif /* PG_AGGREGATE_H */
signed short int16
Definition: c.h:428
Definition: c.h:660
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress AggregateCreate(const char *aggName, Oid aggNamespace, bool replace, char aggKind, int numArgs, int numDirectArgs, oidvector *parameterTypes, Datum allParameterTypes, Datum parameterModes, Datum parameterNames, List *parameterDefaults, Oid variadicArgType, List *aggtransfnName, List *aggfinalfnName, List *aggcombinefnName, List *aggserialfnName, List *aggdeserialfnName, List *aggmtransfnName, List *aggminvtransfnName, List *aggmfinalfnName, bool finalfnExtraArgs, bool mfinalfnExtraArgs, char finalfnModify, char mfinalfnModify, List *aggsortopName, Oid aggTransType, int32 aggTransSpace, Oid aggmTransType, int32 aggmTransSpace, const char *agginitval, const char *aggminitval, char proparallel)
Definition: pg_aggregate.c:46
#define BKI_DEFAULT(value)
Definition: genbki.h:35
signed int int32
Definition: c.h:429
FormData_pg_aggregate
Definition: pg_aggregate.h:102
#define BKI_LOOKUP_OPT(catalog)
Definition: genbki.h:47
#define BKI_LOOKUP(catalog)
Definition: genbki.h:46
uintptr_t Datum
Definition: postgres.h:411
FormData_pg_aggregate * Form_pg_aggregate
Definition: pg_aggregate.h:109
Oid regproc
Definition: c.h:584
Definition: c.h:621
CATALOG(pg_aggregate, 2600, AggregateRelationId)
Definition: pg_aggregate.h:32
DECLARE_TOAST(pg_aggregate, 4159, 4160)
Definition: pg_list.h:50
DECLARE_UNIQUE_INDEX_PKEY(pg_aggregate_fnoid_index, 2650, AggregateFnoidIndexId, on pg_aggregate using btree(aggfnoid oid_ops))