diff options
| author | Peter Eisentraut <peter@eisentraut.org> | 2025-12-02 09:10:02 +0100 |
|---|---|---|
| committer | Peter Eisentraut <peter@eisentraut.org> | 2025-12-02 09:18:54 +0100 |
| commit | 35988b31db7767ba446009611b9928add1d40f98 (patch) | |
| tree | f5ba4c83eb5ce5b11ebfbb3e87f50180701b7fc5 | |
| parent | ec782f56b0c30ef493e8356b46e1131612f01d9f (diff) | |
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
| -rw-r--r-- | src/backend/access/hash/hash_xlog.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/backend/access/hash/hash_xlog.c b/src/backend/access/hash/hash_xlog.c index 2a0145f3c9b..ad2e36d2ed9 100644 --- a/src/backend/access/hash/hash_xlog.c +++ b/src/backend/access/hash/hash_xlog.c @@ -314,8 +314,6 @@ hash_xlog_split_allocate_page(XLogReaderState *record) Buffer oldbuf; Buffer newbuf; Buffer metabuf; - Size datalen PG_USED_FOR_ASSERTS_ONLY; - char *data; XLogRedoAction action; /* @@ -375,6 +373,10 @@ hash_xlog_split_allocate_page(XLogReaderState *record) { Page page; HashMetaPage metap; + Size datalen; + char *data; + uint32 *uidata; + int uidatacount; page = BufferGetPage(metabuf); metap = HashPageGetMeta(page); @@ -382,34 +384,31 @@ hash_xlog_split_allocate_page(XLogReaderState *record) data = XLogRecGetBlockData(record, 2, &datalen); + /* + * This cast is ok because XLogRecGetBlockData() returns a MAXALIGNed + * buffer. + */ + uidata = (uint32 *) data; + uidatacount = 0; + if (xlrec->flags & XLH_SPLIT_META_UPDATE_MASKS) { - uint32 lowmask; - uint32 *highmask; - - /* extract low and high masks. */ - memcpy(&lowmask, data, sizeof(uint32)); - highmask = (uint32 *) ((char *) data + sizeof(uint32)); + uint32 lowmask = uidata[uidatacount++]; + uint32 highmask = uidata[uidatacount++]; /* update metapage */ metap->hashm_lowmask = lowmask; - metap->hashm_highmask = *highmask; - - data += sizeof(uint32) * 2; + metap->hashm_highmask = highmask; } if (xlrec->flags & XLH_SPLIT_META_UPDATE_SPLITPOINT) { - uint32 ovflpoint; - uint32 *ovflpages; - - /* extract information of overflow pages. */ - memcpy(&ovflpoint, data, sizeof(uint32)); - ovflpages = (uint32 *) ((char *) data + sizeof(uint32)); + uint32 ovflpoint = uidata[uidatacount++]; + uint32 ovflpages = uidata[uidatacount++]; /* update metapage */ - metap->hashm_spares[ovflpoint] = *ovflpages; metap->hashm_ovflpoint = ovflpoint; + metap->hashm_spares[ovflpoint] = ovflpages; } MarkBufferDirty(metabuf); |
