forked from timescale/timescaledb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontinuous_agg.h
More file actions
205 lines (170 loc) · 8.09 KB
/
Copy pathcontinuous_agg.h
File metadata and controls
205 lines (170 loc) · 8.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* This file and its contents are licensed under the Apache License 2.0.
* Please see the included NOTICE for copyright information and
* LICENSE-APACHE for a copy of the license.
*/
#pragma once
#include <postgres.h>
#include <catalog/pg_type.h>
#include <nodes/parsenodes.h>
#include "chunk.h"
#include "ts_catalog/catalog.h"
#include "compat/compat.h"
#include "with_clause/with_clause_parser.h"
#define TS_INVALIDATION_SLOT_NAME_MAX (32)
/*switch to ts user for _timescaledb_internal access */
#define SWITCH_TO_TS_USER(schemaname, newuid, saved_uid, saved_secctx) \
do \
{ \
if ((schemaname) && \
strncmp(schemaname, INTERNAL_SCHEMA_NAME, strlen(INTERNAL_SCHEMA_NAME)) == 0) \
(newuid) = ts_catalog_database_info_get()->owner_uid; \
else \
(newuid) = InvalidOid; \
if (OidIsValid((newuid))) \
{ \
GetUserIdAndSecContext(&(saved_uid), &(saved_secctx)); \
SetUserIdAndSecContext(newuid, (saved_secctx) | SECURITY_LOCAL_USERID_CHANGE); \
} \
} while (0)
#define RESTORE_USER(newuid, saved_uid, saved_secctx) \
do \
{ \
if (OidIsValid((newuid))) \
SetUserIdAndSecContext(saved_uid, saved_secctx); \
} while (0);
typedef enum ContinuousAggViewType
{
ContinuousAggUserView = 0,
ContinuousAggPartialView,
ContinuousAggDirectView,
ContinuousAggAnyView
} ContinuousAggViewType;
typedef enum ContinuousAggInvalidateUsing
{
ContinuousAggInvalidateUsingDefault = 0,
ContinuousAggInvalidateUsingTrigger,
ContinuousAggInvalidateUsingWal,
} ContinuousAggInvalidateUsing;
/*
* Information about the bucketing function.
*/
typedef struct ContinuousAggBucketFunction
{
/* Oid of the bucketing function. In the catalog table, the regprocedure is used. This ensures
* that the Oid is mapped to a string when a backup is taken and the string is converted back to
* the Oid when the backup is restored. This way, we can use an Oid in the catalog table even
* when a backup is restored and the Oid may have changed. However, the dependency management in
* PostgreSQL does not track the Oid. If the function is dropped and a new one is created, the
* Oid changes and this value points to a non-existing Oid. This can not happen in real-world
* situations since PostgreSQL protects the bucket_function from deletion until the CAgg is
* defined. */
Oid bucket_function;
Oid bucket_width_type; /* type of bucket_width */
/* Is the interval of the bucket fixed? */
bool bucket_fixed_interval;
/* Is the bucket defined on a time datatype ?*/
bool bucket_time_based;
/*
* Fields that are used for time based buckets
*/
Interval *bucket_time_width;
/*
* Custom origin value stored as UTC timestamp.
* If not specified, stores infinity.
*/
TimestampTz bucket_time_origin;
/*
* Bucket offset. Note that we don't support
* both offset and origin at the same time
*/
Interval *bucket_time_offset;
char *bucket_time_timezone;
/*
* Fields that are used on integer based buckets
*/
int64 bucket_integer_width;
int64 bucket_integer_offset;
} ContinuousAggBucketFunction;
typedef struct ContinuousAgg
{
FormData_continuous_agg data;
/* Info about the time bucketing function */
ContinuousAggBucketFunction *bucket_function;
/* Relid of the user-facing view */
Oid relid;
/* Type of the primary partitioning dimension */
Oid partition_type;
} ContinuousAgg;
static inline bool
ContinuousAggIsHierarchical(const ContinuousAgg *cagg)
{
return (cagg->data.parent_mat_hypertable_id != INVALID_HYPERTABLE_ID);
}
typedef enum ContinuousAggHypertableStatus
{
HypertableIsNotContinuousAgg = 0,
HypertableIsMaterialization = 1,
HypertableIsRawTable = 2,
HypertableIsMaterializationAndRaw = HypertableIsMaterialization | HypertableIsRawTable,
} ContinuousAggHypertableStatus;
typedef struct ContinuousAggInfo
{
/* (int32) elements */
List *mat_hypertable_ids;
/* (const ContinuousAggBucketFunction *) elements; stores NULL for fixed buckets */
List *bucket_functions;
} ContinuousAggInfo;
typedef struct ContinuousAggPolicyOffset
{
Datum value;
Oid type;
bool isnull;
const char *name;
} ContinuousAggPolicyOffset;
extern TSDLLEXPORT Oid ts_cagg_permissions_check(Oid cagg_oid, Oid userid);
extern TSDLLEXPORT ContinuousAggInfo ts_continuous_agg_get_all_caggs_info(int32 raw_hypertable_id);
extern TSDLLEXPORT ContinuousAgg *
ts_continuous_agg_find_by_mat_hypertable_id(int32 mat_hypertable_id, bool missing_ok);
extern TSDLLEXPORT void ts_continuous_agg_set_schema_change_timestamp(int32 mat_hypertable_id,
int64 threshold);
extern TSDLLEXPORT ContinuousAggHypertableStatus
ts_continuous_agg_hypertable_status(int32 hypertable_id);
extern TSDLLEXPORT List *ts_continuous_aggs_find_by_raw_table_id(int32 raw_hypertable_id);
extern TSDLLEXPORT ContinuousAgg *ts_continuous_agg_find_by_view_name(const char *schema,
const char *name,
ContinuousAggViewType type);
extern TSDLLEXPORT ContinuousAgg *ts_continuous_agg_find_by_relid(Oid relid);
extern TSDLLEXPORT ContinuousAgg *ts_continuous_agg_find_by_rv(const RangeVar *rv);
extern bool ts_continuous_agg_drop(const char *view_schema, const char *view_name);
extern void ts_continuous_agg_drop_hypertable_callback(int32 hypertable_id);
extern TSDLLEXPORT ContinuousAggViewType ts_continuous_agg_view_type(FormData_continuous_agg *data,
const char *schema,
const char *name);
extern TSDLLEXPORT void ts_continuous_agg_rename_schema_name(const char *old_schema,
const char *new_schema);
extern TSDLLEXPORT void ts_continuous_agg_rename_view(const char *old_schema, const char *old_name,
const char *new_schema, const char *new_name,
ObjectType *object_type);
extern TSDLLEXPORT const Dimension *
ts_continuous_agg_find_integer_now_func_by_materialization_id(int32 mat_htid);
extern ContinuousAgg *ts_continuous_agg_find_userview_name(const char *schema, const char *name);
extern TSDLLEXPORT void ts_continuous_agg_invalidate_chunk(Hypertable *ht, Chunk *chunk);
extern TSDLLEXPORT bool ts_continuous_agg_bucket_on_interval(Oid bucket_function);
extern TSDLLEXPORT void
ts_compute_inscribed_bucketed_refresh_window_variable(int64 *start, int64 *end,
const ContinuousAggBucketFunction *bf);
extern TSDLLEXPORT void
ts_compute_circumscribed_bucketed_refresh_window_variable(int64 *start, int64 *end,
const ContinuousAggBucketFunction *bf);
extern TSDLLEXPORT int64 ts_cagg_variable_next_bucket_start(int64 timeval,
const ContinuousAggBucketFunction *bf);
extern TSDLLEXPORT int64
ts_cagg_variable_current_bucket_start(int64 timeval, const ContinuousAggBucketFunction *bf);
extern TSDLLEXPORT Query *ts_continuous_agg_get_query(ContinuousAgg *cagg);
extern TSDLLEXPORT Query *ts_continuous_agg_get_finalized_query(ContinuousAgg *cagg);
extern TSDLLEXPORT int64
ts_continuous_agg_fixed_bucket_width(const ContinuousAggBucketFunction *bucket_function);
extern TSDLLEXPORT int64
ts_continuous_agg_bucket_width(const ContinuousAggBucketFunction *bucket_function);
extern TSDLLEXPORT void ts_get_invalidation_replication_slot_name(char *slotname, Size szslot);