PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
hash_xlog.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * hash_xlog.h
4  * header file for Postgres hash AM implementation
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/access/hash_xlog.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef HASH_XLOG_H
15 #define HASH_XLOG_H
16 
17 #include "access/xlogreader.h"
18 #include "lib/stringinfo.h"
19 #include "storage/off.h"
20 
21 /* Number of buffers required for XLOG_HASH_SQUEEZE_PAGE operation */
22 #define HASH_XLOG_FREE_OVFL_BUFS 6
23 
24 /*
25  * XLOG records for hash operations
26  */
27 #define XLOG_HASH_INIT_META_PAGE 0x00 /* initialize the meta page */
28 #define XLOG_HASH_INIT_BITMAP_PAGE 0x10 /* initialize the bitmap page */
29 #define XLOG_HASH_INSERT 0x20 /* add index tuple without split */
30 #define XLOG_HASH_ADD_OVFL_PAGE 0x30 /* add overflow page */
31 #define XLOG_HASH_SPLIT_ALLOCATE_PAGE 0x40 /* allocate new page for split */
32 #define XLOG_HASH_SPLIT_PAGE 0x50 /* split page */
33 #define XLOG_HASH_SPLIT_COMPLETE 0x60 /* completion of split
34  * operation */
35 #define XLOG_HASH_MOVE_PAGE_CONTENTS 0x70 /* remove tuples from one page
36  * and add to another page */
37 #define XLOG_HASH_SQUEEZE_PAGE 0x80 /* add tuples to one of the previous
38  * pages in chain and free the ovfl
39  * page */
40 #define XLOG_HASH_DELETE 0x90 /* delete index tuples from a page */
41 #define XLOG_HASH_SPLIT_CLEANUP 0xA0 /* clear split-cleanup flag in primary
42  * bucket page after deleting tuples
43  * that are moved due to split */
44 #define XLOG_HASH_UPDATE_META_PAGE 0xB0 /* update meta page after
45  * vacuum */
46 
47 #define XLOG_HASH_VACUUM_ONE_PAGE 0xC0 /* remove dead tuples from index page */
48 
49 /*
50  * xl_hash_split_allocate_page flag values, 8 bits are available.
51  */
52 #define XLH_SPLIT_META_UPDATE_MASKS (1<<0)
53 #define XLH_SPLIT_META_UPDATE_SPLITPOINT (1<<1)
54 
55 /*
56  * This is what we need to know about a HASH index create.
57  *
58  * Backup block 0: metapage
59  */
60 typedef struct xl_hash_createidx
61 {
62  double num_tuples;
66 #define SizeOfHashCreateIdx (offsetof(xl_hash_createidx, ffactor) + sizeof(uint16))
67 
68 /*
69  * This is what we need to know about simple (without split) insert.
70  *
71  * This data record is used for XLOG_HASH_INSERT
72  *
73  * Backup Blk 0: original page (data contains the inserted tuple)
74  * Backup Blk 1: metapage (HashMetaPageData)
75  */
76 typedef struct xl_hash_insert
77 {
80 
81 #define SizeOfHashInsert (offsetof(xl_hash_insert, offnum) + sizeof(OffsetNumber))
82 
83 /*
84  * This is what we need to know about addition of overflow page.
85  *
86  * This data record is used for XLOG_HASH_ADD_OVFL_PAGE
87  *
88  * Backup Blk 0: newly allocated overflow page
89  * Backup Blk 1: page before new overflow page in the bucket chain
90  * Backup Blk 2: bitmap page
91  * Backup Blk 3: new bitmap page
92  * Backup Blk 4: metapage
93  */
94 typedef struct xl_hash_add_ovfl_page
95 {
99 
100 #define SizeOfHashAddOvflPage \
101  (offsetof(xl_hash_add_ovfl_page, bmpage_found) + sizeof(bool))
102 
103 /*
104  * This is what we need to know about allocating a page for split.
105  *
106  * This data record is used for XLOG_HASH_SPLIT_ALLOCATE_PAGE
107  *
108  * Backup Blk 0: page for old bucket
109  * Backup Blk 1: page for new bucket
110  * Backup Blk 2: metapage
111  */
113 {
119 
120 #define SizeOfHashSplitAllocPage \
121  (offsetof(xl_hash_split_allocate_page, flags) + sizeof(uint8))
122 
123 /*
124  * This is what we need to know about completing the split operation.
125  *
126  * This data record is used for XLOG_HASH_SPLIT_COMPLETE
127  *
128  * Backup Blk 0: page for old bucket
129  * Backup Blk 1: page for new bucket
130  */
132 {
136 
137 #define SizeOfHashSplitComplete \
138  (offsetof(xl_hash_split_complete, new_bucket_flag) + sizeof(uint16))
139 
140 /*
141  * This is what we need to know about move page contents required during
142  * squeeze operation.
143  *
144  * This data record is used for XLOG_HASH_MOVE_PAGE_CONTENTS
145  *
146  * Backup Blk 0: bucket page
147  * Backup Blk 1: page containing moved tuples
148  * Backup Blk 2: page from which tuples will be removed
149  */
151 {
153  bool is_prim_bucket_same_wrt; /* TRUE if the page to which
154  * tuples are moved is same as
155  * primary bucket page */
157 
158 #define SizeOfHashMovePageContents \
159  (offsetof(xl_hash_move_page_contents, is_prim_bucket_same_wrt) + sizeof(bool))
160 
161 /*
162  * This is what we need to know about the squeeze page operation.
163  *
164  * This data record is used for XLOG_HASH_SQUEEZE_PAGE
165  *
166  * Backup Blk 0: page containing tuples moved from freed overflow page
167  * Backup Blk 1: freed overflow page
168  * Backup Blk 2: page previous to the freed overflow page
169  * Backup Blk 3: page next to the freed overflow page
170  * Backup Blk 4: bitmap page containing info of freed overflow page
171  * Backup Blk 5: meta page
172  */
173 typedef struct xl_hash_squeeze_page
174 {
178  bool is_prim_bucket_same_wrt; /* TRUE if the page to which
179  * tuples are moved is same as
180  * primary bucket page */
181  bool is_prev_bucket_same_wrt; /* TRUE if the page to which
182  * tuples are moved is the
183  * page previous to the freed
184  * overflow page */
186 
187 #define SizeOfHashSqueezePage \
188  (offsetof(xl_hash_squeeze_page, is_prev_bucket_same_wrt) + sizeof(bool))
189 
190 /*
191  * This is what we need to know about the deletion of index tuples from a page.
192  *
193  * This data record is used for XLOG_HASH_DELETE
194  *
195  * Backup Blk 0: primary bucket page
196  * Backup Blk 1: page from which tuples are deleted
197  */
198 typedef struct xl_hash_delete
199 {
200  bool clear_dead_marking; /* TRUE if this operation clears
201  * LH_PAGE_HAS_DEAD_TUPLES flag */
202  bool is_primary_bucket_page; /* TRUE if the operation is for
203  * primary bucket page */
205 
206 #define SizeOfHashDelete (offsetof(xl_hash_delete, is_primary_bucket_page) + sizeof(bool))
207 
208 /*
209  * This is what we need for metapage update operation.
210  *
211  * This data record is used for XLOG_HASH_UPDATE_META_PAGE
212  *
213  * Backup Blk 0: meta page
214  */
216 {
217  double ntuples;
219 
220 #define SizeOfHashUpdateMetaPage \
221  (offsetof(xl_hash_update_meta_page, ntuples) + sizeof(double))
222 
223 /*
224  * This is what we need to initialize metapage.
225  *
226  * This data record is used for XLOG_HASH_INIT_META_PAGE
227  *
228  * Backup Blk 0: meta page
229  */
231 {
232  double num_tuples;
236 
237 #define SizeOfHashInitMetaPage \
238  (offsetof(xl_hash_init_meta_page, ffactor) + sizeof(uint16))
239 
240 /*
241  * This is what we need to initialize bitmap page.
242  *
243  * This data record is used for XLOG_HASH_INIT_BITMAP_PAGE
244  *
245  * Backup Blk 0: bitmap page
246  * Backup Blk 1: meta page
247  */
249 {
252 
253 #define SizeOfHashInitBitmapPage \
254  (offsetof(xl_hash_init_bitmap_page, bmsize) + sizeof(uint16))
255 
256 /*
257  * This is what we need for index tuple deletion and to
258  * update the meta page.
259  *
260  * This data record is used for XLOG_HASH_VACUUM_ONE_PAGE
261  *
262  * Backup Blk 0: bucket page
263  * Backup Blk 1: meta page
264  */
266 {
268  int ntuples;
269 
270  /* TARGET OFFSET NUMBERS FOLLOW AT THE END */
272 
273 #define SizeOfHashVacuumOnePage \
274  (offsetof(xl_hash_vacuum_one_page, ntuples) + sizeof(int))
275 
276 extern void hash_redo(XLogReaderState *record);
277 extern void hash_desc(StringInfo buf, XLogReaderState *record);
278 extern const char *hash_identify(uint8 info);
279 extern void hash_mask(char *pagedata, BlockNumber blkno);
280 
281 #endif /* HASH_XLOG_H */
struct xl_hash_delete xl_hash_delete
regproc RegProcedure
Definition: c.h:395
unsigned char uint8
Definition: c.h:266
struct xl_hash_move_page_contents xl_hash_move_page_contents
struct xl_hash_insert xl_hash_insert
bool clear_dead_marking
Definition: hash_xlog.h:200
uint32 BlockNumber
Definition: block.h:31
BlockNumber prevblkno
Definition: hash_xlog.h:175
bool is_prim_bucket_same_wrt
Definition: hash_xlog.h:178
uint16 OffsetNumber
Definition: off.h:24
struct xl_hash_update_meta_page xl_hash_update_meta_page
unsigned short uint16
Definition: c.h:267
BlockNumber nextblkno
Definition: hash_xlog.h:176
struct xl_hash_squeeze_page xl_hash_squeeze_page
double num_tuples
Definition: hash_xlog.h:62
bool is_primary_bucket_page
Definition: hash_xlog.h:202
void hash_mask(char *pagedata, BlockNumber blkno)
Definition: hash_xlog.c:1224
static char * buf
Definition: pg_test_fsync.c:65
unsigned int uint32
Definition: c.h:268
struct xl_hash_createidx xl_hash_createidx
void hash_desc(StringInfo buf, XLogReaderState *record)
Definition: hashdesc.c:20
void hash_redo(XLogReaderState *record)
Definition: hash_xlog.c:1170
struct xl_hash_init_meta_page xl_hash_init_meta_page
struct xl_hash_split_allocate_page xl_hash_split_allocate_page
bool is_prev_bucket_same_wrt
Definition: hash_xlog.h:181
OffsetNumber offnum
Definition: hash_xlog.h:78
struct xl_hash_vacuum_one_page xl_hash_vacuum_one_page
RegProcedure procid
Definition: hash_xlog.h:233
RegProcedure procid
Definition: hash_xlog.h:63
struct xl_hash_add_ovfl_page xl_hash_add_ovfl_page
struct xl_hash_split_complete xl_hash_split_complete
struct xl_hash_init_bitmap_page xl_hash_init_bitmap_page
const char * hash_identify(uint8 info)
Definition: hashdesc.c:124