From 4736de3f7cd9071d7be565be43b5835430a0ff9e Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Mon, 30 Nov 2026 14:49:09 +0900 Subject: [PATCH v7 9/9] Fix outdated comments in tuplestore.c. The header comment named hashjoin batch files as a user of tuplestore, but those use BufFile directly, and it said the positions are saved with ftell(). tuplestore_in_memory() said it returns true if the store has not spilled to disk, though tuplestore_clear() brings a spilled store back into memory. Also say which read pointer the backward-scan rule of tuplestore_gettuple() is about, and that the read positions are kept in the read pointers. --- src/backend/utils/sort/tuplestore.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c index 783a9152fdc..fb0cb6af320 100644 --- a/src/backend/utils/sort/tuplestore.c +++ b/src/backend/utils/sort/tuplestore.c @@ -4,7 +4,7 @@ * Generalized routines for temporary tuple storage. * * This module handles temporary storage of tuples for purposes such - * as Materialize nodes, hashjoin batch files, etc. It is essentially + * as Materialize nodes, CTE scans, etc. It is essentially * a dumbed-down version of tuplesort.c; it does no sorting of tuples * but can only store and regurgitate a sequence of tuples. However, * because no sort is required, it is allowed to start reading the sequence @@ -39,8 +39,9 @@ * current write position, and the write-position variables in the tuplestore * aren't kept up to date. Similarly, in TSS_READFILE state the temp file's * seek position is the active read pointer's position, and that read pointer - * isn't kept up to date. We update the appropriate variables using ftell() - * before switching to the other state or activating a different read pointer. + * isn't kept up to date. We update the appropriate variables using + * BufFileTell() before switching to the other state or activating a different + * read pointer. * * * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group @@ -202,7 +203,8 @@ struct Tuplestorestate int64 rowstrimmed; /* number of rows trimmed so far */ /* - * These variables are used to keep track of the current positions. + * These variables are used to keep track of the current read and write + * positions; the read positions are in the read pointers. * * In state WRITEFILE, the current file seek position is the write point; * in state READFILE, the write position is remembered in writepos_xxx. @@ -1001,8 +1003,9 @@ tuplestore_puttuple_common(Tuplestorestate *state, void *tuple) * Returns NULL if no more tuples. If should_free is set, the * caller must pfree the returned tuple when done with it. * - * Backward scan is only allowed if randomAccess was set true or - * EXEC_FLAG_BACKWARD was specified to tuplestore_set_eflags(). + * Backward scan is only allowed if the active read pointer has + * EXEC_FLAG_BACKWARD, as set by randomAccess, tuplestore_set_eflags() or + * tuplestore_alloc_read_pointer(). */ static void * tuplestore_gettuple(Tuplestorestate *state, bool forward, @@ -1827,7 +1830,8 @@ tuplestore_get_stats(Tuplestorestate *state, bool *used_disk, int64 *max_space) /* * tuplestore_in_memory * - * Returns true if the tuplestore has not spilled to disk. + * Returns true if the tuplestore has not spilled to disk since it was + * created or last cleared. * * XXX exposing this is a violation of modularity ... should get rid of it. */