From 3b7f5978f1d63244be03cde5c2c9f2acad3328b3 Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Tue, 24 Nov 2026 15:14:28 +0900 Subject: [PATCH v7 2/9] Fix new tuplestore read pointer position in READFILE. tuplestore_alloc_read_pointer() initializes the new pointer by copying read pointer 0. In READFILE state the active pointer's position lives only in the temp file's seek point, so when pointer 0 is active the copied file/offset were stale. Take the position with BufFileTell() in that case, as tuplestore_copy_read_pointer() already does. No current caller is affected: they allocate pointers before storing any tuple, or rewind the new pointer right away. --- src/backend/utils/sort/tuplestore.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c index 4f0d3571abb..8371d5fb6e1 100644 --- a/src/backend/utils/sort/tuplestore.c +++ b/src/backend/utils/sort/tuplestore.c @@ -449,6 +449,18 @@ tuplestore_alloc_read_pointer(Tuplestorestate *state, int eflags) state->readptrs[state->readptrcount] = state->readptrs[0]; state->readptrs[state->readptrcount].eflags = eflags; + /* + * In READFILE state the active read pointer's position is the temp file's + * seek point, not what is in its variables. So if pointer 0 is active, + * take the position with a tell, as tuplestore_copy_read_pointer does; + * not needed when eof_reached. + */ + if (state->status == TSS_READFILE && state->activeptr == 0 && + !state->readptrs[0].eof_reached) + BufFileTell(state->myfile, + &state->readptrs[state->readptrcount].file, + &state->readptrs[state->readptrcount].offset); + state->eflags |= eflags; return state->readptrcount++;