summaryrefslogtreecommitdiff
path: root/src/backend/access/gist/gist.c
diff options
context:
space:
mode:
authorHeikki Linnakangas2010-11-16 09:02:11 +0000
committerHeikki Linnakangas2010-11-16 09:25:17 +0000
commitacbffaa77d0c4846f8749daa45fde507be1e969b (patch)
treee60e19eff1d2d7431411de753ee1a2f150ab3e31 /src/backend/access/gist/gist.c
parent0e27a7319155079ec817582968cd443e3ee0c3c7 (diff)
The GiST scan algorithm uses LSNs to detect concurrent pages splits, but
temporary indexes are not WAL-logged. We used a constant LSN for temporary indexes, on the assumption that we don't need to worry about concurrent page splits in temporary indexes because they're only visible to the current session. But that assumption is wrong, it's possible to insert rows and split pages in the same session, while a scan is in progress. For example, by opening a cursor and fetching some rows, and INSERTing new rows before fetching some more. Fix by generating fake increasing LSNs, used in place of real LSNs in temporary GiST indexes.
Diffstat (limited to 'src/backend/access/gist/gist.c')
-rw-r--r--src/backend/access/gist/gist.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 00b1620ab00..fbc828e7832 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -23,8 +23,6 @@
#include "miscadmin.h"
#include "utils/memutils.h"
-const XLogRecPtr XLogRecPtrForTemp = {1, 1};
-
/* Working state for gistbuild and its callback */
typedef struct
{
@@ -127,7 +125,7 @@ gistbuild(PG_FUNCTION_ARGS)
END_CRIT_SECTION();
}
else
- PageSetLSN(BufferGetPage(buffer), XLogRecPtrForTemp);
+ PageSetLSN(BufferGetPage(buffer), GetXLogRecPtrForTemp());
LockBuffer(buffer, GIST_UNLOCK);
WriteBuffer(buffer);
@@ -356,7 +354,7 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
ptr = dist;
while (ptr)
{
- PageSetLSN(BufferGetPage(ptr->buffer), XLogRecPtrForTemp);
+ PageSetLSN(BufferGetPage(ptr->buffer), GetXLogRecPtrForTemp());
ptr = ptr->next;
}
}
@@ -475,7 +473,7 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
END_CRIT_SECTION();
}
else
- PageSetLSN(state->stack->page, XLogRecPtrForTemp);
+ PageSetLSN(state->stack->page, GetXLogRecPtrForTemp());
if (state->stack->blkno == GIST_ROOT_BLKNO)
state->needInsertComplete = false;
@@ -1206,7 +1204,7 @@ gistnewroot(Relation r, Buffer buffer, IndexTuple *itup, int len, ItemPointer ke
END_CRIT_SECTION();
}
else
- PageSetLSN(page, XLogRecPtrForTemp);
+ PageSetLSN(page, GetXLogRecPtrForTemp());
}
void