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
48  * index page */
49 
50 /*
51  * xl_hash_split_allocate_page flag values, 8 bits are available.
52  */
53 #define XLH_SPLIT_META_UPDATE_MASKS (1<<0)
54 #define XLH_SPLIT_META_UPDATE_SPLITPOINT (1<<1)
55 
56 /*
57  * This is what we need to know about a HASH index create.
58  *
59  * Backup block 0: metapage
60  */
61 typedef struct xl_hash_createidx
62 {
63  double num_tuples;
67 #define SizeOfHashCreateIdx (offsetof(xl_hash_createidx, ffactor) + sizeof(uint16))
68 
69 /*
70  * This is what we need to know about simple (without split) insert.
71  *
72  * This data record is used for XLOG_HASH_INSERT
73  *
74  * Backup Blk 0: original page (data contains the inserted tuple)
75  * Backup Blk 1: metapage (HashMetaPageData)
76  */
77 typedef struct xl_hash_insert
78 {
81 
82 #define SizeOfHashInsert (offsetof(xl_hash_insert, offnum) + sizeof(OffsetNumber))
83 
84 /*
85  * This is what we need to know about addition of overflow page.
86  *
87  * This data record is used for XLOG_HASH_ADD_OVFL_PAGE
88  *
89  * Backup Blk 0: newly allocated overflow page
90  * Backup Blk 1: page before new overflow page in the bucket chain
91  * Backup Blk 2: bitmap page
92  * Backup Blk 3: new bitmap page
93  * Backup Blk 4: metapage
94  */
95 typedef struct xl_hash_add_ovfl_page
96 {
100 
101 #define SizeOfHashAddOvflPage \
102  (offsetof(xl_hash_add_ovfl_page, bmpage_found) + sizeof(bool))
103 
104 /*
105  * This is what we need to know about allocating a page for split.
106  *
107  * This data record is used for XLOG_HASH_SPLIT_ALLOCATE_PAGE
108  *
109  * Backup Blk 0: page for old bucket
110  * Backup Blk 1: page for new bucket
111  * Backup Blk 2: metapage
112  */
114 {
120 
121 #define SizeOfHashSplitAllocPage \
122  (offsetof(xl_hash_split_allocate_page, flags) + sizeof(uint8))
123 
124 /*
125  * This is what we need to know about completing the split operation.
126  *
127  * This data record is used for XLOG_HASH_SPLIT_COMPLETE
128  *
129  * Backup Blk 0: page for old bucket
130  * Backup Blk 1: page for new bucket
131  */
133 {
137 
138 #define SizeOfHashSplitComplete \
139  (offsetof(xl_hash_split_complete, new_bucket_flag) + sizeof(uint16))
140 
141 /*
142  * This is what we need to know about move page contents required during
143  * squeeze operation.
144  *
145  * This data record is used for XLOG_HASH_MOVE_PAGE_CONTENTS
146  *
147  * Backup Blk 0: bucket page
148  * Backup Blk 1: page containing moved tuples
149  * Backup Blk 2: page from which tuples will be removed
150  */
152 {
154  bool is_prim_bucket_same_wrt; /* TRUE if the page to which
155  * tuples are moved is same as
156  * primary bucket page */
158 
159 #define SizeOfHashMovePageContents \
160  (offsetof(xl_hash_move_page_contents, is_prim_bucket_same_wrt) + sizeof(bool))
161 
162 /*
163  * This is what we need to know about the squeeze page operation.
164  *
165  * This data record is used for XLOG_HASH_SQUEEZE_PAGE
166  *
167  * Backup Blk 0: page containing tuples moved from freed overflow page
168  * Backup Blk 1: freed overflow page
169  * Backup Blk 2: page previous to the freed overflow page
170  * Backup Blk 3: page next to the freed overflow page
171  * Backup Blk 4: bitmap page containing info of freed overflow page
172  * Backup Blk 5: meta page
173  */
174 typedef struct xl_hash_squeeze_page
175 {
179  bool is_prim_bucket_same_wrt; /* TRUE if the page to which
180  * tuples are moved is same as
181  * primary bucket page */
182  bool is_prev_bucket_same_wrt; /* TRUE if the page to which
183  * tuples are moved is the
184  * page previous to the freed
185  * overflow page */
187 
188 #define SizeOfHashSqueezePage \
189  (offsetof(xl_hash_squeeze_page, is_prev_bucket_same_wrt) + sizeof(bool))
190 
191 /*
192  * This is what we need to know about the deletion of index tuples from a page.
193  *
194  * This data record is used for XLOG_HASH_DELETE
195  *
196  * Backup Blk 0: primary bucket page
197  * Backup Blk 1: page from which tuples are deleted
198  */
199 typedef struct xl_hash_delete
200 {
201  bool clear_dead_marking; /* TRUE if this operation clears
202  * LH_PAGE_HAS_DEAD_TUPLES flag */
203  bool is_primary_bucket_page; /* TRUE if the operation is for
204  * primary bucket page */
206 
207 #define SizeOfHashDelete (offsetof(xl_hash_delete, is_primary_bucket_page) + sizeof(bool))
208 
209 /*
210  * This is what we need for metapage update operation.
211  *
212  * This data record is used for XLOG_HASH_UPDATE_META_PAGE
213  *
214  * Backup Blk 0: meta page
215  */
217 {
218  double ntuples;
220 
221 #define SizeOfHashUpdateMetaPage \
222  (offsetof(xl_hash_update_meta_page, ntuples) + sizeof(double))
223 
224 /*
225  * This is what we need to initialize metapage.
226  *
227  * This data record is used for XLOG_HASH_INIT_META_PAGE
228  *
229  * Backup Blk 0: meta page
230  */
232 {
233  double num_tuples;
237 
238 #define SizeOfHashInitMetaPage \
239  (offsetof(xl_hash_init_meta_page, ffactor) + sizeof(uint16))
240 
241 /*
242  * This is what we need to initialize bitmap page.
243  *
244  * This data record is used for XLOG_HASH_INIT_BITMAP_PAGE
245  *
246  * Backup Blk 0: bitmap page
247  * Backup Blk 1: meta page
248  */
250 {
253 
254 #define SizeOfHashInitBitmapPage \
255  (offsetof(xl_hash_init_bitmap_page, bmsize) + sizeof(uint16))
256 
257 /*
258  * This is what we need for index tuple deletion and to
259  * update the meta page.
260  *
261  * This data record is used for XLOG_HASH_VACUUM_ONE_PAGE
262  *
263  * Backup Blk 0: bucket page
264  * Backup Blk 1: meta page
265  */
267 {
269  int ntuples;
270 
271  /* TARGET OFFSET NUMBERS FOLLOW AT THE END */
273 
274 #define SizeOfHashVacuumOnePage \
275  (offsetof(xl_hash_vacuum_one_page, ntuples) + sizeof(int))
276 
277 extern void hash_redo(XLogReaderState *record);
278 extern void hash_desc(StringInfo buf, XLogReaderState *record);
279 extern const char *hash_identify(uint8 info);
280 extern void hash_mask(char *pagedata, BlockNumber blkno);
281 
282 #endif /* HASH_XLOG_H */
struct xl_hash_init_meta_page xl_hash_init_meta_page
struct xl_hash_delete xl_hash_delete
struct xl_hash_add_ovfl_page xl_hash_add_ovfl_page
regproc RegProcedure
Definition: c.h:395
unsigned char uint8
Definition: c.h:266
bool clear_dead_marking
Definition: hash_xlog.h:201
uint32 BlockNumber
Definition: block.h:31
struct xl_hash_move_page_contents xl_hash_move_page_contents
BlockNumber prevblkno
Definition: hash_xlog.h:176
bool is_prim_bucket_same_wrt
Definition: hash_xlog.h:179
uint16 OffsetNumber
Definition: off.h:24
unsigned short uint16
Definition: c.h:267
BlockNumber nextblkno
Definition: hash_xlog.h:177
double num_tuples
Definition: hash_xlog.h:63
bool is_primary_bucket_page
Definition: hash_xlog.h:203
void hash_mask(char *pagedata, BlockNumber blkno)
Definition: hash_xlog.c:1233
static char * buf
Definition: pg_test_fsync.c:66
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:1179
struct xl_hash_insert xl_hash_insert
struct xl_hash_init_bitmap_page xl_hash_init_bitmap_page
struct xl_hash_vacuum_one_page xl_hash_vacuum_one_page
struct xl_hash_split_complete xl_hash_split_complete
struct xl_hash_split_allocate_page xl_hash_split_allocate_page
bool is_prev_bucket_same_wrt
Definition: hash_xlog.h:182
OffsetNumber offnum
Definition: hash_xlog.h:79
struct xl_hash_update_meta_page xl_hash_update_meta_page
RegProcedure procid
Definition: hash_xlog.h:234
RegProcedure procid
Definition: hash_xlog.h:64
struct xl_hash_squeeze_page xl_hash_squeeze_page
const char * hash_identify(uint8 info)
Definition: hashdesc.c:124