From 668e37d13853b29f5549e78aaf678a32d19b9b8e Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 24 Dec 2009 17:52:04 +0000
Subject: [PATCH] Fix wrong WAL info value generated when gistContinueInsert()
 performs an index page split.  This would result in index corruption, or even
 more likely an error during WAL replay, if we were unlucky enough to crash
 during end-of-recovery cleanup after having completed an incomplete GIST
 insertion.

Yoichi Hirai
---
 src/backend/access/gist/gistxlog.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/backend/access/gist/gistxlog.c b/src/backend/access/gist/gistxlog.c
index 7a9f8934cf4..d6aeb22f3c5 100644
--- a/src/backend/access/gist/gistxlog.c
+++ b/src/backend/access/gist/gistxlog.c
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *			 $PostgreSQL: pgsql/src/backend/access/gist/gistxlog.c,v 1.33 2009/12/19 01:32:32 sriggs Exp $
+ *			 $PostgreSQL: pgsql/src/backend/access/gist/gistxlog.c,v 1.34 2009/12/24 17:52:04 tgl Exp $
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
@@ -650,6 +650,7 @@ gistContinueInsert(gistIncompleteInsert *insert)
 			int			j,
 						k,
 						pituplen = 0;
+			uint8		xlinfo;
 			XLogRecData *rdata;
 			XLogRecPtr	recptr;
 			Buffer		tempbuffer = InvalidBuffer;
@@ -738,6 +739,7 @@ gistContinueInsert(gistIncompleteInsert *insert)
 				for (j = 0; j < ntodelete; j++)
 					PageIndexTupleDelete(pages[0], todelete[j]);
 
+				xlinfo = XLOG_GIST_PAGE_SPLIT;
 				rdata = formSplitRdata(index->rd_node, insert->path[i],
 									   false, &(insert->key),
 									 gistMakePageLayout(buffers, numbuffer));
@@ -751,6 +753,7 @@ gistContinueInsert(gistIncompleteInsert *insert)
 					PageIndexTupleDelete(pages[0], todelete[j]);
 				gistfillbuffer(pages[0], itup, lenitup, InvalidOffsetNumber);
 
+				xlinfo = XLOG_GIST_PAGE_UPDATE;
 				rdata = formUpdateRdata(index->rd_node, buffers[0],
 										todelete, ntodelete,
 										itup, lenitup, &(insert->key));
@@ -767,7 +770,7 @@ gistContinueInsert(gistIncompleteInsert *insert)
 				GistPageGetOpaque(pages[j])->rightlink = InvalidBlockNumber;
 				MarkBufferDirty(buffers[j]);
 			}
-			recptr = XLogInsert(RM_GIST_ID, XLOG_GIST_PAGE_UPDATE, rdata);
+			recptr = XLogInsert(RM_GIST_ID, xlinfo, rdata);
 			for (j = 0; j < numbuffer; j++)
 			{
 				PageSetLSN(pages[j], recptr);
-- 
GitLab