1 /*
2 * This file and its contents are licensed under the Apache License 2.0.
3 * Please see the included NOTICE for copyright information and
4 * LICENSE-APACHE for a copy of the license.
5 */
6 #ifndef TIMESCALEDB_CATALOG_H
7 #define TIMESCALEDB_CATALOG_H
8
9 #include <postgres.h>
10 #include <utils/jsonb.h>
11 #include <utils/rel.h>
12 #include <nodes/nodes.h>
13 #include <access/heapam.h>
14
15 #include "export.h"
16 #include "extension_constants.h"
17 #include "scanner.h"
18
19 /*
20 * TimescaleDB catalog.
21 *
22 * The TimescaleDB catalog contains schema metadata for hypertables, among other
23 * things. The metadata is stored in regular tables. This header file contains
24 * definitions for those tables and should match any table declarations in
25 * sql/common/tables.sql.
26 *
27 * A source file that includes this header has access to a catalog object,
28 * which contains cached information about catalog tables, such as relation
29 * OIDs.
30 *
31 * Generally, definitions and naming should roughly follow how things are done
32 * in Postgres internally.
33 */
34 typedef enum CatalogTable
35 {
36 HYPERTABLE = 0,
37 HYPERTABLE_DATA_NODE,
38 DIMENSION,
39 DIMENSION_SLICE,
40 CHUNK,
41 CHUNK_CONSTRAINT,
42 CHUNK_INDEX,
43 CHUNK_DATA_NODE,
44 TABLESPACE,
45 BGW_JOB,
46 BGW_JOB_STAT,
47 METADATA,
48 BGW_POLICY_CHUNK_STATS,
49 CONTINUOUS_AGG,
50 CONTINUOUS_AGGS_HYPERTABLE_INVALIDATION_LOG,
51 CONTINUOUS_AGGS_INVALIDATION_THRESHOLD,
52 CONTINUOUS_AGGS_MATERIALIZATION_INVALIDATION_LOG,
53 HYPERTABLE_COMPRESSION,
54 COMPRESSION_CHUNK_SIZE,
55 REMOTE_TXN,
56 CHUNK_COPY_OPERATION,
57 _MAX_CATALOG_TABLES,
58 } CatalogTable;
59
60 typedef struct TableInfoDef
61 {
62 const char *schema_name;
63 const char *table_name;
64 } TableInfoDef;
65
66 typedef struct TableIndexDef
67 {
68 int length;
69 char **names;
70 } TableIndexDef;
71
72 #define INVALID_CATALOG_TABLE _MAX_CATALOG_TABLES
73 #define INVALID_INDEXID -1
74
75 #define CATALOG_INTERNAL_FUNC(catalog, func) (catalog->functions[func].function_id)
76
77 #define CatalogInternalCall1(func, datum1) \
78 OidFunctionCall1(CATALOG_INTERNAL_FUNC(ts_catalog_get(), func), datum1)
79 #define CatalogInternalCall2(func, datum1, datum2) \
80 OidFunctionCall2(CATALOG_INTERNAL_FUNC(ts_catalog_get(), func), datum1, datum2)
81 #define CatalogInternalCall3(func, datum1, datum2, datum3) \
82 OidFunctionCall3(CATALOG_INTERNAL_FUNC(ts_catalog_get(), func), datum1, datum2, datum3)
83 #define CatalogInternalCall4(func, datum1, datum2, datum3, datum4) \
84 OidFunctionCall4(CATALOG_INTERNAL_FUNC(ts_catalog_get(), func), datum1, datum2, datum3, datum4)
85
86 typedef enum InternalFunction
87 {
88 DDL_ADD_CHUNK_CONSTRAINT,
89 DDL_ADD_HYPERTABLE_FK_CONSTRAINT,
90 _MAX_INTERNAL_FUNCTIONS,
91 } InternalFunction;
92
93 /******************************
94 *
95 * Hypertable table definitions
96 *
97 ******************************/
98
99 #define HYPERTABLE_TABLE_NAME "hypertable"
100
101 /* Hypertable table attribute numbers */
102 enum Anum_hypertable
103 {
104 Anum_hypertable_id = 1,
105 Anum_hypertable_schema_name,
106 Anum_hypertable_table_name,
107 Anum_hypertable_associated_schema_name,
108 Anum_hypertable_associated_table_prefix,
109 Anum_hypertable_num_dimensions,
110 Anum_hypertable_chunk_sizing_func_schema,
111 Anum_hypertable_chunk_sizing_func_name,
112 Anum_hypertable_chunk_target_size,
113 Anum_hypertable_compression_state,
114 Anum_hypertable_compressed_hypertable_id,
115 Anum_hypertable_replication_factor,
116 _Anum_hypertable_max,
117 };
118
119 #define Natts_hypertable (_Anum_hypertable_max - 1)
120
121 typedef struct FormData_hypertable
122 {
123 int32 id;
124 NameData schema_name;
125 NameData table_name;
126 NameData associated_schema_name;
127 NameData associated_table_prefix;
128 int16 num_dimensions;
129 NameData chunk_sizing_func_schema;
130 NameData chunk_sizing_func_name;
131 int64 chunk_target_size;
132 int16 compression_state;
133 int32 compressed_hypertable_id;
134 int16 replication_factor;
135 } FormData_hypertable;
136
137 typedef FormData_hypertable *Form_hypertable;
138
139 /* Hypertable primary index attribute numbers */
140 enum Anum_hypertable_pkey_idx
141 {
142 Anum_hypertable_pkey_idx_id = 1,
143 _Anum_hypertable_pkey_max,
144 };
145
146 #define Natts_hypertable_pkey_idx (_Anum_hypertable_pkey_max - 1)
147
148 /* Hypertable name (schema,table) index attribute numbers */
149 enum Anum_hypertable_name_idx
150 {
151 Anum_hypertable_name_idx_table = 1,
152 Anum_hypertable_name_idx_schema,
153 _Anum_hypertable_name_max,
154 };
155
156 #define Natts_hypertable_name_idx (_Anum_hypertable_name_max - 1)
157
158 enum
159 {
160 HYPERTABLE_ID_INDEX = 0,
161 HYPERTABLE_NAME_INDEX,
162 _MAX_HYPERTABLE_INDEX,
163 };
164
165 #define HYPERTABLE_DATA_NODE_TABLE_NAME "hypertable_data_node"
166
167 enum Anum_hypertable_data_node
168 {
169 Anum_hypertable_data_node_hypertable_id = 1,
170 Anum_hypertable_data_node_node_hypertable_id,
171 Anum_hypertable_data_node_node_name,
172 Anum_hypertable_data_node_block_chunks,
173 _Anum_hypertable_data_node_max,
174 };
175
176 #define Natts_hypertable_data_node (_Anum_hypertable_data_node_max - 1)
177
178 typedef struct FormData_hypertable_data_node
179 {
180 int32 hypertable_id;
181 int32 node_hypertable_id;
182 NameData node_name;
183 bool block_chunks;
184 } FormData_hypertable_data_node;
185
186 typedef FormData_hypertable_data_node *Form_hypertable_data_node;
187
188 enum
189 {
190 HYPERTABLE_DATA_NODE_HYPERTABLE_ID_NODE_NAME_IDX,
191 HYPERTABLE_DATA_NODE_NODE_HYPERTABLE_ID_NODE_NAME_IDX,
192 _MAX_HYPERTABLE_DATA_NODE_INDEX,
193 };
194
195 enum Anum_hypertable_data_node_hypertable_id_node_name_idx
196 {
197 Anum_hypertable_data_node_hypertable_id_node_name_idx_hypertable_id = 1,
198 Anum_hypertable_data_node_hypertable_id_node_name_idx_node_name,
199 _Anum_hypertable_data_node_hypertable_id_node_name_idx_max,
200 };
201
202 struct FormData_hypertable_data_node_hypertable_id_node_name_idx
203 {
204 int32 hypertable_id;
205 NameData node_name;
206 };
207
208 enum Anum_hypertable_data_node_node_hypertable_id_node_name_idx
209 {
210 Anum_hypertable_data_node_node_hypertable_id_node_name_idx_hypertable_id = 1,
211 Anum_hypertable_data_node_node_hypertable_id_node_name_idx_node_name,
212 _Anum_hypertable_data_node_node_hypertable_id_node_name_idx_max,
213 };
214
215 struct FormData_hypertable_data_node_node_hypertable_id_node_name_idx
216 {
217 int32 node_hypertable_id;
218 NameData node_name;
219 };
220
221 /******************************
222 *
223 * Dimension table definitions
224 *
225 ******************************/
226
227 #define DIMENSION_TABLE_NAME "dimension"
228
229 enum Anum_dimension
230 {
231 Anum_dimension_id = 1,
232 Anum_dimension_hypertable_id,
233 Anum_dimension_column_name,
234 Anum_dimension_column_type,
235 Anum_dimension_aligned,
236 Anum_dimension_num_slices,
237 Anum_dimension_partitioning_func_schema,
238 Anum_dimension_partitioning_func,
239 Anum_dimension_interval_length,
240 Anum_dimension_integer_now_func_schema,
241 Anum_dimension_integer_now_func,
242 _Anum_dimension_max,
243 };
244
245 #define Natts_dimension (_Anum_dimension_max - 1)
246
247 typedef struct FormData_dimension
248 {
249 int32 id;
250 int32 hypertable_id;
251 NameData column_name;
252 Oid column_type;
253 bool aligned;
254 /* closed (space) columns */
255 int16 num_slices;
256 NameData partitioning_func_schema;
257 NameData partitioning_func;
258 /* open (time) columns */
259 int64 interval_length;
260 NameData integer_now_func_schema;
261 NameData integer_now_func;
262 } FormData_dimension;
263
264 typedef FormData_dimension *Form_dimension;
265
266 enum Anum_dimension_id_idx
267 {
268 Anum_dimension_id_idx_id = 1,
269 _Anum_dimension_id_idx_max,
270 };
271
272 #define Natts_dimension_id_idx (_Anum_dimension_id_idx_max - 1)
273
274 enum Anum_dimension_hypertable_id_column_name_idx
275 {
276 Anum_dimension_hypertable_id_column_name_idx_hypertable_id = 1,
277 Anum_dimension_hypertable_id_column_name_idx_column_name,
278 _Anum_dimension_hypertable_id_idx_max,
279 };
280
281 #define Natts_dimension_hypertable_id_idx (_Anum_dimension_hypertable_id_idx_max - 1)
282
283 enum
284 {
285 DIMENSION_ID_IDX = 0,
286 DIMENSION_HYPERTABLE_ID_COLUMN_NAME_IDX,
287 _MAX_DIMENSION_INDEX,
288 };
289
290 /******************************
291 *
292 * Dimension slice table definitions
293 *
294 ******************************/
295
296 #define DIMENSION_SLICE_TABLE_NAME "dimension_slice"
297
298 enum Anum_dimension_slice
299 {
300 Anum_dimension_slice_id = 1,
301 Anum_dimension_slice_dimension_id,
302 Anum_dimension_slice_range_start,
303 Anum_dimension_slice_range_end,
304 _Anum_dimension_slice_max,
305 };
306
307 #define Natts_dimension_slice (_Anum_dimension_slice_max - 1)
308
309 typedef struct FormData_dimension_slice
310 {
311 int32 id;
312 int32 dimension_id;
313 int64 range_start;
314 int64 range_end;
315 } FormData_dimension_slice;
316
317 typedef FormData_dimension_slice *Form_dimension_slice;
318
319 enum Anum_dimension_slice_id_idx
320 {
321 Anum_dimension_slice_id_idx_id = 1,
322 _Anum_dimension_slice_id_idx_max,
323 };
324
325 #define Natts_dimension_slice_id_idx (_Anum_dimension_slice_id_idx_max - 1)
326
327 enum Anum_dimension_slice_dimension_id_range_start_range_end_idx
328 {
329 Anum_dimension_slice_dimension_id_range_start_range_end_idx_dimension_id = 1,
330 Anum_dimension_slice_dimension_id_range_start_range_end_idx_range_start,
331 Anum_dimension_slice_dimension_id_range_start_range_end_idx_range_end,
332 _Anum_dimension_slice_dimension_id_range_start_range_end_idx_max,
333 };
334
335 #define Natts_dimension_slice_dimension_id_range_start_range_end_idx \
336 (_Anum_dimension_slice_dimension_id_range_start_range_end_idx_max - 1)
337
338 enum
339 {
340 DIMENSION_SLICE_ID_IDX = 0,
341 DIMENSION_SLICE_DIMENSION_ID_RANGE_START_RANGE_END_IDX,
342 _MAX_DIMENSION_SLICE_INDEX,
343 };
344
345 /*************************
346 *
347 * Chunk table definitions
348 *
349 *************************/
350
351 #define CHUNK_TABLE_NAME "chunk"
352
353 enum Anum_chunk
354 {
355 Anum_chunk_id = 1,
356 Anum_chunk_hypertable_id,
357 Anum_chunk_schema_name,
358 Anum_chunk_table_name,
359 Anum_chunk_compressed_chunk_id,
360 Anum_chunk_dropped,
361 Anum_chunk_status,
362 _Anum_chunk_max,
363 };
364
365 #define Natts_chunk (_Anum_chunk_max - 1)
366
367 typedef struct FormData_chunk
368 {
369 int32 id;
370 int32 hypertable_id;
371 NameData schema_name;
372 NameData table_name;
373 int32 compressed_chunk_id;
374 bool dropped;
375 int32 status;
376 } FormData_chunk;
377
378 typedef FormData_chunk *Form_chunk;
379
380 enum
381 {
382 CHUNK_ID_INDEX = 0,
383 CHUNK_HYPERTABLE_ID_INDEX,
384 CHUNK_SCHEMA_NAME_INDEX,
385 CHUNK_COMPRESSED_CHUNK_ID_INDEX,
386 _MAX_CHUNK_INDEX,
387 };
388
389 enum Anum_chunk_idx
390 {
391 Anum_chunk_idx_id = 1,
392 };
393
394 enum Anum_chunk_hypertable_id_idx
395 {
396 Anum_chunk_hypertable_id_idx_hypertable_id = 1,
397 };
398
399 enum Anum_chunk_compressed_chunk_id_idx
400 {
401 Anum_chunk_compressed_chunk_id_idx_compressed_chunk_id = 1,
402 };
403
404 enum Anum_chunk_schema_name_idx
405 {
406 Anum_chunk_schema_name_idx_schema_name = 1,
407 Anum_chunk_schema_name_idx_table_name,
408 };
409
410 /************************************
411 *
412 * Chunk constraint table definitions
413 *
414 ************************************/
415
416 #define CHUNK_CONSTRAINT_TABLE_NAME "chunk_constraint"
417
418 enum Anum_chunk_constraint
419 {
420 Anum_chunk_constraint_chunk_id = 1,
421 Anum_chunk_constraint_dimension_slice_id,
422 Anum_chunk_constraint_constraint_name,
423 Anum_chunk_constraint_hypertable_constraint_name,
424 _Anum_chunk_constraint_max,
425 };
426
427 #define Natts_chunk_constraint (_Anum_chunk_constraint_max - 1)
428
429 /* Do Not use GET_STRUCT with FormData_chunk_constraint. It contains NULLS */
430 typedef struct FormData_chunk_constraint
431 {
432 int32 chunk_id;
433 int32 dimension_slice_id;
434 NameData constraint_name;
435 NameData hypertable_constraint_name;
436 } FormData_chunk_constraint;
437
438 typedef FormData_chunk_constraint *Form_chunk_constraint;
439
440 enum
441 {
442 CHUNK_CONSTRAINT_CHUNK_ID_CONSTRAINT_NAME_IDX = 0,
443 CHUNK_CONSTRAINT_CHUNK_ID_DIMENSION_SLICE_ID_IDX,
444 _MAX_CHUNK_CONSTRAINT_INDEX,
445 };
446
447 enum Anum_chunk_constraint_chunk_id_dimension_slice_id_idx
448 {
449 Anum_chunk_constraint_chunk_id_dimension_slice_id_idx_chunk_id = 1,
450 Anum_chunk_constraint_chunk_id_dimension_slice_id_idx_dimension_slice_id,
451 _Anum_chunk_constraint_chunk_id_dimension_slice_id_idx_max,
452 };
453
454 enum Anum_chunk_constraint_chunk_id_constraint_name_idx
455 {
456 Anum_chunk_constraint_chunk_id_constraint_name_idx_chunk_id = 1,
457 Anum_chunk_constraint_chunk_id_constraint_name_idx_constraint_name,
458 _Anum_chunk_constraint_chunk_id_constraint_name_idx_max,
459 };
460
461 /************************************
462 *
463 * Chunk index table definitions
464 *
465 ************************************/
466
467 #define CHUNK_INDEX_TABLE_NAME "chunk_index"
468
469 enum Anum_chunk_index
470 {
471 Anum_chunk_index_chunk_id = 1,
472 Anum_chunk_index_index_name,
473 Anum_chunk_index_hypertable_id,
474 Anum_chunk_index_hypertable_index_name,
475 _Anum_chunk_index_max,
476 };
477
478 #define Natts_chunk_index (_Anum_chunk_index_max - 1)
479
480 typedef struct FormData_chunk_index
481 {
482 int32 chunk_id;
483 NameData index_name;
484 int32 hypertable_id;
485 NameData hypertable_index_name;
486 } FormData_chunk_index;
487
488 typedef FormData_chunk_index *Form_chunk_index;
489
490 enum
491 {
492 CHUNK_INDEX_CHUNK_ID_INDEX_NAME_IDX = 0,
493 CHUNK_INDEX_HYPERTABLE_ID_HYPERTABLE_INDEX_NAME_IDX,
494 _MAX_CHUNK_INDEX_INDEX,
495 };
496
497 enum Anum_chunk_index_chunk_id_index_name_idx
498 {
499 Anum_chunk_index_chunk_id_index_name_idx_chunk_id = 1,
500 Anum_chunk_index_chunk_id_index_name_idx_index_name,
501 _Anum_chunk_index_chunk_id_index_name_idx_max,
502 };
503
504 enum Anum_chunk_index_hypertable_id_hypertable_index_name_idx
505 {
506 Anum_chunk_index_hypertable_id_hypertable_index_name_idx_hypertable_id = 1,
507 Anum_chunk_index_hypertable_id_hypertable_index_name_idx_hypertable_index_name,
508 Anum_chunk_index_hypertable_id_hypertable_index_name_idx_max,
509 };
510
511 /************************************
512 *
513 * Chunk data node table definitions
514 *
515 ************************************/
516
517 #define CHUNK_DATA_NODE_TABLE_NAME "chunk_data_node"
518
519 enum Anum_chunk_data_node
520 {
521 Anum_chunk_data_node_chunk_id = 1,
522 Anum_chunk_data_node_node_chunk_id,
523 Anum_chunk_data_node_node_name,
524 _Anum_chunk_data_node_max,
525 };
526
527 #define Natts_chunk_data_node (_Anum_chunk_data_node_max - 1)
528
529 typedef struct FormData_chunk_data_node
530 {
531 int32 chunk_id;
532 int32 node_chunk_id;
533 NameData node_name;
534 } FormData_chunk_data_node;
535
536 typedef FormData_chunk_data_node *Form_chunk_data_node;
537
538 enum
539 {
540 CHUNK_DATA_NODE_CHUNK_ID_NODE_NAME_IDX,
541 CHUNK_DATA_NODE_NODE_CHUNK_ID_NODE_NAME_IDX,
542 _MAX_CHUNK_DATA_NODE_INDEX,
543 };
544
545 enum Anum_chunk_data_node_chunk_id_node_name_idx
546 {
547 Anum_chunk_data_node_chunk_id_node_name_idx_chunk_id = 1,
548 Anum_chunk_data_node_chunk_id_node_name_idx_node_name,
549 _Anum_chunk_data_node_chunk_id_node_name_idx_max,
550 };
551
552 struct FormData_chunk_data_node_chunk_id_node_name_idx
553 {
554 int32 chunk_id;
555 NameData node_name;
556 };
557
558 enum Anum_chunk_data_node_node_chunk_id_node_name_idx
559 {
560 Anum_chunk_data_node_node_chunk_id_node_name_idx_chunk_id = 1,
561 Anum_chunk_data_node_node_chunk_id_node_name_idx_node_name,
562 _Anum_chunk_data_node_node_chunk_id_node_name_idx_max,
563 };
564
565 struct FormData_chunk_data_node_node_chunk_id_node_name_idx
566 {
567 int32 node_chunk_id;
568 NameData node_name;
569 };
570
571 /************************************
572 *
573 * Tablespace table definitions
574 *
575 ************************************/
576
577 #define TABLESPACE_TABLE_NAME "tablespace"
578
579 enum Anum_tablespace
580 {
581 Anum_tablespace_id = 1,
582 Anum_tablespace_hypertable_id,
583 Anum_tablespace_tablespace_name,
584 _Anum_tablespace_max,
585 };
586
587 #define Natts_tablespace (_Anum_tablespace_max - 1)
588
589 typedef struct FormData_tablespace
590 {
591 int32 id;
592 int32 hypertable_id;
593 NameData tablespace_name;
594 } FormData_tablespace;
595
596 typedef FormData_tablespace *Form_tablespace;
597
598 enum
599 {
600 TABLESPACE_PKEY_IDX = 0,
601 TABLESPACE_HYPERTABLE_ID_TABLESPACE_NAME_IDX,
602 _MAX_TABLESPACE_INDEX,
603 };
604
605 enum Anum_tablespace_pkey_idx
606 {
607 Anum_tablespace_pkey_idx_tablespace_id = 1,
608 _Anum_tablespace_pkey_idx_max,
609 };
610
611 typedef struct FormData_tablespace_pkey_idx
612 {
613 int32 tablespace_id;
614 } FormData_tablespace_pkey_idx;
615
616 enum Anum_tablespace_hypertable_id_tablespace_name_idx
617 {
618 Anum_tablespace_hypertable_id_tablespace_name_idx_hypertable_id = 1,
619 Anum_tablespace_hypertable_id_tablespace_name_idx_tablespace_name,
620 _Anum_tablespace_hypertable_id_tablespace_name_idx_max,
621 };
622
623 typedef struct FormData_tablespace_hypertable_id_tablespace_name_idx
624 {
625 int32 hypertable_id;
626 NameData tablespace_name;
627 } FormData_tablespace_hypertable_id_tablespace_name_idx;
628
629 /************************************
630 *
631 * bgw_job table definitions
632 *
633 ************************************/
634
635 #define BGW_JOB_TABLE_NAME "bgw_job"
636
637 enum Anum_bgw_job
638 {
639 Anum_bgw_job_id = 1,
640 Anum_bgw_job_application_name,
641 Anum_bgw_job_schedule_interval,
642 Anum_bgw_job_max_runtime,
643 Anum_bgw_job_max_retries,
644 Anum_bgw_job_retry_period,
645 Anum_bgw_job_proc_schema,
646 Anum_bgw_job_proc_name,
647 Anum_bgw_job_owner,
648 Anum_bgw_job_scheduled,
649 Anum_bgw_job_hypertable_id,
650 Anum_bgw_job_config,
651 _Anum_bgw_job_max,
652 };
653
654 #define Natts_bgw_job (_Anum_bgw_job_max - 1)
655
656 typedef struct FormData_bgw_job
657 {
658 int32 id;
659 NameData application_name;
660 Interval schedule_interval;
661 Interval max_runtime;
662 int32 max_retries;
663 Interval retry_period;
664 NameData proc_schema;
665 NameData proc_name;
666 NameData owner;
667 bool scheduled;
668 int32 hypertable_id;
669 Jsonb *config;
670 } FormData_bgw_job;
671
672 typedef FormData_bgw_job *Form_bgw_job;
673
674 enum
675 {
676 BGW_JOB_PKEY_IDX = 0,
677 BGW_JOB_PROC_HYPERTABLE_ID_IDX,
678 _MAX_BGW_JOB_INDEX,
679 };
680
681 enum Anum_bgw_job_pkey_idx
682 {
683 Anum_bgw_job_pkey_idx_id = 1,
684 _Anum_bgw_job_pkey_idx_max,
685 };
686
687 #define Natts_bjw_job_pkey_idx (_Anum_bgw_job_pkey_idx_max - 1)
688
689 enum Anum_bgw_job_proc_hypertable_id_idx
690 {
691 Anum_bgw_job_proc_hypertable_id_idx_proc_schema = 1,
692 Anum_bgw_job_proc_hypertable_id_idx_proc_name,
693 Anum_bgw_job_proc_hypertable_id_idx_hypertable_id,
694 _Anum_bgw_job_proc_hypertable_id_idx_max,
695 };
696
697 #define Natts_bgw_job_proc_hypertable_id_idx (_Anum_bgw_job_proc_hypertable_id_idx_max - 1)
698
699 /************************************
700 *
701 * bgw_job_stat table definitions
702 *
703 ************************************/
704
705 #define BGW_JOB_STAT_TABLE_NAME "bgw_job_stat"
706
707 enum Anum_bgw_job_stat
708 {
709 Anum_bgw_job_stat_job_id = 1,
710 Anum_bgw_job_stat_last_start,
711 Anum_bgw_job_stat_last_finish,
712 Anum_bgw_job_stat_next_start,
713 Anum_bgw_job_stat_last_successful_finish,
714 Anum_bgw_job_stat_last_run_success,
715 Anum_bgw_job_stat_total_runs,
716 Anum_bgw_job_stat_total_duration,
717 Anum_bgw_job_stat_total_success,
718 Anum_bgw_job_stat_total_failures,
719 Anum_bgw_job_stat_total_crashes,
720 Anum_bgw_job_stat_consecutive_failures,
721 Anum_bgw_job_stat_consecutive_crashes,
722 _Anum_bgw_job_stat_max,
723 };
724
725 #define Natts_bgw_job_stat (_Anum_bgw_job_stat_max - 1)
726
727 typedef struct FormData_bgw_job_stat
728 {
729 int32 id;
730 TimestampTz last_start;
731 TimestampTz last_finish;
732 TimestampTz next_start;
733 TimestampTz last_successful_finish;
734 bool last_run_success;
735 int64 total_runs;
736 Interval total_duration;
737 int64 total_success;
738 int64 total_failures;
739 int64 total_crashes;
740 int32 consecutive_failures;
741 int32 consecutive_crashes;
742 } FormData_bgw_job_stat;
743
744 typedef FormData_bgw_job_stat *Form_bgw_job_stat;
745
746 enum
747 {
748 BGW_JOB_STAT_PKEY_IDX = 0,
749 _MAX_BGW_JOB_STAT_INDEX,
750 };
751
752 enum Anum_bgw_job_stat_pkey_idx
753 {
754 Anum_bgw_job_stat_pkey_idx_job_id = 1,
755 _Anum_bgw_job_stat_pkey_idx_max,
756 };
757
758 #define Natts_bjw_job_stat_pkey_idx (_Anum_bgw_job_stat_pkey_idx_max - 1)
759
760 /******************************
761 *
762 * metadata table definitions
763 *
764 ******************************/
765
766 #define METADATA_TABLE_NAME "metadata"
767
768 enum Anum_metadata
769 {
770 Anum_metadata_key = 1,
771 Anum_metadata_value,
772 Anum_metadata_include_in_telemetry,
773 _Anum_metadata_max,
774 };
775
776 #define Natts_metadata (_Anum_metadata_max - 1)
777
778 typedef struct FormData_metadata
779 {
780 NameData key;
781 text *value;
782 } FormData_metadata;
783
784 typedef FormData_metadata *Form_metadata;
785
786 /* metadata primary index attribute numbers */
787 enum Anum_metadata_pkey_idx
788 {
789 Anum_metadata_pkey_idx_id = 1,
790 _Anum_metadata_pkey_max,
791 };
792
793 #define Natts_metadata_pkey_idx (_Anum_metadata_pkey_max - 1)
794
795 enum
796 {
797 METADATA_PKEY_IDX = 0,
798 _MAX_METADATA_INDEX,
799 };
800
801 /****** BGW_POLICY_CHUNK_STATS TABLE definitions */
802 #define BGW_POLICY_CHUNK_STATS_TABLE_NAME "bgw_policy_chunk_stats"
803
804 enum Anum_bgw_policy_chunk_stats
805 {
806 Anum_bgw_policy_chunk_stats_job_id = 1,
807 Anum_bgw_policy_chunk_stats_chunk_id,
808 Anum_bgw_policy_chunk_stats_num_times_job_run,
809 Anum_bgw_policy_chunk_stats_last_time_job_run,
810 _Anum_bgw_policy_chunk_stats_max,
811 };
812
813 #define Natts_bgw_policy_chunk_stats (_Anum_bgw_policy_chunk_stats_max - 1)
814
815 typedef struct FormData_bgw_policy_chunk_stats
816 {
817 int32 job_id;
818 int32 chunk_id;
819 int32 num_times_job_run;
820 TimestampTz last_time_job_run;
821 } FormData_bgw_policy_chunk_stats;
822
823 typedef FormData_bgw_policy_chunk_stats *Form_bgw_job_chunk_stats;
824
825 enum
826 {
827 BGW_POLICY_CHUNK_STATS_JOB_ID_CHUNK_ID_IDX = 0,
828 _MAX_BGW_POLICY_CHUNK_STATS_INDEX,
829 };
830
831 enum Anum_bgw_policy_chunk_stats_job_id_chunk_id_idx
832 {
833 Anum_bgw_policy_chunk_stats_job_id_chunk_id_idx_job_id = 1,
834 Anum_bgw_policy_chunk_stats_job_id_chunk_id_idx_chunk_id,
835 _Anum_bgw_policy_chunk_stats_job_id_chunk_id_idx_max,
836 };
837
838 typedef struct FormData_bgw_policy_chunk_stats_job_id_chunk_id_idx
839 {
840 int32 job_id;
841 int32 chunk_id;
842 } FormData_bgw_policy_chunk_stats_job_id_chunk_id_idx;
843
844 /******************************************
845 *
846 * continuous_agg table definitions
847 *
848 ******************************************/
849 #define CONTINUOUS_AGG_TABLE_NAME "continuous_agg"
850 typedef enum Anum_continuous_agg
851 {
852 Anum_continuous_agg_mat_hypertable_id = 1,
853 Anum_continuous_agg_raw_hypertable_id,
854 Anum_continuous_agg_user_view_schema,
855 Anum_continuous_agg_user_view_name,
856 Anum_continuous_agg_partial_view_schema,
857 Anum_continuous_agg_partial_view_name,
858 Anum_continuous_agg_bucket_width,
859 Anum_continuous_agg_direct_view_schema,
860 Anum_continuous_agg_direct_view_name,
861 Anum_continuous_agg_materialize_only,
862 _Anum_continuous_agg_max,
863 } Anum_continuous_agg;
864
865 #define Natts_continuous_agg (_Anum_continuous_agg_max - 1)
866
867 typedef struct FormData_continuous_agg
868 {
869 int32 mat_hypertable_id;
870 int32 raw_hypertable_id;
871 NameData user_view_schema;
872 NameData user_view_name;
873 NameData partial_view_schema;
874 NameData partial_view_name;
875 /*
876 * Don't access bucket_width directly to determine the width of the bucket.
877 * Use corresponding procedures instead:
878 * - ts_continuous_agg_bucket_width
879 * - ts_continuous_agg_max_bucket_width
880 */
881 int64 bucket_width;
882 NameData direct_view_schema;
883 NameData direct_view_name;
884 bool materialized_only;
885 } FormData_continuous_agg;
886
887 typedef FormData_continuous_agg *Form_continuous_agg;
888
889 enum
890 {
891 CONTINUOUS_AGG_PARTIAL_VIEW_SCHEMA_PARTIAL_VIEW_NAME_KEY = 0,
892 CONTINUOUS_AGG_PKEY,
893 CONTINUOUS_AGG_USER_VIEW_SCHEMA_USER_VIEW_NAME_KEY,
894 CONTINUOUS_AGG_RAW_HYPERTABLE_ID_IDX,
895 _MAX_CONTINUOUS_AGG_INDEX,
896 };
897
898 typedef enum Anum_continuous_agg_partial_view_schema_partial_view_name_key
899 {
900 Anum_continuous_agg_partial_view_schema_partial_view_name_key_partial_view_schema = 1,
901 Anum_continuous_agg_partial_view_schema_partial_view_name_key_partial_view_name,
902 _Anum_continuous_agg_partial_view_schema_partial_view_name_key_max,
903 } Anum_continuous_agg_partial_view_schema_partial_view_name_key;
904
905 #define Natts_continuous_agg_partial_view_schema_partial_view_name_key \
906 (_Anum_continuous_agg_partial_view_schema_partial_view_name_key_max - 1)
907
908 typedef enum Anum_continuous_agg_pkey
909 {
910 Anum_continuous_agg_pkey_mat_hypertable_id = 1,
911 _Anum_continuous_agg_pkey_max,
912 } Anum_continuous_agg_pkey;
913
914 #define Natts_continuous_agg_pkey (_Anum_continuous_agg_pkey_max - 1)
915
916 typedef enum Anum_continuous_agg_user_view_schema_user_view_name_key
917 {
918 Anum_continuous_agg_user_view_schema_user_view_name_key_user_view_schema = 1,
919 Anum_continuous_agg_user_view_schema_user_view_name_key_user_view_name,
920 _Anum_continuous_agg_user_view_schema_user_view_name_key_max,
921 } Anum_continuous_agg_user_view_schema_user_view_name_key;
922
923 #define Natts_continuous_agg_user_view_schema_user_view_name_key \
924 (_Anum_continuous_agg_user_view_schema_user_view_name_key_max - 1)
925
926 typedef enum Anum_continuous_agg_raw_hypertable_id_idx
927 {
928 Anum_continuous_agg_raw_hypertable_id_idx_raw_hypertable_id = 1,
929 _Anum_continuous_agg_raw_hypertable_id_idx_max,
930 } Anum_continuous_agg_raw_hypertable_id_idx;
931
932 #define Natts_continuous_agg_raw_hypertable_id_idx \
933 (_Anum_continuous_agg_raw_hypertable_id_idx_max - 1)
934
935 /****** CONTINUOUS_AGGS_HYPERTABLE_INVALIDATION_LOG_TABLE definitions*/
936 #define CONTINUOUS_AGGS_HYPERTABLE_INVALIDATION_LOG_TABLE_NAME \
937 "continuous_aggs_hypertable_invalidation_log"
938 typedef enum Anum_continuous_aggs_hypertable_invalidation_log
939 {
940 Anum_continuous_aggs_hypertable_invalidation_log_hypertable_id = 1,
941 Anum_continuous_aggs_hypertable_invalidation_log_lowest_modified_value,
942 Anum_continuous_aggs_hypertable_invalidation_log_greatest_modified_value,
943 _Anum_continuous_aggs_hypertable_invalidation_log_max,
944 } Anum_continuous_aggs_hypertable_invalidation_log;
945
946 #define Natts_continuous_aggs_hypertable_invalidation_log \
947 (_Anum_continuous_aggs_hypertable_invalidation_log_max - 1)
948
949 typedef struct FormData_continuous_aggs_hypertable_invalidation_log
950 {
951 int32 hypertable_id;
952 int64 lowest_modified_value;
953 int64 greatest_modified_value;
954 } FormData_continuous_aggs_hypertable_invalidation_log;
955
956 typedef FormData_continuous_aggs_hypertable_invalidation_log
957 *Form_continuous_aggs_hypertable_invalidation_log;
958
959 enum
960 {
961 CONTINUOUS_AGGS_HYPERTABLE_INVALIDATION_LOG_IDX = 0,
962 _MAX_CONTINUOUS_AGGS_HYPERTABLE_INVALIDATION_LOG_INDEX,
963 };
964 typedef enum Anum_continuous_aggs_hypertable_invalidation_log_idx
965 {
966 Anum_continuous_aggs_hypertable_invalidation_log_idx_hypertable_id = 1,
967 Anum_continuous_aggs_hypertable_invalidation_log_idx_lowest_modified_value,
968 _Anum_continuous_aggs_hypertable_invalidation_log_idx_max,
969 } Anum_continuous_aggs_hypertable_invalidation_log_idx;
970
971 #define Natts_continuous_aggs_hypertable_invalidation_log_idx \
972 (_Anum_continuous_aggs_hypertable_invalidation_log_idx_max - 1)
973
974 /****** CONTINUOUS_AGGS_INVALIDATION_THRESHOLD_TABLE definitions*/
975 #define CONTINUOUS_AGGS_INVALIDATION_THRESHOLD_TABLE_NAME "continuous_aggs_invalidation_threshold"
976 typedef enum Anum_continuous_aggs_invalidation_threshold
977 {
978 Anum_continuous_aggs_invalidation_threshold_hypertable_id = 1,
979 Anum_continuous_aggs_invalidation_threshold_watermark,
980 _Anum_continuous_aggs_invalidation_threshold_max,
981 } Anum_continuous_aggs_invalidation_threshold;
982
983 #define Natts_continuous_aggs_invalidation_threshold \
984 (_Anum_continuous_aggs_invalidation_threshold_max - 1)
985
986 typedef struct FormData_continuous_aggs_invalidation_threshold
987 {
988 int32 hypertable_id;
989 int64 watermark;
990 } FormData_continuous_aggs_invalidation_threshold;
991
992 typedef FormData_continuous_aggs_invalidation_threshold
993 *Form_continuous_aggs_invalidation_threshold;
994
995 enum
996 {
997 CONTINUOUS_AGGS_INVALIDATION_THRESHOLD_PKEY = 0,
998 _MAX_CONTINUOUS_AGGS_INVALIDATION_THRESHOLD_INDEX,
999 };
1000 typedef enum Anum_continuous_aggs_invalidation_threshold_pkey
1001 {
1002 Anum_continuous_aggs_invalidation_threshold_pkey_hypertable_id = 1,
1003 _Anum_continuous_aggs_invalidation_threshold_pkey_max,
1004 } Anum_continuous_aggs_invalidation_threshold_pkey;
1005
1006 #define Natts_continuous_aggs_invalidation_threshold_pkey \
1007 (_Anum_continuous_aggs_invalidation_threshold_pkey_max - 1)
1008
1009 /****** CONTINUOUS_AGGS_MATERIALIZATION_INVALIDATION_LOG_TABLE definitions*/
1010 #define CONTINUOUS_AGGS_MATERIALIZATION_INVALIDATION_LOG_TABLE_NAME \
1011 "continuous_aggs_materialization_invalidation_log"
1012 typedef enum Anum_continuous_aggs_materialization_invalidation_log
1013 {
1014 Anum_continuous_aggs_materialization_invalidation_log_materialization_id = 1,
1015 Anum_continuous_aggs_materialization_invalidation_log_lowest_modified_value,
1016 Anum_continuous_aggs_materialization_invalidation_log_greatest_modified_value,
1017 _Anum_continuous_aggs_materialization_invalidation_log_max,
1018 } Anum_continuous_aggs_materialization_invalidation_log;
1019
1020 #define Natts_continuous_aggs_materialization_invalidation_log \
1021 (_Anum_continuous_aggs_materialization_invalidation_log_max - 1)
1022
1023 typedef struct FormData_continuous_aggs_materialization_invalidation_log
1024 {
1025 int32 materialization_id;
1026 int64 lowest_modified_value;
1027 int64 greatest_modified_value;
1028 } FormData_continuous_aggs_materialization_invalidation_log;
1029
1030 typedef FormData_continuous_aggs_materialization_invalidation_log
1031 *Form_continuous_aggs_materialization_invalidation_log;
1032
1033 enum
1034 {
1035 CONTINUOUS_AGGS_MATERIALIZATION_INVALIDATION_LOG_IDX = 0,
1036 _MAX_CONTINUOUS_AGGS_MATERIALIZATION_INVALIDATION_LOG_INDEX,
1037 };
1038 typedef enum Anum_continuous_aggs_materialization_invalidation_log_idx
1039 {
1040 Anum_continuous_aggs_materialization_invalidation_log_idx_materialization_id = 1,
1041 Anum_continuous_aggs_materialization_invalidation_log_idx_lowest_modified_value,
1042 _Anum_continuous_aggs_materialization_invalidation_log_idx_max,
1043 } Anum_continuous_aggs_materialization_invalidation_log_idx;
1044
1045 #define Natts_continuous_aggs_materialization_invalidation_log_idx \
1046 (_Anum_continuous_aggs_materialization_invalidation_log_idx_max - 1)
1047
1048 #define HYPERTABLE_COMPRESSION_TABLE_NAME "hypertable_compression"
1049 typedef enum Anum_hypertable_compression
1050 {
1051 Anum_hypertable_compression_hypertable_id = 1,
1052 Anum_hypertable_compression_attname,
1053 Anum_hypertable_compression_algo_id,
1054 Anum_hypertable_compression_segmentby_column_index,
1055 Anum_hypertable_compression_orderby_column_index,
1056 Anum_hypertable_compression_orderby_asc,
1057 Anum_hypertable_compression_orderby_nullsfirst,
1058 _Anum_hypertable_compression_max,
1059 } Anum_hypertable_compression;
1060
1061 #define Natts_hypertable_compression (_Anum_hypertable_compression_max - 1)
1062
1063 typedef struct FormData_hypertable_compression
1064 {
1065 int32 hypertable_id;
1066 NameData attname;
1067 int16 algo_id;
1068 int16 segmentby_column_index;
1069 int16 orderby_column_index;
1070 bool orderby_asc;
1071 bool orderby_nullsfirst;
1072 } FormData_hypertable_compression;
1073
1074 typedef FormData_hypertable_compression *Form_hypertable_compression;
1075
1076 enum
1077 {
1078 HYPERTABLE_COMPRESSION_PKEY = 0,
1079 _MAX_HYPERTABLE_COMPRESSION_INDEX,
1080 };
1081 typedef enum Anum_hypertable_compression_pkey
1082 {
1083 Anum_hypertable_compression_pkey_hypertable_id = 1,
1084 Anum_hypertable_compression_pkey_attname,
1085 _Anum_hypertable_compression_pkey_max,
1086 } Anum_hypertable_compression_pkey;
1087
1088 #define Natts_hypertable_compression_pkey (_Anum_hypertable_compression_pkey_max - 1)
1089
1090 #define COMPRESSION_CHUNK_SIZE_TABLE_NAME "compression_chunk_size"
1091 typedef enum Anum_compression_chunk_size
1092 {
1093 Anum_compression_chunk_size_chunk_id = 1,
1094 Anum_compression_chunk_size_compressed_chunk_id,
1095 Anum_compression_chunk_size_uncompressed_heap_size,
1096 Anum_compression_chunk_size_uncompressed_toast_size,
1097 Anum_compression_chunk_size_uncompressed_index_size,
1098 Anum_compression_chunk_size_compressed_heap_size,
1099 Anum_compression_chunk_size_compressed_toast_size,
1100 Anum_compression_chunk_size_compressed_index_size,
1101 Anum_compression_chunk_size_numrows_pre_compression,
1102 Anum_compression_chunk_size_numrows_post_compression,
1103 _Anum_compression_chunk_size_max,
1104 } Anum_compression_chunk_size;
1105
1106 #define Natts_compression_chunk_size (_Anum_compression_chunk_size_max - 1)
1107
1108 typedef struct FormData_compression_chunk_size
1109 {
1110 int32 chunk_id;
1111 int32 compressed_chunk_id;
1112 int64 uncompressed_heap_size;
1113 int64 uncompressed_toast_size;
1114 int64 uncompressed_index_size;
1115 int64 compressed_heap_size;
1116 int64 compressed_toast_size;
1117 int64 compressed_index_size;
1118 int64 numrows_pre_compression;
1119 int64 numrows_post_compression;
1120 } FormData_compression_chunk_size;
1121
1122 typedef FormData_compression_chunk_size *Form_compression_chunk_size;
1123
1124 enum
1125 {
1126 COMPRESSION_CHUNK_SIZE_PKEY = 0,
1127 _MAX_COMPRESSION_CHUNK_SIZE_INDEX,
1128 };
1129 typedef enum Anum_compression_chunk_size_pkey
1130 {
1131 Anum_compression_chunk_size_pkey_chunk_id = 1,
1132 Anum_compression_chunk_size_pkey_compressed_chunk_id,
1133 _Anum_compression_chunk_size_pkey_max,
1134 } Anum_compression_chunk_size_pkey;
1135
1136 #define Natts_compression_chunk_size_pkey (_Anum_compression_chunk_size_pkey_max - 1)
1137
1138 /*
1139 * The maximum number of indexes a catalog table can have.
1140 * This needs to be bumped in case of new catalog tables that have more indexes.
1141 */
1142 #define _MAX_TABLE_INDEXES 5
1143 /************************************
1144 *
1145 * Remote txn table of 2pc commits
1146 *
1147 ************************************/
1148
1149 #define REMOTE_TXN_TABLE_NAME "remote_txn"
1150
1151 enum Anum_remote_txn
1152 {
1153 Anum_remote_txn_data_node_name = 1,
1154 Anum_remote_txn_remote_transaction_id,
1155 _Anum_remote_txn_max,
1156 };
1157
1158 #define Natts_remote_txn (_Anum_remote_txn_max - 1)
1159
1160 typedef struct FormData_remote_txn
1161 {
1162 NameData data_node_name;
1163 text *remote_transaction_id;
1164 } FormData_remote_txn;
1165
1166 typedef FormData_remote_txn *Form_remote_txn;
1167
1168 enum
1169 {
1170 REMOTE_TXN_PKEY_IDX = 0,
1171 REMOTE_TXN_DATA_NODE_NAME_IDX,
1172 _MAX_REMOTE_TXN_INDEX,
1173 };
1174
1175 enum Anum_remote_txn_pkey_idx
1176 {
1177 Anum_remote_txn_pkey_idx_remote_transaction_id = 1,
1178 _Anum_remote_txn_pkey_idx_max,
1179 };
1180
1181 enum Anum_remote_data_node_name_idx
1182 {
1183 Anum_remote_txn_data_node_name_idx_data_node_name = 1,
1184 _Anum_remote_txn_data_node_name_idx_max,
1185 };
1186
1187 /********************************************
1188 *
1189 * table to track chunk copy/move operations
1190 *
1191 ********************************************/
1192
1193 #define CHUNK_COPY_OPERATION_TABLE_NAME "chunk_copy_operation"
1194
1195 enum Anum_chunk_copy_operation
1196 {
1197 Anum_chunk_copy_operation_operation_id = 1,
1198 Anum_chunk_copy_operation_backend_pid,
1199 Anum_chunk_copy_operation_completed_stage,
1200 Anum_chunk_copy_operation_time_start,
1201 Anum_chunk_copy_operation_chunk_id,
1202 Anum_chunk_copy_operation_source_node_name,
1203 Anum_chunk_copy_operation_dest_node_name,
1204 Anum_chunk_copy_operation_delete_on_src_node,
1205 _Anum_chunk_copy_operation_max,
1206 };
1207
1208 #define Natts_chunk_copy_operation (_Anum_chunk_copy_operation_max - 1)
1209
1210 typedef struct FormData_chunk_copy_operation
1211 {
1212 NameData operation_id;
1213 int32 backend_pid;
1214 NameData completed_stage;
1215 TimestampTz time_start;
1216 int32 chunk_id;
1217 NameData source_node_name;
1218 NameData dest_node_name;
1219 bool delete_on_src_node;
1220 } FormData_chunk_copy_operation;
1221
1222 enum
1223 {
1224 CHUNK_COPY_OPERATION_PKEY_IDX = 0,
1225 _MAX_CHUNK_COPY_OPERATION_INDEX,
1226 };
1227
1228 enum Anum_chunk_copy_operation_pkey_idx
1229 {
1230 Anum_chunk_copy_operation_idx_operation_id = 1,
1231 _Anum_chunk_copy_operation_pkey_idx_max,
1232 };
1233
1234 typedef enum CacheType
1235 {
1236 CACHE_TYPE_HYPERTABLE,
1237 CACHE_TYPE_BGW_JOB,
1238 _MAX_CACHE_TYPES
1239 } CacheType;
1240
1241 typedef struct CatalogTableInfo
1242 {
1243 const char *schema_name;
1244 const char *name;
1245 Oid id;
1246 Oid serial_relid;
1247 Oid index_ids[_MAX_TABLE_INDEXES];
1248 } CatalogTableInfo;
1249
1250 typedef struct CatalogDatabaseInfo
1251 {
1252 char database_name[NAMEDATALEN];
1253 Oid database_id;
1254 Oid schema_id;
1255 Oid owner_uid;
1256 } CatalogDatabaseInfo;
1257
1258 typedef struct Catalog
1259 {
1260 CatalogTableInfo tables[_MAX_CATALOG_TABLES];
1261
1262 Oid cache_schema_id;
1263 struct
1264 {
1265 Oid inval_proxy_id;
1266 } caches[_MAX_CACHE_TYPES];
1267
1268 Oid internal_schema_id;
1269 struct
1270 {
1271 Oid function_id;
1272 } functions[_MAX_INTERNAL_FUNCTIONS];
1273
1274 bool initialized;
1275 } Catalog;
1276
1277 typedef struct CatalogSecurityContext
1278 {
1279 Oid saved_uid;
1280 int saved_security_context;
1281 } CatalogSecurityContext;
1282
1283 extern void ts_catalog_table_info_init(CatalogTableInfo *tables, int max_table,
1284 const TableInfoDef *table_ary,
1285 const TableIndexDef *index_ary, const char **serial_id_ary);
1286
1287 extern TSDLLEXPORT CatalogDatabaseInfo *ts_catalog_database_info_get(void);
1288 extern TSDLLEXPORT Catalog *ts_catalog_get(void);
1289 extern void ts_catalog_reset(void);
1290
1291 /* Functions should operate on a passed-in Catalog struct */
1292 static inline Oid
catalog_get_table_id(Catalog * catalog,CatalogTable tableid)1293 catalog_get_table_id(Catalog *catalog, CatalogTable tableid)
1294 {
1295 return catalog->tables[tableid].id;
1296 }
1297
1298 static inline Oid
catalog_get_index(Catalog * catalog,CatalogTable tableid,int indexid)1299 catalog_get_index(Catalog *catalog, CatalogTable tableid, int indexid)
1300 {
1301 return (indexid == INVALID_INDEXID) ? InvalidOid : catalog->tables[tableid].index_ids[indexid];
1302 }
1303
1304 extern TSDLLEXPORT int64 ts_catalog_table_next_seq_id(const Catalog *catalog, CatalogTable table);
1305 extern Oid ts_catalog_get_cache_proxy_id(Catalog *catalog, CacheType type);
1306
1307 /* Functions that modify the actual catalog table on disk */
1308 extern TSDLLEXPORT bool ts_catalog_database_info_become_owner(CatalogDatabaseInfo *database_info,
1309 CatalogSecurityContext *sec_ctx);
1310 extern TSDLLEXPORT void ts_catalog_restore_user(CatalogSecurityContext *sec_ctx);
1311
1312 extern TSDLLEXPORT void ts_catalog_insert_only(Relation rel, HeapTuple tuple);
1313 extern TSDLLEXPORT void ts_catalog_insert(Relation rel, HeapTuple tuple);
1314 extern TSDLLEXPORT void ts_catalog_insert_values(Relation rel, TupleDesc tupdesc, Datum *values,
1315 bool *nulls);
1316 extern TSDLLEXPORT void ts_catalog_update_tid_only(Relation rel, ItemPointer tid, HeapTuple tuple);
1317 extern TSDLLEXPORT void ts_catalog_update_tid(Relation rel, ItemPointer tid, HeapTuple tuple);
1318 extern TSDLLEXPORT void ts_catalog_update(Relation rel, HeapTuple tuple);
1319 extern TSDLLEXPORT void ts_catalog_delete_tid_only(Relation rel, ItemPointer tid);
1320 extern TSDLLEXPORT void ts_catalog_delete_tid(Relation rel, ItemPointer tid);
1321 extern TSDLLEXPORT void ts_catalog_delete_only(Relation rel, HeapTuple tuple);
1322 extern TSDLLEXPORT void ts_catalog_delete(Relation rel, HeapTuple tuple);
1323 extern void ts_catalog_invalidate_cache(Oid catalog_relid, CmdType operation);
1324
1325 bool TSDLLEXPORT ts_catalog_scan_one(CatalogTable table, int indexid, ScanKeyData *scankey,
1326 int num_keys, tuple_found_func tuple_found, LOCKMODE lockmode,
1327 char *policy_type, void *data);
1328 void TSDLLEXPORT ts_catalog_scan_all(CatalogTable table, int indexid, ScanKeyData *scankey,
1329 int num_keys, tuple_found_func tuple_found, LOCKMODE lockmode,
1330 void *data);
1331
1332 #endif /* TIMESCALEDB_CATALOG_H */
1333