Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 398cf25

Browse files
committed
In GIN recompression code, use mmemove rather than memcpy, for vacuum.
When vacuuming a data leaf page, any compressed posting lists that are not modified, are copied back to the buffer from a later location in the same buffer rather than from a palloc'd copy. IOW, they are just moved downwards in the same buffer. Because the source and destination addresses can overlap, we must use memmove rather than memcpy. Report and fix by Alexander Korotkov.
1 parent fbe19ee commit 398cf25

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/backend/access/gin/gindatapage.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,13 @@ ginVacuumPostingTreeLeaf(Relation indexrel, Buffer buffer, GinVacuumState *gvs)
753753
* *prdata is filled with WAL information about this operation. The caller
754754
* is responsible for inserting to the WAL, along with any other information
755755
* about the operation that triggered this recompression.
756+
*
757+
* NOTE: The segment pointers can point directly to the same buffer, with
758+
* the limitation that any earlier segment must not overlap with an original,
759+
* later segment. In other words, some segments may point the original buffer
760+
* as long as you don't make any segments larger. Currently, leafRepackItems
761+
* satisies this rule because it rewrites all segments after the first
762+
* modified one, and vacuum can only make segments shorter.
756763
*/
757764
static void
758765
dataPlaceToPageLeafRecompress(Buffer buf, disassembledLeaf *leaf,
@@ -798,7 +805,13 @@ dataPlaceToPageLeafRecompress(Buffer buf, disassembledLeaf *leaf,
798805
if (!modified)
799806
unmodifiedsize += segsize;
800807
else
801-
memcpy(ptr, seginfo->seg, segsize);
808+
{
809+
/*
810+
* Use memmove rather than memcpy, in case the segment points
811+
* to the same buffer
812+
*/
813+
memmove(ptr, seginfo->seg, segsize);
814+
}
802815
ptr += segsize;
803816
newsize += segsize;
804817
}

0 commit comments

Comments
 (0)