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.94.2) (envelope-from ) id 1tzLw3-0018RU-0j for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Mar 2025 20:40:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tzLw1-00C6X2-9I for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Mar 2025 20:40:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tzLw0-00C6Wl-VP for pgsql-hackers@lists.postgresql.org; Mon, 31 Mar 2025 20:40:40 +0000 Received: from mout-p-201.mailbox.org ([2001:67c:2050:0:465::201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tzLvz-002Cx1-0t for pgsql-hackers@lists.postgresql.org; Mon, 31 Mar 2025 20:40:40 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4ZRNLS3LDKz9v2v; Mon, 31 Mar 2025 22:40:32 +0200 (CEST) Date: Mon, 31 Mar 2025 22:40:31 +0200 From: Christoph Berg To: David Rowley Cc: Tatsuo Ishii , pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Add memory/disk usage for Window aggregate nodes in EXPLAIN. Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Re: David Rowley > Any chance you could share the output of: > > explain (analyze,buffers off,costs off) select sum(n) over() from > generate_series(1,2000) a(n); PostgreSQL 18devel on x86-linux, compiled by gcc-14.2.0, 32-bit =# explain (analyze,buffers off,costs off) select sum(n) over() from generate_series(1,2000) a(n); QUERY PLAN ────────────────────────────────────────────────────────────────────────────────────────── WindowAgg (actual time=1.248..1.731 rows=2000.00 loops=1) Window: w1 AS () Storage: Memory Maximum Storage: 63kB -> Function Scan on generate_series a (actual time=0.301..0.536 rows=2000.00 loops=1) Planning Time: 0.066 ms Execution Time: 1.913 ms (6 rows) > Could you maybe also do a binary search for the number of rows where > it goes to disk by adjusting the 2000 up in some increments until the > Storage method is disk? (Not that I think we should set it to the > minimum, but it would be good to not set it too much higher than we > need to) The test has a `set work_mem = 64;` which I used here: =# explain (analyze,buffers off,costs off) select sum(n) over() from generate_series(1,2047) a(n); QUERY PLAN ────────────────────────────────────────────────────────────────────────────────────────── WindowAgg (actual time=1.037..1.429 rows=2047.00 loops=1) Window: w1 AS () Storage: Memory Maximum Storage: 64kB -> Function Scan on generate_series a (actual time=0.262..0.457 rows=2047.00 loops=1) Planning Time: 0.058 ms Execution Time: 1.594 ms (6 rows) =# explain (analyze,buffers off,costs off) select sum(n) over() from generate_series(1,2048) a(n); QUERY PLAN ────────────────────────────────────────────────────────────────────────────────────────── WindowAgg (actual time=2.073..2.686 rows=2048.00 loops=1) Window: w1 AS () Storage: Disk Maximum Storage: 65kB -> Function Scan on generate_series a (actual time=0.624..1.064 rows=2048.00 loops=1) Planning Time: 0.064 ms Execution Time: 2.934 ms (6 rows) (With the default work_mem, the tipping point is around 149500) Christoph