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 1spNtJ-0014mp-Ar for pgsql-hackers@arkaria.postgresql.org; Sat, 14 Sep 2024 08:12:26 +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 1spNtI-007Hqp-2Y for pgsql-hackers@arkaria.postgresql.org; Sat, 14 Sep 2024 08:12:24 +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 1spNtH-007HpX-Kf for pgsql-hackers@lists.postgresql.org; Sat, 14 Sep 2024 08:12:23 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1spNtE-0015nT-EP for pgsql-hackers@postgresql.org; Sat, 14 Sep 2024 08:12:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=iWYveygv012LSfcj+pymRcVE4MLMVK3mECU2vIMXW2E=; b=129SDrcpb9l4VF0yL+bpenSTi4 lK3I2sNMuQSHZhhB/RBfYkkh54Cu4cNMIWGeEmjHFLREzlRr27tHv6ENU8fQOEdK+1r+Zgj6tiNTX uzvV58AcjacdXek0UyygEAgTyqhB162q4MXTcesL8yQypJ3zzZreCMNeQ+OwlNhBKoRWxwemj8rUY Z973SUrOoQ2Bte47zxiGVKq/n+JPmocg6VNGNT15bQECAbLlclxO3DjtVAgHBgR+IcqtTgQa0LIQ2 ueAVbuGrHwffgZ84at4o4Rg4NpACB57l87okUXNPmlykNEVtBJq/eERySWwzDvIoVe1buytD30CnP mlWpGuCA==; Received: from 4.140.178.217.shared.user.transix.jp ([217.178.140.4] helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1spNt9-002dtZ-Jv; Sat, 14 Sep 2024 08:12:19 +0000 Date: Sat, 14 Sep 2024 17:12:01 +0900 (JST) Message-Id: <20240914.171201.2241093933296787263.ishii@postgresql.org> To: ashutosh.bapat.oss@gmail.com Cc: dgrowleyml@gmail.com, orlovmg@gmail.com, jian.universality@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Add memory/disk usage for WindowAgg nodes in EXPLAIN From: Tatsuo Ishii In-Reply-To: References: <20240913.183153.727679591062671857.ishii@postgresql.org> X-Mailer: Mew version 6.8 on Emacs 26.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk >> > or the case when the last usage fit in memory but an earlier >> > usage spilled to disk. >> >> In my understanding once tuplestore changes the storage type to disk, >> it never returns to the memory storage type in terms of >> tuplestore_get_stats. i.e. once state->usedDisk is set to true, it >> never goes back to false. So the test case is not necessary. >> David, am I correct? > > I understand that. I am requesting a testcase to test that same logic. Maybe something like this? In the example below there are 2 partitions. the first one has 1998 rows and the second one has 2 rows. Assuming that work_mem is 64kB, the first one does not fit the memory and spills to disk. The second partition fits memory. However as state->usedDisk remains true, explain shows "Storage: Disk". test=# explain (analyze,costs off) select sum(n) over(partition by m) from (SELECT n < 3 as m, n from generate_series(1,2000) a(n)); n QUERY PLAN -------------------------------------------------------------------------------- ------------- WindowAgg (actual time=1.958..473328.589 rows=2000 loops=1) Storage: Disk Maximum Storage: 65kB -> Sort (actual time=1.008..1.277 rows=2000 loops=1) Sort Key: ((a.n < 3)) Sort Method: external merge Disk: 48kB -> Function Scan on generate_series a (actual time=0.300..0.633 rows=2 000 loops=1) Planning Time: 0.069 ms Execution Time: 474515.476 ms (8 rows) Best reagards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp