1 /*
2 * brin_internal.h
3 * internal declarations for BRIN indexes
4 *
5 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
6 * Portions Copyright (c) 1994, Regents of the University of California
7 *
8 * IDENTIFICATION
9 * src/include/access/brin_internal.h
10 */
11 #ifndef BRIN_INTERNAL_H
12 #define BRIN_INTERNAL_H
13
14 #include "access/amapi.h"
main(String[] args)15 #include "storage/bufpage.h"
16 #include "utils/typcache.h"
17
18
19 /*
20 * A BrinDesc is a struct designed to enable decoding a BRIN tuple from the
21 * on-disk format to an in-memory tuple and vice-versa.
22 */
23
24 /* struct returned by "OpcInfo" amproc */
25 typedef struct BrinOpcInfo
26 {
27 /* Number of columns stored in an index column of this opclass */
28 uint16 oi_nstored;
29
30 /* Opaque pointer for the opclass' private use */
31 void *oi_opaque;
32
33 /* Type cache entries of the stored columns */
34 TypeCacheEntry *oi_typcache[FLEXIBLE_ARRAY_MEMBER];
35 } BrinOpcInfo;
36
37 /* the size of a BrinOpcInfo for the given number of columns */
38 #define SizeofBrinOpcInfo(ncols) \
39 (offsetof(BrinOpcInfo, oi_typcache) + sizeof(TypeCacheEntry *) * ncols)
40
41 typedef struct BrinDesc
42 {
43 /* Containing memory context */
44 MemoryContext bd_context;
45
46 /* the index relation itself */
47 Relation bd_index;
48
49 /* tuple descriptor of the index relation */
50 TupleDesc bd_tupdesc;
51
52 /* cached copy for on-disk tuples; generated at first use */
53 TupleDesc bd_disktdesc;
54
55 /* total number of Datum entries that are stored on-disk for all columns */
56 int bd_totalstored;
57
58 /* per-column info; bd_tupdesc->natts entries long */
59 BrinOpcInfo *bd_info[FLEXIBLE_ARRAY_MEMBER];
60 } BrinDesc;
61
62 /*
63 * Globally-known function support numbers for BRIN indexes. Individual
64 * opclasses can define more function support numbers, which must fall into
65 * BRIN_FIRST_OPTIONAL_PROCNUM .. BRIN_LAST_OPTIONAL_PROCNUM.
66 */
67 #define BRIN_PROCNUM_OPCINFO 1
68 #define BRIN_PROCNUM_ADDVALUE 2
69 #define BRIN_PROCNUM_CONSISTENT 3
70 #define BRIN_PROCNUM_UNION 4
71 #define BRIN_MANDATORY_NPROCS 4
72 /* procedure numbers up to 10 are reserved for BRIN future expansion */
73 #define BRIN_FIRST_OPTIONAL_PROCNUM 11
74 #define BRIN_LAST_OPTIONAL_PROCNUM 15
75
76 #undef BRIN_DEBUG
77
78 #ifdef BRIN_DEBUG
79 #define BRIN_elog(args) elog args
80 #else
81 #define BRIN_elog(args) ((void) 0)
82 #endif
83
84 /* brin.c */
85 extern BrinDesc *brin_build_desc(Relation rel);
86 extern void brin_free_desc(BrinDesc *bdesc);
87 extern IndexBuildResult *brinbuild(Relation heap, Relation index,
88 struct IndexInfo *indexInfo);
89 extern void brinbuildempty(Relation index);
90 extern bool brininsert(Relation idxRel, Datum *values, bool *nulls,
91 ItemPointer heaptid, Relation heapRel,
92 IndexUniqueCheck checkUnique,
93 struct IndexInfo *indexInfo);
94 extern IndexScanDesc brinbeginscan(Relation r, int nkeys, int norderbys);
95 extern int64 bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
96 extern void brinrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
97 ScanKey orderbys, int norderbys);
98 extern void brinendscan(IndexScanDesc scan);
99 extern IndexBulkDeleteResult *brinbulkdelete(IndexVacuumInfo *info,
100 IndexBulkDeleteResult *stats,
101 IndexBulkDeleteCallback callback,
102 void *callback_state);
103 extern IndexBulkDeleteResult *brinvacuumcleanup(IndexVacuumInfo *info,
104 IndexBulkDeleteResult *stats);
105 extern bytea *brinoptions(Datum reloptions, bool validate);
106
107 /* brin_validate.c */
108 extern bool brinvalidate(Oid opclassoid);
109
110 #endif /* BRIN_INTERNAL_H */
111