From e41417571307cbf1f019525a3a7d3bf98e7c4603 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Sat, 23 Aug 2008 10:41:38 +0000 Subject: Fix possible duplicate tuples while GiST scan. Now page is processed at once and ItemPointers are collected in memory. Remove tuple's killing by killtuple() if tuple was moved to another page - it could produce unaceptable overhead. Backpatch up to 8.1 because the bug was introduced by GiST's concurrency support. --- src/backend/access/gist/gistscan.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/backend/access/gist/gistscan.c') diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c index b0fdb740047..4864fd1248d 100644 --- a/src/backend/access/gist/gistscan.c +++ b/src/backend/access/gist/gistscan.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.65 2006/10/04 00:29:48 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.65.2.1 2008/08/23 10:41:38 teodor Exp $ * *------------------------------------------------------------------------- */ @@ -67,6 +67,7 @@ gistrescan(PG_FUNCTION_ARGS) ReleaseBuffer(so->markbuf); so->markbuf = InvalidBuffer; } + } else { @@ -82,6 +83,8 @@ gistrescan(PG_FUNCTION_ARGS) scan->opaque = so; } + so->nPageData = so->curPageData = 0; + /* Update scan key, if a new one is given */ if (key && scan->numberOfKeys > 0) { @@ -148,6 +151,11 @@ gistmarkpos(PG_FUNCTION_ARGS) so->markbuf = so->curbuf; } + so->markNPageData = so->nPageData; + so->markCurPageData = so->curPageData; + if ( so->markNPageData > 0 ) + memcpy( so->markPageData, so->pageData, sizeof(ItemPointerData) * so->markNPageData ); + PG_RETURN_VOID(); } @@ -197,6 +205,11 @@ gistrestrpos(PG_FUNCTION_ARGS) so->curbuf = so->markbuf; } + so->nPageData = so->markNPageData; + so->curPageData = so->markNPageData; + if ( so->markNPageData > 0 ) + memcpy( so->pageData, so->markPageData, sizeof(ItemPointerData) * so->markNPageData ); + PG_RETURN_VOID(); } -- cgit v1.2.3