Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTNud-00000000IUk-3lkA for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Nov 2026 18:28:12 +0000 Received: from localhost ([127.0.0.1]:54616 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xTNud-00000006Vhv-1Mgf for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Nov 2026 18:28:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:46086) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTJ5Z-00000005Tci-3UUB for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 13:19:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTJ5W-00000000Aze-2aQT for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 13:19:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=2AQbAJ8qF0AS0aHeiCUL1Z3C5YsUN4ORtTWyUyGN8Eg=; b=imWBuQcQtB8UvuhrP253oUtbi+ 4vrBPoiICo63H5RxUVPjRCmp23XfbFdncHHXegkZph6uEYaz2vFDKL1L5mrbsmmSAk2s/jKSYMyDm K7OUE0cdIh8H1eyAiVWR7TaVSRoScq7hgqVFfVqAfkzjzWRyW9SPEzD8CiovmSyBjektq5sq0+KdI dZYeJ9hjwAOXef3yT6Pl5uXF5Re7HBMNjvxFSNMs/WAwhlR3ReCaYrwfqbpjUC4g23j+BBrbYb/e7 fiPArhR6wyyJ0kgtpzvMiG+UepZZc4Ncme3HGpodBDsqz+yZrRzovme5vUXUyIEQP2nAVKo/+rP4d czqezyhw==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTJ5U-00000000RCn-2ZL7 for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 13:19:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xTJ5T-000000017Nq-0FRx for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 13:19:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19911: Window aggregate over ROWS n FOLLOWING: "unexpected end of tuplestore" after spill To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: tharakan@gmail.com Reply-To: tharakan@gmail.com, pgsql-bugs@lists.postgresql.org Date: Tue, 17 Nov 2026 13:18:49 +0000 Message-ID: <19911-991c431cc0ba50d1@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19911 Logged by: Robins Tharakan Email address: tharakan@gmail.com PostgreSQL version: Unsupported/Unknown Operating system: Debian 13 (x86_64) Description: =20 A window aggregate whose ROWS frame starts at an offset FOLLOWING fails with an internal error when the rows before the frame's start don't fit in work_mem: ERROR: XX000: unexpected end of tuplestore LOCATION: window_gettupleslot, nodeWindowAgg.c:3358 The query should return its rows: with work_mem large enough for the partition (4MB for the first query below), it does. It fails the same way for max(), sum() and count(*), with or without PARTITION BY or ORDER BY. first_value() and nth_value(), RANGE and GROUPS frames, and frames starting at an offset PRECEDING give the same rows at 64kB as at 64MB. A Valgrind run didn't report much else interesting. SQL =3D=3D=3D SET work_mem =3D '64kB'; SELECT count(x), max(x) FROM (SELECT max(g) OVER (ROWS BETWEEN 2000 FOLLOWING AND UNBOUNDED FOLLOWING) AS x FROM generate_series(1, 2002) g) s; -- expected: 2 | 2002 (as with work_mem =3D '4MB') -- got: ERROR: XX000: unexpected end of tuplestore Commit =3D=3D=3D=3D=3D=3D Reproduces on master (11591f273e6) and on every supported branch, including v14 (853b35f35b1). A release build (no assertions, -O2) raises the same error. Error Log =3D=3D=3D=3D=3D=3D=3D ERROR: unexpected end of tuplestore STATEMENT: SELECT count(x), max(x) FROM (SELECT max(g) OVER (ROWS BETWEEN 2000 FOLLOWING AND UNBOUNDED FOLLOWING) AS x FROM generate_series(1, 2002) g) s; Backtrace =3D=3D=3D=3D=3D=3D=3D=3D #0 window_gettupleslot (winobj=3D..., pos=3D2001, slot=3D...) at nodeWindowAgg.c:3358 #1 eval_windowaggregates (winstate=3D...) at nodeWindowAgg.c:982 #2 ExecWindowAgg (pstate=3D...) at nodeWindowAgg.c:2431 #3 ExecProcNodeFirst (node=3D...) at execProcnode.c:469 #4 ExecProcNode (node=3D...) at executor.h:327 #5 fetch_input_tuple (aggstate=3D...) at nodeAgg.c:564 #6 agg_retrieve_direct (aggstate=3D...) at nodeAgg.c:2464 #7 ExecAgg (pstate=3D...) at nodeAgg.c:2279 At #0, for the first output row (currentpos 0, frameheadpos 2000): the fetch of row 2000 has just returned g =3D 2002, and the read pointer is at EOF with seekpos 2000. Found using SQLsmith, SQLReduce, creduce and Claude. - Robins Tharakan Databricks