|
46 | 46 | * Portions Copyright (c) 1994, Regents of the University of California |
47 | 47 | * |
48 | 48 | * IDENTIFICATION |
49 | | - * $PostgreSQL: pgsql/src/backend/utils/sort/tuplestore.c,v 1.41 2008/10/04 21:56:54 tgl Exp $ |
| 49 | + * $PostgreSQL: pgsql/src/backend/utils/sort/tuplestore.c,v 1.42 2008/10/07 00:05:55 tgl Exp $ |
50 | 50 | * |
51 | 51 | *------------------------------------------------------------------------- |
52 | 52 | */ |
@@ -434,25 +434,38 @@ tuplestore_end(Tuplestorestate *state) |
434 | 434 | void |
435 | 435 | tuplestore_select_read_pointer(Tuplestorestate*state,intptr) |
436 | 436 | { |
437 | | -TSReadPointer*readptr=&state->readptrs[ptr]; |
| 437 | +TSReadPointer*readptr; |
| 438 | +TSReadPointer*oldptr; |
438 | 439 |
|
439 | 440 | Assert(ptr >=0&&ptr<state->readptrcount); |
440 | 441 |
|
441 | 442 | /* No work if already active */ |
442 | 443 | if (ptr==state->activeptr) |
443 | 444 | return; |
444 | 445 |
|
| 446 | +readptr=&state->readptrs[ptr]; |
| 447 | +oldptr=&state->readptrs[state->activeptr]; |
| 448 | + |
445 | 449 | switch (state->status) |
446 | 450 | { |
447 | 451 | caseTSS_INMEM: |
448 | 452 | caseTSS_WRITEFILE: |
449 | 453 | /* no work */ |
450 | 454 | break; |
451 | 455 | caseTSS_READFILE: |
| 456 | +/* |
| 457 | + * First, save the current read position in the pointer about |
| 458 | + * to become inactive. |
| 459 | + */ |
| 460 | +if (!oldptr->eof_reached) |
| 461 | +BufFileTell(state->myfile, |
| 462 | +&oldptr->file, |
| 463 | +&oldptr->offset); |
| 464 | + |
452 | 465 | /* |
453 | 466 | * We have to make the temp file's seek position equal to the |
454 | | - * logical position of the read pointer. In eof_reached state, |
455 | | - * that's the EOF, which we have available from the saved |
| 467 | + * logical position of thenewread pointer. In eof_reached |
| 468 | + *state,that's the EOF, which we have available from the saved |
456 | 469 | * write position. |
457 | 470 | */ |
458 | 471 | if (readptr->eof_reached) |
|