From: Tom Lane Date: Tue, 7 Oct 2008 00:05:55 +0000 (+0000) Subject: Fix oversight in recent patch to support multiple read positions in X-Git-Tag: recoveryinfrav9~560 X-Git-Url: http://git.postgresql.org/gitweb/irc:/static/gitweb.js?a=commitdiff_plain;h=7e128e002b88d689e17e517d21eabefeaa19bffb;p=users%2Fsimon%2Fpostgres.git Fix oversight in recent patch to support multiple read positions in tuplestore: in READFILE state tuplestore_select_read_pointer must save the current file seek position in the read pointer being deactivated. --- diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c index 9e9ffec53e..d2eff7ba3c 100644 --- a/src/backend/utils/sort/tuplestore.c +++ b/src/backend/utils/sort/tuplestore.c @@ -434,7 +434,8 @@ tuplestore_end(Tuplestorestate *state) void tuplestore_select_read_pointer(Tuplestorestate *state, int ptr) { - TSReadPointer *readptr = &state->readptrs[ptr]; + TSReadPointer *readptr; + TSReadPointer *oldptr; Assert(ptr >= 0 && ptr < state->readptrcount); @@ -442,6 +443,9 @@ tuplestore_select_read_pointer(Tuplestorestate *state, int ptr) if (ptr == state->activeptr) return; + readptr = &state->readptrs[ptr]; + oldptr = &state->readptrs[state->activeptr]; + switch (state->status) { case TSS_INMEM: @@ -449,10 +453,19 @@ tuplestore_select_read_pointer(Tuplestorestate *state, int ptr) /* no work */ break; case TSS_READFILE: + /* + * First, save the current read position in the pointer about + * to become inactive. + */ + if (!oldptr->eof_reached) + BufFileTell(state->myfile, + &oldptr->file, + &oldptr->offset); + /* * We have to make the temp file's seek position equal to the - * logical position of the read pointer. In eof_reached state, - * that's the EOF, which we have available from the saved + * logical position of the new read pointer. In eof_reached + * state, that's the EOF, which we have available from the saved * write position. */ if (readptr->eof_reached)