Skip to content

Commit 35988b3

Browse files
committed
Simplify hash_xlog_split_allocate_page()
Instead of complicated pointer arithmetic, overlay a uint32 array and just access the array members. That's safe thanks to XLogRecGetBlockData() returning a MAXALIGNed buffer. Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/aSQy2JawavlVlEB0%40ip-10-97-1-34.eu-west-3.compute.internal
1 parent ec782f5 commit 35988b3

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/backend/access/hash/hash_xlog.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,6 @@ hash_xlog_split_allocate_page(XLogReaderState *record)
314314
Buffer oldbuf;
315315
Buffer newbuf;
316316
Buffer metabuf;
317-
Size datalen PG_USED_FOR_ASSERTS_ONLY;
318-
char *data;
319317
XLogRedoAction action;
320318

321319
/*
@@ -375,41 +373,42 @@ hash_xlog_split_allocate_page(XLogReaderState *record)
375373
{
376374
Page page;
377375
HashMetaPage metap;
376+
Size datalen;
377+
char *data;
378+
uint32 *uidata;
379+
int uidatacount;
378380

379381
page = BufferGetPage(metabuf);
380382
metap = HashPageGetMeta(page);
381383
metap->hashm_maxbucket = xlrec->new_bucket;
382384

383385
data = XLogRecGetBlockData(record, 2, &datalen);
384386

387+
/*
388+
* This cast is ok because XLogRecGetBlockData() returns a MAXALIGNed
389+
* buffer.
390+
*/
391+
uidata = (uint32 *) data;
392+
uidatacount = 0;
393+
385394
if (xlrec->flags & XLH_SPLIT_META_UPDATE_MASKS)
386395
{
387-
uint32 lowmask;
388-
uint32 *highmask;
389-
390-
/* extract low and high masks. */
391-
memcpy(&lowmask, data, sizeof(uint32));
392-
highmask = (uint32 *) ((char *) data + sizeof(uint32));
396+
uint32 lowmask = uidata[uidatacount++];
397+
uint32 highmask = uidata[uidatacount++];
393398

394399
/* update metapage */
395400
metap->hashm_lowmask = lowmask;
396-
metap->hashm_highmask = *highmask;
397-
398-
data += sizeof(uint32) * 2;
401+
metap->hashm_highmask = highmask;
399402
}
400403

401404
if (xlrec->flags & XLH_SPLIT_META_UPDATE_SPLITPOINT)
402405
{
403-
uint32 ovflpoint;
404-
uint32 *ovflpages;
405-
406-
/* extract information of overflow pages. */
407-
memcpy(&ovflpoint, data, sizeof(uint32));
408-
ovflpages = (uint32 *) ((char *) data + sizeof(uint32));
406+
uint32 ovflpoint = uidata[uidatacount++];
407+
uint32 ovflpages = uidata[uidatacount++];
409408

410409
/* update metapage */
411-
metap->hashm_spares[ovflpoint] = *ovflpages;
412410
metap->hashm_ovflpoint = ovflpoint;
411+
metap->hashm_spares[ovflpoint] = ovflpages;
413412
}
414413

415414
MarkBufferDirty(metabuf);

0 commit comments

Comments
 (0)