Re: BUG #19911: Window aggregate over ROWS n FOLLOWING: "unexpected end of tuplestore" after spill

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: assam258(at)gmail(dot)com
Cc: tharakan(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19911: Window aggregate over ROWS n FOLLOWING: "unexpected end of tuplestore" after spill
Date: 2026-11-24 17:24:31
Message-ID: 1016045.1795541071@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Henson Choi <assam258(at)gmail(dot)com> writes:
> v6 numbering (v6-0002 is new, v6-0004 and v6-0006 have the changes
> below, the rest are unchanged from v5):

> v6 v5 v4
> 0001 0001 0001 Track absolute row numbers
> 0002 (new) Fix new read pointer position in READFILE
> 0003 0002 0002 Add tuplestore_tell() and tuplestore_seek()
> 0004 0003 Do not let seek land on the tuple kept by a trim
> 0005 0004 0003 Reimplement advance() and skiptuples()
> 0006 0005 Fix skiptuples() at the boundaries
> 0007 0006 0004 Use absolute tuplestore positions in WindowAgg
> 0008 0007 Keep accepting a mark position of -1

Thanks for this additional work.

v6-0002: Good catch. I concur that this error is probably not
reachable from any in-core code, but we should fix it for the
possible benefit of extensions. The proposed one-line comment
feels a bit too terse, otherwise fine.

v6-0004: this definitely makes me feel like I chose the wrong
definition for rowstrimmed, ie it should include memtupdeleted in
TSS_INMEM state. You sure it's preferable to leave it this way?
I'm also feeling uncomfortable with the logic around whether the
extra untrimmed tuple counts as a legal move destination. That
all seems squishy and easy to get wrong; I wonder if we should
do it another way, e.g. explicitly hold onto that tuple via a
separate pointer until the next tuplestore operation.

v6-0006: I agree I messed up on the step-backwards-from-EOF case,
but somehow this coding feels uglier than the approach I used
before. In particular, the forward case wasn't broken but this
way of coding it doesn't seem like an improvement to me. Maybe
it's all in the eye of the beholder.

v6-0008: I do not see a need for this. No documentation or comment
suggests that WinSetMarkPosition will accept -1, and the fact that
it did seems to me like an implementation artifact. (I have a very
vague recollection that initializing markpos = -1 was meant to
record that no WinSetMarkPosition call had happened; but we have not
actually needed that information, so we might as well simplify.)
I also think trying to preserve exact bug-compatibility here is
inconsistent with the fact that we're probably not going to preserve
it with respect to reachability of the untrimmed tuple.

> ... I would like to redesign the file-mode storage layout as a
> separate patch in the first half of next year, and that would redefine
> trim and the fields behind it to fit the new layout.

I agree that we need to do some additional performance work here,
but this sketch seems a trifle over-ambitious. I had also thought
of the idea of keeping an index of block-starting tuples, and I
think we ought to see what that will buy us, but I'm less on board
with the rest of this. The complexity vs. performance tradeoff
is not sounding great. But that's a discussion for another day.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Previous Message Matheus Alcantara 2026-11-24 16:33:07 Re: BUG #19931: postgres_fdw: FOR UPDATE over a pushed-down join ignores a pseudoconstant qual