Fix GiST index deletion assert issue.
authorPeter Geoghegan <pg@bowt.ie>
Wed, 27 Jan 2021 07:24:37 +0000 (23:24 -0800)
committerPeter Geoghegan <pg@bowt.ie>
Wed, 27 Jan 2021 07:24:37 +0000 (23:24 -0800)
Avoid calling heap_index_delete_tuples() with an empty deltids array to
avoid an assertion failure.

This issue was arguably an oversight in commit b5f58cf2, though the
failing assert itself was added by my recent commit d168b666.  No
backpatch, though, since the oversight is harmless in the back branches.

Author: Peter Geoghegan <pg@bowt.ie>
Reported-By: Jaime Casanova <jcasanov@systemguards.com.ec>
Discussion: https://postgr.es/m/CAJKUy5jscES84n3puE=sYngyF+zpb4wv8UMtuLnLPv5z=6yyNw@mail.gmail.com

src/backend/access/gist/gist.c
src/backend/access/index/genam.c

index f203bb594cdb9ba72c2de83f3fa68de0a3db79c4..0683f42c2588357bf5e64bbaeb5ee4b2a86a32fd 100644 (file)
@@ -1645,7 +1645,6 @@ gistprunepage(Relation rel, Page page, Buffer buffer, Relation heapRel)
        int                     ndeletable = 0;
        OffsetNumber offnum,
                                maxoff;
-       TransactionId latestRemovedXid = InvalidTransactionId;
 
        Assert(GistPageIsLeaf(page));
 
@@ -1664,13 +1663,15 @@ gistprunepage(Relation rel, Page page, Buffer buffer, Relation heapRel)
                        deletable[ndeletable++] = offnum;
        }
 
-       if (XLogStandbyInfoActive() && RelationNeedsWAL(rel))
-               latestRemovedXid =
-                       index_compute_xid_horizon_for_tuples(rel, heapRel, buffer,
-                                                                                                deletable, ndeletable);
-
        if (ndeletable > 0)
        {
+               TransactionId latestRemovedXid = InvalidTransactionId;
+
+               if (XLogStandbyInfoActive() && RelationNeedsWAL(rel))
+                       latestRemovedXid =
+                               index_compute_xid_horizon_for_tuples(rel, heapRel, buffer,
+                                                                                                        deletable, ndeletable);
+
                START_CRIT_SECTION();
 
                PageIndexMultiDelete(page, deletable, ndeletable);
index c911c705ba62f0955ad8ca302540a5753b5869ac..1c3e937c61534326df9dc7ef2ccb0ac0afd29f57 100644 (file)
@@ -301,6 +301,8 @@ index_compute_xid_horizon_for_tuples(Relation irel,
        Page            ipage = BufferGetPage(ibuf);
        IndexTuple      itup;
 
+       Assert(nitems > 0);
+
        delstate.bottomup = false;
        delstate.bottomupfreespace = 0;
        delstate.ndeltids = 0;