Simplify/speed up assertion cross-check in ginCompressPostingList().
authorTom Lane
Sat, 7 Mar 2020 18:31:17 +0000 (13:31 -0500)
committerTom Lane
Sat, 7 Mar 2020 18:31:17 +0000 (13:31 -0500)
I noticed while testing some other stuff that the CHECK_ENCODING_ROUNDTRIP
logic in ginCompressPostingList could account for over 50% of the runtime
of an INSERT with a GIN index.  While that's not relevant to production
performance, it's still kind of annoying in a debug build.  Replacing
the loop around short memcmp's with one long memcmp works just as well
and is significantly faster, at least on my machine.

src/backend/access/gin/ginpostinglist.c

index 7dff2071d8faaa4bcb00435339b4316b23bcaa09..461ec93fdef5179a1c3776ee5377624e7513d88e 100644 (file)
@@ -266,11 +266,9 @@ ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
    {
        int         ndecoded;
        ItemPointer tmp = ginPostingListDecode(result, &ndecoded);
-       int         i;
 
        Assert(ndecoded == totalpacked);
-       for (i = 0; i < ndecoded; i++)
-           Assert(memcmp(&tmp[i], &ipd[i], sizeof(ItemPointerData)) == 0);
+       Assert(memcmp(tmp, ipd, ndecoded * sizeof(ItemPointerData)) == 0);
        pfree(tmp);
    }
 #endif