From 8a9adb3139b4a9974a099f98ba4408aa36df0891 Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Tue, 24 Nov 2026 15:14:28 +0900 Subject: [PATCH v6 2/8] 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. Author: Henson Choi Discussion: https://postgr.es/m/19911-991c431cc0ba50d1@postgresql.org --- src/backend/utils/sort/tuplestore.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c index 4f0d3571abb..cf92276cf87 100644 --- a/src/backend/utils/sort/tuplestore.c +++ b/src/backend/utils/sort/tuplestore.c @@ -449,6 +449,13 @@ tuplestore_alloc_read_pointer(Tuplestorestate *state, int eflags) state->readptrs[state->readptrcount] = state->readptrs[0]; state->readptrs[state->readptrcount].eflags = eflags; + /* In READFILE, an active pointer 0's position is the seek point */ + 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++; -- 2.54.0 (Apple Git-157)