But It seems to me that it would be better to rewrite all mentions of
TupleDelete to MultiDelete in gist code.


Sure. Patch is attached, and it changes WAL format, so be carefull with testing.
Please, have a look.

Also in attach scripts reproduce bug from Jeff's report:
g.pl - creates and fills test table
w.pl - worker, could run in several session

Usage
perl g.pl | psql contrib_regression
perl w.pl |  psql contrib_regression | grep 'UPDATE 0'

and killall -9 postgres while w.pl is running. Recovery will fail with high probability.

Thank you, Jeff, for report.
--
Teodor Sigaev                                   E-mail: teo...@sigaev.ru
                                                   WWW: http://www.sigaev.ru/
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 4edc5a7..53bccf6 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -466,6 +466,11 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE 
*giststate,
                 */
                START_CRIT_SECTION();
 
+               /*
+                * While we delete only one tuple at once we could mix calls
+                * PageIndexTupleDelete() here and PageIndexMultiDelete() in
+                * gistRedoPageUpdateRecord()
+                */
                if (OffsetNumberIsValid(oldoffnum))
                        PageIndexTupleDelete(page, oldoffnum);
                gistfillbuffer(page, itup, ntup, InvalidOffsetNumber);
diff --git a/src/backend/access/gist/gistvacuum.c 
b/src/backend/access/gist/gistvacuum.c
index 2337dbd..a0b0eeb 100644
--- a/src/backend/access/gist/gistvacuum.c
+++ b/src/backend/access/gist/gistvacuum.c
@@ -208,23 +208,20 @@ gistbulkdelete(PG_FUNCTION_ARGS)
                                idxtuple = (IndexTuple) PageGetItem(page, iid);
 
                                if (callback(&(idxtuple->t_tid), 
callback_state))
-                               {
-                                       todelete[ntodelete] = i - ntodelete;
-                                       ntodelete++;
-                                       stats->tuples_removed += 1;
-                               }
+                                       todelete[ntodelete++] = i;
                                else
                                        stats->num_index_tuples += 1;
                        }
 
+                       stats->tuples_removed += ntodelete;
+
                        if (ntodelete)
                        {
                                START_CRIT_SECTION();
 
                                MarkBufferDirty(buffer);
 
-                               for (i = 0; i < ntodelete; i++)
-                                       PageIndexTupleDelete(page, todelete[i]);
+                               PageIndexMultiDelete(page, todelete, ntodelete);
                                GistMarkTuplesDeleted(page);
 
                                if (RelationNeedsWAL(rel))
diff --git a/src/backend/access/gist/gistxlog.c 
b/src/backend/access/gist/gistxlog.c
index fbdbb3c..c63cc81 100644
--- a/src/backend/access/gist/gistxlog.c
+++ b/src/backend/access/gist/gistxlog.c
@@ -83,13 +83,11 @@ gistRedoPageUpdateRecord(XLogReaderState *record)
                /* Delete old tuples */
                if (xldata->ntodelete > 0)
                {
-                       int                     i;
                        OffsetNumber *todelete = (OffsetNumber *) data;
 
                        data += sizeof(OffsetNumber) * xldata->ntodelete;
 
-                       for (i = 0; i < xldata->ntodelete; i++)
-                               PageIndexTupleDelete(page, todelete[i]);
+                       PageIndexMultiDelete(page, todelete, xldata->ntodelete);
                        if (GistPageIsLeaf(page))
                                GistMarkTuplesDeleted(page);
                }

Attachment: g.pl
Description: Perl program

Attachment: w.pl
Description: Perl program

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to