| From: | Henson Choi <assam258(at)gmail(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| 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-19 07:22:28 |
| Message-ID: | CAAAe_zBzVHBabZeD3GMSQsEKAe7CZAw_LZHrf3bgPR3bdtKY5Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi Tom,
> In particular, if tuplestore had an API call to the
> effect of "set the read pointer to absolute tuple number N", we
> could get rid of a lot of silliness in WindowAgg. Having a call
> to read out the position as an absolute tuple number might help
> too, but I'm not sure we'd even need it if we had the first one.
v3 follows that direction. There are four patches.
0001 removes needless complexity unrelated to this bug: only the
heap tuple kind exists, so the tuple-kind callbacks become direct
calls. It can be dropped if you prefer.
0002 gives each read pointer an absolute row number, counted from 0
since creation or the last tuplestore_clear(). Assert-enabled builds
check it against the array position while the store is in memory.
0003 adds tuplestore_tell() and tuplestore_seek(). tell returns the
number of the row the next forward fetch would return, or the number
of rows stored at EOF. seek clears the EOF state, as fseek() does.
In memory it computes the array position; on disk it steps over the
records by their length words without reading the tuples, so the
cost is still proportional to the distance.
I also added tell. As the counterpart of seek it is likely to find
uses, and WinSetMarkPosition() already uses it to move the read
pointer only forward.
0004 removes seekpos from WindowAgg. window_gettupleslot() positions
the pointer with tell and seek, and WinSetMarkPosition() never seeks
past the stored rows, so a WindowObject's pointer never reaches EOF.
Asserts check that in both places. The regression test is the same
as in v1 and v2.
> There are
> some fine points to be dealt with, like compensating for
> "tuplestore_trim" operations
The row numbers are not affected by trim. Trim does not change the
total row count tuplestore keeps, and the in-memory array position is
derived from that count. A seek to a trimmed row returns false.
v3 is for master. For the back branches, I'd like your view on
whether to use this series or v2. It applies to REL_19 as is; 14 to
18 need small context adjustments.
Best regards,
Henson
| Attachment | Content-Type | Size |
|---|---|---|
| v3-0001-Remove-tuple-kind-callback-indirection-from-tuple.patch | application/octet-stream | 9.1 KB |
| v3-0002-Track-absolute-row-numbers-in-tuplestore-read-poi.patch | application/octet-stream | 8.5 KB |
| v3-0003-Add-tuplestore_tell-and-tuplestore_seek.patch | application/octet-stream | 7.6 KB |
| v3-0004-Use-absolute-tuplestore-positions-in-WindowAgg.patch | application/octet-stream | 8.1 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Daniel Gustafsson | 2026-11-19 11:53:22 | Re: BUG #19920: Out-of-Bounds Read on a Zero-Length Array in pg_trgm word_similarity('', '') |
| Previous Message | Fujii Masao | 2026-11-19 07:14:21 | Re: BUG #19776: pg_combinebackup ignores the truncation_block_length of an intermediate incremental backup |