PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ginxlog.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------
2  * ginxlog.h
3  * header file for postgres inverted index xlog implementation.
4  *
5  * Copyright (c) 2006-2017, PostgreSQL Global Development Group
6  *
7  * src/include/access/ginxlog.h
8  *--------------------------------------------------------------------------
9  */
10 #ifndef GINXLOG_H
11 #define GINXLOG_H
12 
13 #include "access/ginblock.h"
14 #include "access/itup.h"
15 #include "access/xlogreader.h"
16 #include "lib/stringinfo.h"
17 #include "storage/off.h"
18 
19 #define XLOG_GIN_CREATE_INDEX 0x00
20 
21 #define XLOG_GIN_CREATE_PTREE 0x10
22 
24 {
26  /* A compressed posting list follows */
28 
29 /*
30  * The format of the insertion record varies depending on the page type.
31  * ginxlogInsert is the common part between all variants.
32  *
33  * Backup Blk 0: target page
34  * Backup Blk 1: left child, if this insertion finishes an incomplete split
35  */
36 
37 #define XLOG_GIN_INSERT 0x20
38 
39 typedef struct
40 {
41  uint16 flags; /* GIN_INSERT_ISLEAF and/or GIN_INSERT_ISDATA */
42 
43  /*
44  * FOLLOWS:
45  *
46  * 1. if not leaf page, block numbers of the left and right child pages
47  * whose split this insertion finishes, as BlockIdData[2] (beware of
48  * adding fields in this struct that would make them not 16-bit aligned)
49  *
50  * 2. a ginxlogInsertEntry or ginxlogRecompressDataLeaf struct, depending
51  * on tree type.
52  *
53  * NB: the below structs are only 16-bit aligned when appended to a
54  * ginxlogInsert struct! Beware of adding fields to them that require
55  * stricter alignment.
56  */
58 
59 typedef struct
60 {
62  bool isDelete;
63  IndexTupleData tuple; /* variable length */
65 
66 
67 typedef struct
68 {
70 
71  /* Variable number of 'actions' follow */
73 
74 /*
75  * Note: this struct is currently not used in code, and only acts as
76  * documentation. The WAL record format is as specified here, but the code
77  * uses straight access through a Pointer and memcpy to read/write these.
78  */
79 typedef struct
80 {
81  uint8 segno; /* segment this action applies to */
82  char type; /* action type (see below) */
83 
84  /*
85  * Action-specific data follows. For INSERT and REPLACE actions that is a
86  * GinPostingList struct. For ADDITEMS, a uint16 for the number of items
87  * added, followed by the items themselves as ItemPointers. DELETE actions
88  * have no further data.
89  */
91 
92 /* Action types */
93 #define GIN_SEGMENT_UNMODIFIED 0 /* no action (not used in WAL records) */
94 #define GIN_SEGMENT_DELETE 1 /* a whole segment is removed */
95 #define GIN_SEGMENT_INSERT 2 /* a whole segment is added */
96 #define GIN_SEGMENT_REPLACE 3 /* a segment is replaced */
97 #define GIN_SEGMENT_ADDITEMS 4 /* items are added to existing segment */
98 
99 typedef struct
100 {
104 
105 /*
106  * Backup Blk 0: new left page (= original page, if not root split)
107  * Backup Blk 1: new right page
108  * Backup Blk 2: original page / new root page, if root split
109  * Backup Blk 3: left child, if this insertion completes an earlier split
110  */
111 #define XLOG_GIN_SPLIT 0x30
112 
113 typedef struct ginxlogSplit
114 {
116  BlockNumber rrlink; /* right link, or root's blocknumber if root
117  * split */
118  BlockNumber leftChildBlkno; /* valid on a non-leaf split */
120  uint16 flags; /* see below */
121 } ginxlogSplit;
122 
123 /*
124  * Flags used in ginxlogInsert and ginxlogSplit records
125  */
126 #define GIN_INSERT_ISDATA 0x01 /* for both insert and split records */
127 #define GIN_INSERT_ISLEAF 0x02 /* ditto */
128 #define GIN_SPLIT_ROOT 0x04 /* only for split records */
129 
130 /*
131  * Vacuum simply WAL-logs the whole page, when anything is modified. This
132  * is functionally identical to heap_newpage records, but is kept separate for
133  * debugging purposes. (When inspecting the WAL stream, it's easier to see
134  * what's going on when GIN vacuum records are marked as such, not as heap
135  * records.) This is currently only used for entry tree leaf pages.
136  */
137 #define XLOG_GIN_VACUUM_PAGE 0x40
138 
139 /*
140  * Vacuuming posting tree leaf page is WAL-logged like recompression caused
141  * by insertion.
142  */
143 #define XLOG_GIN_VACUUM_DATA_LEAF_PAGE 0x90
144 
146 {
149 
150 /*
151  * Backup Blk 0: deleted page
152  * Backup Blk 1: parent
153  * Backup Blk 2: left sibling
154  */
155 #define XLOG_GIN_DELETE_PAGE 0x50
156 
157 typedef struct ginxlogDeletePage
158 {
162 
163 #define XLOG_GIN_UPDATE_META_PAGE 0x60
164 
165 /*
166  * Backup Blk 0: metapage
167  * Backup Blk 1: tail page
168  */
169 typedef struct ginxlogUpdateMeta
170 {
175  int32 ntuples; /* if ntuples > 0 then metadata.tail was
176  * updated with that many tuples; else new sub
177  * list was inserted */
178  /* array of inserted tuples follows */
180 
181 #define XLOG_GIN_INSERT_LISTPAGE 0x70
182 
183 typedef struct ginxlogInsertListPage
184 {
187  /* array of inserted tuples follows */
189 
190 /*
191  * Backup Blk 0: metapage
192  * Backup Blk 1 to (ndeleted + 1): deleted pages
193  */
194 
195 #define XLOG_GIN_DELETE_LISTPAGE 0x80
196 
197 /*
198  * The WAL record for deleting list pages must contain a block reference to
199  * all the deleted pages, so the number of pages that can be deleted in one
200  * record is limited by XLR_MAX_BLOCK_ID. (block_id 0 is used for the
201  * metapage.)
202  */
203 #define GIN_NDELETE_AT_ONCE Min(16, XLR_MAX_BLOCK_ID - 1)
205 {
209 
210 extern void gin_redo(XLogReaderState *record);
211 extern void gin_desc(StringInfo buf, XLogReaderState *record);
212 extern const char *gin_identify(uint8 info);
213 extern void gin_xlog_startup(void);
214 extern void gin_xlog_cleanup(void);
215 extern void gin_mask(char *pagedata, BlockNumber blkno);
216 
217 #endif /* GINXLOG_H */
BlockNumber prevTail
Definition: ginxlog.h:173
struct ginxlogVacuumDataLeafPage ginxlogVacuumDataLeafPage
RelFileNode node
Definition: ginxlog.h:171
struct ginxlogCreatePostingTree ginxlogCreatePostingTree
void gin_xlog_startup(void)
Definition: ginxlog.c:750
BlockNumber rightlink
Definition: ginxlog.h:185
OffsetNumber offset
Definition: ginxlog.h:101
void gin_mask(char *pagedata, BlockNumber blkno)
Definition: ginxlog.c:768
BlockNumber rightLink
Definition: ginxlog.h:160
unsigned char uint8
Definition: c.h:256
BlockNumber rightChildBlkno
Definition: ginxlog.h:119
struct ginxlogUpdateMeta ginxlogUpdateMeta
uint32 BlockNumber
Definition: block.h:31
OffsetNumber parentOffset
Definition: ginxlog.h:159
uint16 flags
Definition: ginxlog.h:41
ginxlogRecompressDataLeaf data
Definition: ginxlog.h:147
signed int int32
Definition: c.h:246
uint16 OffsetNumber
Definition: off.h:24
GinMetaPageData metadata
Definition: ginxlog.h:206
unsigned short uint16
Definition: c.h:257
void gin_desc(StringInfo buf, XLogReaderState *record)
Definition: gindesc.c:74
struct ginxlogDeleteListPages ginxlogDeleteListPages
struct ginxlogInsertListPage ginxlogInsertListPage
static char * buf
Definition: pg_test_fsync.c:67
RelFileNode node
Definition: ginxlog.h:115
const char * gin_identify(uint8 info)
Definition: gindesc.c:185
unsigned int uint32
Definition: c.h:258
struct ginxlogSplit ginxlogSplit
BlockNumber newRightlink
Definition: ginxlog.h:174
struct ginxlogDeletePage ginxlogDeletePage
void gin_redo(XLogReaderState *record)
Definition: ginxlog.c:698
IndexTupleData tuple
Definition: ginxlog.h:63
BlockNumber leftChildBlkno
Definition: ginxlog.h:118
GinMetaPageData metadata
Definition: ginxlog.h:172
OffsetNumber offset
Definition: ginxlog.h:61
void gin_xlog_cleanup(void)
Definition: ginxlog.c:758
BlockNumber rrlink
Definition: ginxlog.h:116
uint16 flags
Definition: ginxlog.h:120