PostgreSQL Source Code
git master
Loading...
Searching...
No Matches
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-2026, 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 operation */
34
#define XLOG_HASH_MOVE_PAGE_CONTENTS 0x70
/* remove tuples from one page
35
* and add to another page */
36
#define XLOG_HASH_SQUEEZE_PAGE 0x80
/* add tuples to one of the previous
37
* pages in chain and free the ovfl
38
* page */
39
#define XLOG_HASH_DELETE 0x90
/* delete index tuples from a page */
40
#define XLOG_HASH_SPLIT_CLEANUP 0xA0
/* clear split-cleanup flag in primary
41
* bucket page after deleting tuples
42
* that are moved due to split */
43
#define XLOG_HASH_UPDATE_META_PAGE 0xB0
/* update meta page after vacuum */
44
45
#define XLOG_HASH_VACUUM_ONE_PAGE 0xC0
/* remove dead tuples from index
46
* page */
47
48
/*
49
* xl_hash_split_allocate_page flag values, 8 bits are available.
50
*/
51
#define XLH_SPLIT_META_UPDATE_MASKS (1<<0)
52
#define XLH_SPLIT_META_UPDATE_SPLITPOINT (1<<1)
53
54
/*
55
* This is what we need to know about simple (without split) insert.
56
*
57
* This data record is used for XLOG_HASH_INSERT
58
*
59
* Backup Blk 0: original page (data contains the inserted tuple)
60
* Backup Blk 1: metapage (HashMetaPageData)
61
*/
62
typedef
struct
xl_hash_insert
63
{
64
OffsetNumber
offnum
;
65
}
xl_hash_insert
;
66
67
#define SizeOfHashInsert (offsetof(xl_hash_insert, offnum) + sizeof(OffsetNumber))
68
69
/*
70
* This is what we need to know about addition of overflow page.
71
*
72
* This data record is used for XLOG_HASH_ADD_OVFL_PAGE
73
*
74
* Backup Blk 0: newly allocated overflow page
75
* Backup Blk 1: page before new overflow page in the bucket chain
76
* Backup Blk 2: bitmap page
77
* Backup Blk 3: new bitmap page
78
* Backup Blk 4: metapage
79
*/
80
typedef
struct
xl_hash_add_ovfl_page
81
{
82
uint16
bmsize
;
83
bool
bmpage_found
;
84
}
xl_hash_add_ovfl_page
;
85
86
#define SizeOfHashAddOvflPage \
87
(offsetof(xl_hash_add_ovfl_page, bmpage_found) + sizeof(bool))
88
89
/*
90
* This is what we need to know about allocating a page for split.
91
*
92
* This data record is used for XLOG_HASH_SPLIT_ALLOCATE_PAGE
93
*
94
* Backup Blk 0: page for old bucket
95
* Backup Blk 1: page for new bucket
96
* Backup Blk 2: metapage
97
*/
98
typedef
struct
xl_hash_split_allocate_page
99
{
100
uint32
new_bucket
;
101
uint16
old_bucket_flag
;
102
uint16
new_bucket_flag
;
103
uint8
flags
;
104
}
xl_hash_split_allocate_page
;
105
106
#define SizeOfHashSplitAllocPage \
107
(offsetof(xl_hash_split_allocate_page, flags) + sizeof(uint8))
108
109
/*
110
* This is what we need to know about completing the split operation.
111
*
112
* This data record is used for XLOG_HASH_SPLIT_COMPLETE
113
*
114
* Backup Blk 0: page for old bucket
115
* Backup Blk 1: page for new bucket
116
*/
117
typedef
struct
xl_hash_split_complete
118
{
119
uint16
old_bucket_flag
;
120
uint16
new_bucket_flag
;
121
}
xl_hash_split_complete
;
122
123
#define SizeOfHashSplitComplete \
124
(offsetof(xl_hash_split_complete, new_bucket_flag) + sizeof(uint16))
125
126
/*
127
* This is what we need to know about move page contents required during
128
* squeeze operation.
129
*
130
* This data record is used for XLOG_HASH_MOVE_PAGE_CONTENTS
131
*
132
* Backup Blk 0: primary bucket page
133
* Backup Blk 1: page containing moved tuples
134
* Backup Blk 2: page from which tuples will be removed
135
*/
136
typedef
struct
xl_hash_move_page_contents
137
{
138
uint16
ntups
;
139
bool
is_prim_bucket_same_wrt
;
/* true if the page to which
140
* tuples are moved is same as
141
* primary bucket page */
142
}
xl_hash_move_page_contents
;
143
144
#define SizeOfHashMovePageContents \
145
(offsetof(xl_hash_move_page_contents, is_prim_bucket_same_wrt) + sizeof(bool))
146
147
/*
148
* This is what we need to know about the squeeze page operation.
149
*
150
* This data record is used for XLOG_HASH_SQUEEZE_PAGE
151
*
152
* Backup Blk 0: primary bucket page
153
* Backup Blk 1: page containing tuples moved from freed overflow page
154
* Backup Blk 2: freed overflow page
155
* Backup Blk 3: page previous to the freed overflow page
156
* Backup Blk 4: page next to the freed overflow page
157
* Backup Blk 5: bitmap page containing info of freed overflow page
158
* Backup Blk 6: meta page
159
*/
160
typedef
struct
xl_hash_squeeze_page
161
{
162
BlockNumber
prevblkno
;
163
BlockNumber
nextblkno
;
164
uint16
ntups
;
165
bool
is_prim_bucket_same_wrt
;
/* true if the page to which
166
* tuples are moved is same as
167
* primary bucket page */
168
bool
is_prev_bucket_same_wrt
;
/* true if the page to which
169
* tuples are moved is the page
170
* previous to the freed overflow
171
* page */
172
}
xl_hash_squeeze_page
;
173
174
#define SizeOfHashSqueezePage \
175
(offsetof(xl_hash_squeeze_page, is_prev_bucket_same_wrt) + sizeof(bool))
176
177
/*
178
* This is what we need to know about the deletion of index tuples from a page.
179
*
180
* This data record is used for XLOG_HASH_DELETE
181
*
182
* Backup Blk 0: primary bucket page
183
* Backup Blk 1: page from which tuples are deleted
184
*/
185
typedef
struct
xl_hash_delete
186
{
187
bool
clear_dead_marking
;
/* true if this operation clears
188
* LH_PAGE_HAS_DEAD_TUPLES flag */
189
bool
is_primary_bucket_page
;
/* true if the operation is for
190
* primary bucket page */
191
}
xl_hash_delete
;
192
193
#define SizeOfHashDelete (offsetof(xl_hash_delete, is_primary_bucket_page) + sizeof(bool))
194
195
/*
196
* This is what we need for metapage update operation.
197
*
198
* This data record is used for XLOG_HASH_UPDATE_META_PAGE
199
*
200
* Backup Blk 0: meta page
201
*/
202
typedef
struct
xl_hash_update_meta_page
203
{
204
double
ntuples
;
205
}
xl_hash_update_meta_page
;
206
207
#define SizeOfHashUpdateMetaPage \
208
(offsetof(xl_hash_update_meta_page, ntuples) + sizeof(double))
209
210
/*
211
* This is what we need to initialize metapage.
212
*
213
* This data record is used for XLOG_HASH_INIT_META_PAGE
214
*
215
* Backup Blk 0: meta page
216
*/
217
typedef
struct
xl_hash_init_meta_page
218
{
219
double
num_tuples
;
220
RegProcedure
procid
;
221
uint16
ffactor
;
222
}
xl_hash_init_meta_page
;
223
224
#define SizeOfHashInitMetaPage \
225
(offsetof(xl_hash_init_meta_page, ffactor) + sizeof(uint16))
226
227
/*
228
* This is what we need to initialize bitmap page.
229
*
230
* This data record is used for XLOG_HASH_INIT_BITMAP_PAGE
231
*
232
* Backup Blk 0: bitmap page
233
* Backup Blk 1: meta page
234
*/
235
typedef
struct
xl_hash_init_bitmap_page
236
{
237
uint16
bmsize
;
238
}
xl_hash_init_bitmap_page
;
239
240
#define SizeOfHashInitBitmapPage \
241
(offsetof(xl_hash_init_bitmap_page, bmsize) + sizeof(uint16))
242
243
/*
244
* This is what we need for index tuple deletion and to
245
* update the meta page.
246
*
247
* This data record is used for XLOG_HASH_VACUUM_ONE_PAGE
248
*
249
* Backup Blk 0: primary bucket page
250
* Backup Blk 1: meta page
251
*/
252
typedef
struct
xl_hash_vacuum_one_page
253
{
254
TransactionId
snapshotConflictHorizon
;
255
uint16
ntuples
;
256
bool
isCatalogRel
;
/* to handle recovery conflict during logical
257
* decoding on standby */
258
259
/* TARGET OFFSET NUMBERS */
260
OffsetNumber
offsets
[
FLEXIBLE_ARRAY_MEMBER
];
261
}
xl_hash_vacuum_one_page
;
262
263
#define SizeOfHashVacuumOnePage offsetof(xl_hash_vacuum_one_page, offsets)
264
265
extern
void
hash_redo
(
XLogReaderState
*record);
266
extern
void
hash_desc
(
StringInfo
buf
,
XLogReaderState
*record);
267
extern
const
char
*
hash_identify
(
uint8
info);
268
extern
void
hash_mask
(
char
*
pagedata
,
BlockNumber
blkno);
269
270
#endif
/* HASH_XLOG_H */
BlockNumber
uint32 BlockNumber
Definition
block.h:31
uint8
uint8_t uint8
Definition
c.h:544
FLEXIBLE_ARRAY_MEMBER
#define FLEXIBLE_ARRAY_MEMBER
Definition
c.h:480
RegProcedure
regproc RegProcedure
Definition
c.h:664
uint16
uint16_t uint16
Definition
c.h:545
uint32
uint32_t uint32
Definition
c.h:546
TransactionId
uint32 TransactionId
Definition
c.h:666
hash_mask
void hash_mask(char *pagedata, BlockNumber blkno)
Definition
hash_xlog.c:1117
hash_identify
const char * hash_identify(uint8 info)
Definition
hashdesc.c:131
hash_desc
void hash_desc(StringInfo buf, XLogReaderState *record)
Definition
hashdesc.c:20
hash_redo
void hash_redo(XLogReaderState *record)
Definition
hash_xlog.c:1063
off.h
OffsetNumber
uint16 OffsetNumber
Definition
off.h:24
buf
static char buf[DEFAULT_XLOG_SEG_SIZE]
Definition
pg_test_fsync.c:71
fb
static int fb(int x)
Definition
preproc-init.c:92
stringinfo.h
StringInfoData
Definition
stringinfo.h:47
XLogReaderState
Definition
xlogreader.h:175
xl_hash_add_ovfl_page
Definition
hash_xlog.h:75
xl_hash_add_ovfl_page::bmpage_found
bool bmpage_found
Definition
hash_xlog.h:77
xl_hash_add_ovfl_page::bmsize
uint16 bmsize
Definition
hash_xlog.h:76
xl_hash_delete
Definition
hash_xlog.h:180
xl_hash_delete::clear_dead_marking
bool clear_dead_marking
Definition
hash_xlog.h:181
xl_hash_delete::is_primary_bucket_page
bool is_primary_bucket_page
Definition
hash_xlog.h:183
xl_hash_init_bitmap_page
Definition
hash_xlog.h:230
xl_hash_init_bitmap_page::bmsize
uint16 bmsize
Definition
hash_xlog.h:231
xl_hash_init_meta_page
Definition
hash_xlog.h:212
xl_hash_init_meta_page::procid
RegProcedure procid
Definition
hash_xlog.h:214
xl_hash_init_meta_page::num_tuples
double num_tuples
Definition
hash_xlog.h:213
xl_hash_init_meta_page::ffactor
uint16 ffactor
Definition
hash_xlog.h:215
xl_hash_insert
Definition
hash_xlog.h:57
xl_hash_insert::offnum
OffsetNumber offnum
Definition
hash_xlog.h:58
xl_hash_move_page_contents
Definition
hash_xlog.h:131
xl_hash_move_page_contents::ntups
uint16 ntups
Definition
hash_xlog.h:132
xl_hash_move_page_contents::is_prim_bucket_same_wrt
bool is_prim_bucket_same_wrt
Definition
hash_xlog.h:133
xl_hash_split_allocate_page
Definition
hash_xlog.h:93
xl_hash_split_allocate_page::new_bucket_flag
uint16 new_bucket_flag
Definition
hash_xlog.h:96
xl_hash_split_allocate_page::flags
uint8 flags
Definition
hash_xlog.h:97
xl_hash_split_allocate_page::old_bucket_flag
uint16 old_bucket_flag
Definition
hash_xlog.h:95
xl_hash_split_allocate_page::new_bucket
uint32 new_bucket
Definition
hash_xlog.h:94
xl_hash_split_complete
Definition
hash_xlog.h:112
xl_hash_split_complete::new_bucket_flag
uint16 new_bucket_flag
Definition
hash_xlog.h:114
xl_hash_split_complete::old_bucket_flag
uint16 old_bucket_flag
Definition
hash_xlog.h:113
xl_hash_squeeze_page
Definition
hash_xlog.h:155
xl_hash_squeeze_page::prevblkno
BlockNumber prevblkno
Definition
hash_xlog.h:156
xl_hash_squeeze_page::is_prim_bucket_same_wrt
bool is_prim_bucket_same_wrt
Definition
hash_xlog.h:159
xl_hash_squeeze_page::ntups
uint16 ntups
Definition
hash_xlog.h:158
xl_hash_squeeze_page::is_prev_bucket_same_wrt
bool is_prev_bucket_same_wrt
Definition
hash_xlog.h:162
xl_hash_squeeze_page::nextblkno
BlockNumber nextblkno
Definition
hash_xlog.h:157
xl_hash_update_meta_page
Definition
hash_xlog.h:197
xl_hash_update_meta_page::ntuples
double ntuples
Definition
hash_xlog.h:198
xl_hash_vacuum_one_page
Definition
hash_xlog.h:247
xl_hash_vacuum_one_page::isCatalogRel
bool isCatalogRel
Definition
hash_xlog.h:250
xl_hash_vacuum_one_page::ntuples
uint16 ntuples
Definition
hash_xlog.h:249
xl_hash_vacuum_one_page::snapshotConflictHorizon
TransactionId snapshotConflictHorizon
Definition
hash_xlog.h:248
xl_hash_vacuum_one_page::offsets
OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]
Definition
hash_xlog.h:254
xlogreader.h
src
include
access
hash_xlog.h
Generated on Sat Jan 31 2026 12:13:16 for PostgreSQL Source Code by
1.9.8