PostgreSQL Source Code  git master
spgxlog.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * spgxlog.h
4  * xlog declarations for SP-GiST access method.
5  *
6  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/access/spgxlog.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef SPGXLOG_H
14 #define SPGXLOG_H
15 
16 #include "access/xlogreader.h"
17 #include "lib/stringinfo.h"
18 #include "storage/off.h"
19 
20 /* XLOG record types for SPGiST */
21  /* #define XLOG_SPGIST_CREATE_INDEX 0x00 */ /* not used anymore */
22 #define XLOG_SPGIST_ADD_LEAF 0x10
23 #define XLOG_SPGIST_MOVE_LEAFS 0x20
24 #define XLOG_SPGIST_ADD_NODE 0x30
25 #define XLOG_SPGIST_SPLIT_TUPLE 0x40
26 #define XLOG_SPGIST_PICKSPLIT 0x50
27 #define XLOG_SPGIST_VACUUM_LEAF 0x60
28 #define XLOG_SPGIST_VACUUM_ROOT 0x70
29 #define XLOG_SPGIST_VACUUM_REDIRECT 0x80
30 
31 /*
32  * Some redo functions need an SpGistState, although only a few of its fields
33  * need to be valid. spgxlogState carries the required info in xlog records.
34  * (See fillFakeState in spgxlog.c for more comments.)
35  */
36 typedef struct spgxlogState
37 {
39  bool isBuild;
41 
42 /*
43  * Backup Blk 0: destination page for leaf tuple
44  * Backup Blk 1: parent page (if any)
45  */
46 typedef struct spgxlogAddLeaf
47 {
48  bool newPage; /* init dest page? */
49  bool storesNulls; /* page is in the nulls tree? */
50  OffsetNumber offnumLeaf; /* offset where leaf tuple gets placed */
51  OffsetNumber offnumHeadLeaf; /* offset of head tuple in chain, if any */
52 
53  OffsetNumber offnumParent; /* where the parent downlink is, if any */
55 
56  /* new leaf tuple follows (unaligned!) */
58 
59 /*
60  * Backup Blk 0: source leaf page
61  * Backup Blk 1: destination leaf page
62  * Backup Blk 2: parent page
63  */
64 typedef struct spgxlogMoveLeafs
65 {
66  uint16 nMoves; /* number of tuples moved from source page */
67  bool newPage; /* init dest page? */
68  bool replaceDead; /* are we replacing a DEAD source tuple? */
69  bool storesNulls; /* pages are in the nulls tree? */
70 
71  /* where the parent downlink is */
74 
76 
77  /*----------
78  * data follows:
79  * array of deleted tuple numbers, length nMoves
80  * array of inserted tuple numbers, length nMoves + 1 or 1
81  * list of leaf tuples, length nMoves + 1 or 1 (unaligned!)
82  *
83  * Note: if replaceDead is true then there is only one inserted tuple
84  * number and only one leaf tuple in the data, because we are not copying
85  * the dead tuple from the source
86  *----------
87  */
90 
91 #define SizeOfSpgxlogMoveLeafs offsetof(spgxlogMoveLeafs, offsets)
92 
93 /*
94  * Backup Blk 0: original page
95  * Backup Blk 1: where new tuple goes, if not same place
96  * Backup Blk 2: where parent downlink is, if updated and different from
97  * the old and new
98  */
99 typedef struct spgxlogAddNode
100 {
101  /*
102  * Offset of the original inner tuple, in the original page (on backup
103  * block 0).
104  */
106 
107  /*
108  * Offset of the new tuple, on the new page (on backup block 1). Invalid,
109  * if we overwrote the old tuple in the original page).
110  */
112  bool newPage; /* init new page? */
113 
114  /*----
115  * Where is the parent downlink? parentBlk indicates which page it's on,
116  * and offnumParent is the offset within the page. The possible values for
117  * parentBlk are:
118  *
119  * 0: parent == original page
120  * 1: parent == new page
121  * 2: parent == different page (blk ref 2)
122  * -1: parent not updated
123  *----
124  */
126  OffsetNumber offnumParent; /* offset within the parent page */
127 
129 
131 
132  /*
133  * updated inner tuple follows (unaligned!)
134  */
136 
137 /*
138  * Backup Blk 0: where the prefix tuple goes
139  * Backup Blk 1: where the postfix tuple goes (if different page)
140  */
141 typedef struct spgxlogSplitTuple
142 {
143  /* where the prefix tuple goes */
145 
146  /* where the postfix tuple goes */
148  bool newPage; /* need to init that page? */
149  bool postfixBlkSame; /* was postfix tuple put on same page as
150  * prefix? */
151 
152  /*
153  * new prefix inner tuple follows, then new postfix inner tuple (both are
154  * unaligned!)
155  */
157 
158 /*
159  * Buffer references in the rdata array are:
160  * Backup Blk 0: Src page (only if not root)
161  * Backup Blk 1: Dest page (if used)
162  * Backup Blk 2: Inner page
163  * Backup Blk 3: Parent page (if any, and different from Inner)
164  */
165 typedef struct spgxlogPickSplit
166 {
168 
169  uint16 nDelete; /* n to delete from Src */
170  uint16 nInsert; /* n to insert on Src and/or Dest */
171  bool initSrc; /* re-init the Src page? */
172  bool initDest; /* re-init the Dest page? */
173 
174  /* where to put new inner tuple */
176  bool initInner; /* re-init the Inner page? */
177 
178  bool storesNulls; /* pages are in the nulls tree? */
179 
180  /* where the parent downlink is, if any */
181  bool innerIsParent; /* is parent the same as inner page? */
184 
186 
187  /*----------
188  * data follows:
189  * array of deleted tuple numbers, length nDelete
190  * array of inserted tuple numbers, length nInsert
191  * array of page selector bytes for inserted tuples, length nInsert
192  * new inner tuple (unaligned!)
193  * list of leaf tuples, length nInsert (unaligned!)
194  *----------
195  */
198 
199 #define SizeOfSpgxlogPickSplit offsetof(spgxlogPickSplit, offsets)
200 
201 typedef struct spgxlogVacuumLeaf
202 {
203  uint16 nDead; /* number of tuples to become DEAD */
204  uint16 nPlaceholder; /* number of tuples to become PLACEHOLDER */
205  uint16 nMove; /* number of tuples to move */
206  uint16 nChain; /* number of tuples to re-chain */
207 
209 
210  /*----------
211  * data follows:
212  * tuple numbers to become DEAD
213  * tuple numbers to become PLACEHOLDER
214  * tuple numbers to move from (and replace with PLACEHOLDER)
215  * tuple numbers to move to (replacing what is there)
216  * tuple numbers to update nextOffset links of
217  * tuple numbers to insert in nextOffset links
218  *----------
219  */
222 
223 #define SizeOfSpgxlogVacuumLeaf offsetof(spgxlogVacuumLeaf, offsets)
224 
225 typedef struct spgxlogVacuumRoot
226 {
227  /* vacuum a root page when it is also a leaf */
228  uint16 nDelete; /* number of tuples to delete */
229 
231 
232  /* offsets of tuples to delete follow */
235 
236 #define SizeOfSpgxlogVacuumRoot offsetof(spgxlogVacuumRoot, offsets)
237 
238 typedef struct spgxlogVacuumRedirect
239 {
240  uint16 nToPlaceholder; /* number of redirects to make placeholders */
241  OffsetNumber firstPlaceholder; /* first placeholder tuple to remove */
242  TransactionId snapshotConflictHorizon; /* newest XID of removed redirects */
243  bool isCatalogRel; /* to handle recovery conflict during logical
244  * decoding on standby */
245 
246  /* offsets of redirect tuples to make placeholders follow */
249 
250 #define SizeOfSpgxlogVacuumRedirect offsetof(spgxlogVacuumRedirect, offsets)
251 
252 extern void spg_redo(XLogReaderState *record);
253 extern void spg_desc(StringInfo buf, XLogReaderState *record);
254 extern const char *spg_identify(uint8 info);
255 extern void spg_xlog_startup(void);
256 extern void spg_xlog_cleanup(void);
257 extern void spg_mask(char *pagedata, BlockNumber blkno);
258 
259 #endif /* SPGXLOG_H */
uint32 BlockNumber
Definition: block.h:31
unsigned short uint16
Definition: c.h:505
signed char int8
Definition: c.h:492
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:398
unsigned char uint8
Definition: c.h:504
uint32 TransactionId
Definition: c.h:652
uint16 OffsetNumber
Definition: off.h:24
static char * buf
Definition: pg_test_fsync.c:73
struct spgxlogSplitTuple spgxlogSplitTuple
void spg_redo(XLogReaderState *record)
Definition: spgxlog.c:935
struct spgxlogAddLeaf spgxlogAddLeaf
struct spgxlogMoveLeafs spgxlogMoveLeafs
struct spgxlogVacuumRedirect spgxlogVacuumRedirect
struct spgxlogVacuumRoot spgxlogVacuumRoot
struct spgxlogVacuumLeaf spgxlogVacuumLeaf
void spg_xlog_cleanup(void)
Definition: spgxlog.c:984
void spg_mask(char *pagedata, BlockNumber blkno)
Definition: spgxlog.c:994
struct spgxlogAddNode spgxlogAddNode
void spg_xlog_startup(void)
Definition: spgxlog.c:976
struct spgxlogState spgxlogState
struct spgxlogPickSplit spgxlogPickSplit
void spg_desc(StringInfo buf, XLogReaderState *record)
Definition: spgdesc.c:20
const char * spg_identify(uint8 info)
Definition: spgdesc.c:132
uint16 nodeI
Definition: spgxlog.h:54
bool newPage
Definition: spgxlog.h:48
OffsetNumber offnumLeaf
Definition: spgxlog.h:50
bool storesNulls
Definition: spgxlog.h:49
OffsetNumber offnumHeadLeaf
Definition: spgxlog.h:51
OffsetNumber offnumParent
Definition: spgxlog.h:53
OffsetNumber offnumNew
Definition: spgxlog.h:111
bool newPage
Definition: spgxlog.h:112
OffsetNumber offnumParent
Definition: spgxlog.h:126
OffsetNumber offnum
Definition: spgxlog.h:105
spgxlogState stateSrc
Definition: spgxlog.h:130
uint16 nodeI
Definition: spgxlog.h:128
int8 parentBlk
Definition: spgxlog.h:125
bool replaceDead
Definition: spgxlog.h:68
bool storesNulls
Definition: spgxlog.h:69
uint16 nMoves
Definition: spgxlog.h:66
uint16 nodeI
Definition: spgxlog.h:73
OffsetNumber offnumParent
Definition: spgxlog.h:72
spgxlogState stateSrc
Definition: spgxlog.h:75
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]
Definition: spgxlog.h:88
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]
Definition: spgxlog.h:196
uint16 nInsert
Definition: spgxlog.h:170
spgxlogState stateSrc
Definition: spgxlog.h:185
bool innerIsParent
Definition: spgxlog.h:181
uint16 nodeI
Definition: spgxlog.h:183
bool storesNulls
Definition: spgxlog.h:178
OffsetNumber offnumParent
Definition: spgxlog.h:182
OffsetNumber offnumInner
Definition: spgxlog.h:175
uint16 nDelete
Definition: spgxlog.h:169
bool isRootSplit
Definition: spgxlog.h:167
OffsetNumber offnumPostfix
Definition: spgxlog.h:147
OffsetNumber offnumPrefix
Definition: spgxlog.h:144
bool postfixBlkSame
Definition: spgxlog.h:149
TransactionId myXid
Definition: spgxlog.h:38
bool isBuild
Definition: spgxlog.h:39
spgxlogState stateSrc
Definition: spgxlog.h:208
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]
Definition: spgxlog.h:220
uint16 nPlaceholder
Definition: spgxlog.h:204
OffsetNumber firstPlaceholder
Definition: spgxlog.h:241
TransactionId snapshotConflictHorizon
Definition: spgxlog.h:242
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]
Definition: spgxlog.h:247
spgxlogState stateSrc
Definition: spgxlog.h:230
uint16 nDelete
Definition: spgxlog.h:228
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]
Definition: spgxlog.h:233