1/*-------------------------------------------------------------------------
2 *
3 * brin_xlog.h
4 * POSTGRES BRIN access XLOG definitions.
5 *
6 *
7 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/access/brin_xlog.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef BRIN_XLOG_H
15#define BRIN_XLOG_H
16
17#include "access/xlogreader.h"
18#include "lib/stringinfo.h"
19#include "storage/bufpage.h"
20#include "storage/itemptr.h"
21#include "storage/relfilenode.h"
22#include "utils/relcache.h"
23
24
25/*
26 * WAL record definitions for BRIN's WAL operations
27 *
28 * XLOG allows to store some information in high 4 bits of log
29 * record xl_info field.
30 */
31#define XLOG_BRIN_CREATE_INDEX 0x00
32#define XLOG_BRIN_INSERT 0x10
33#define XLOG_BRIN_UPDATE 0x20
34#define XLOG_BRIN_SAMEPAGE_UPDATE 0x30
35#define XLOG_BRIN_REVMAP_EXTEND 0x40
36#define XLOG_BRIN_DESUMMARIZE 0x50
37
38#define XLOG_BRIN_OPMASK 0x70
39/*
40 * When we insert the first item on a new page, we restore the entire page in
41 * redo.
42 */
43#define XLOG_BRIN_INIT_PAGE 0x80
44
45/*
46 * This is what we need to know about a BRIN index create.
47 *
48 * Backup block 0: metapage
49 */
50typedef struct xl_brin_createidx
51{
52 BlockNumber pagesPerRange;
53 uint16 version;
54} xl_brin_createidx;
55#define SizeOfBrinCreateIdx (offsetof(xl_brin_createidx, version) + sizeof(uint16))
56
57/*
58 * This is what we need to know about a BRIN tuple insert
59 *
60 * Backup block 0: main page, block data is the new BrinTuple.
61 * Backup block 1: revmap page
62 */
63typedef struct xl_brin_insert
64{
65 BlockNumber heapBlk;
66
67 /* extra information needed to update the revmap */
68 BlockNumber pagesPerRange;
69
70 /* offset number in the main page to insert the tuple to. */
71 OffsetNumber offnum;
72} xl_brin_insert;
73
74#define SizeOfBrinInsert (offsetof(xl_brin_insert, offnum) + sizeof(OffsetNumber))
75
76/*
77 * A cross-page update is the same as an insert, but also stores information
78 * about the old tuple.
79 *
80 * Like in xlog_brin_update:
81 * Backup block 0: new page, block data includes the new BrinTuple.
82 * Backup block 1: revmap page
83 *
84 * And in addition:
85 * Backup block 2: old page
86 */
87typedef struct xl_brin_update
88{
89 /* offset number of old tuple on old page */
90 OffsetNumber oldOffnum;
91
92 xl_brin_insert insert;
93} xl_brin_update;
94
95#define SizeOfBrinUpdate (offsetof(xl_brin_update, insert) + SizeOfBrinInsert)
96
97/*
98 * This is what we need to know about a BRIN tuple samepage update
99 *
100 * Backup block 0: updated page, with new BrinTuple as block data
101 */
102typedef struct xl_brin_samepage_update
103{
104 OffsetNumber offnum;
105} xl_brin_samepage_update;
106
107#define SizeOfBrinSamepageUpdate (sizeof(OffsetNumber))
108
109/*
110 * This is what we need to know about a revmap extension
111 *
112 * Backup block 0: metapage
113 * Backup block 1: new revmap page
114 */
115typedef struct xl_brin_revmap_extend
116{
117 /*
118 * XXX: This is actually redundant - the block number is stored as part of
119 * backup block 1.
120 */
121 BlockNumber targetBlk;
122} xl_brin_revmap_extend;
123
124#define SizeOfBrinRevmapExtend (offsetof(xl_brin_revmap_extend, targetBlk) + \
125 sizeof(BlockNumber))
126
127/*
128 * This is what we need to know about a range de-summarization
129 *
130 * Backup block 0: revmap page
131 * Backup block 1: regular page
132 */
133typedef struct xl_brin_desummarize
134{
135 BlockNumber pagesPerRange;
136 /* page number location to set to invalid */
137 BlockNumber heapBlk;
138 /* offset of item to delete in regular index page */
139 OffsetNumber regOffset;
140} xl_brin_desummarize;
141
142#define SizeOfBrinDesummarize (offsetof(xl_brin_desummarize, regOffset) + \
143 sizeof(OffsetNumber))
144
145
146extern void brin_redo(XLogReaderState *record);
147extern void brin_desc(StringInfo buf, XLogReaderState *record);
148extern const char *brin_identify(uint8 info);
149extern void brin_mask(char *pagedata, BlockNumber blkno);
150
151#endif /* BRIN_XLOG_H */
152