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 1sR0qN-00Crjk-1U for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jul 2024 02:44:39 +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 1sR0qK-00BrQE-4W for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jul 2024 02:44:36 +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 1sR0qJ-00BrQ6-Od for pgsql-hackers@lists.postgresql.org; Tue, 09 Jul 2024 02:44:35 +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 1sR0qF-0018Jc-Us for pgsql-hackers@postgresql.org; Tue, 09 Jul 2024 02:44:34 +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=b2Bfve7Bm8zaNZGvz09vO7AdPObjw2E9nnmBKOJZ640=; b=ELPjLeypRJyDfy8njJ2K92kZ6c u9/ywuRq4RU0bYSy5wA8HpsrHA7YWiwBYMq+9sIDsw5zZ2jopD7Xa+OE8GmOcnWMBEBtpX1zEjNf+ yvmjz83BVQFPlqAByWyW0FK/gJa/tmblcddIvvOqCuTfuP9Au7E+VJEHW4JTgyy7l/a+eJSwYvkRS EsD5GRIttc8ncys/xl6jzuRPgFlHNelskH2dGWVbIDMStRreliYke3hmy840x9jQs6cQQFq1Yr+9L 4snHJsIeDunGacyaKFBZ/gqzJ1tZfPuU9cDdvCukDqogwrvl93pMsirqnGRj/cgh3r/bJ1x1ypWg+ q95M8Iow==; Received: from [2409:11:4120:300:75c1:a5c2:7690:c6aa] (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 1sR0qC-002OTM-3M; Tue, 09 Jul 2024 02:44:30 +0000 Date: Tue, 09 Jul 2024 11:44:12 +0900 (JST) Message-Id: <20240709.114412.199303920149670049.ishii@postgresql.org> To: dgrowleyml@gmail.com Cc: pgsql-hackers@postgresql.org Subject: Re: Add memory/disk usage for WindowAgg nodes in EXPLAIN From: Tatsuo Ishii In-Reply-To: References: <20240706.202254.89740021795421286.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 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:75c1:a5c2:7690:c6aa (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Sat, 6 Jul 2024 at 23:23, Tatsuo Ishii wrote: >> So I wanted to Add memory/disk usage for WindowAgg. Patch attached. > > Thanks for working on that. Thank you for the infrastructure you created in tuplestore.c and explain.c. BTW, it seems these executor nodes (other than Materialize and Window Aggregate node) use tuplestore for their own purpose. CTE Scan Recursive Union Table Function Scan I have already implemented that for CTE Scan. Do you think other two nodes are worth to add the information? I think for consistency sake, it will better to add the info Recursive Union and Table Function Scan. >> Since WindowAgg node could create multiple tuplestore for each Window >> partition, we need to track each tuplestore storage usage so that the >> maximum storage usage is determined. For this purpose I added new >> fields to the WindowAggState. > > I'd recently been looking at the code that recreates the tuplestore > for each partition and thought we could do a bit better. In [1], I > proposed a patch to make this better. > > If you based your patch on [1], maybe a better way of doing this is > having tuplestore.c track the maximum space used on disk in an extra > field which is updated with tuplestore_clear(). It's probably ok to > update a new field called maxDiskSpace in tuplestore_clear() if > state->status != TSS_INMEM. If the tuplestore went to disk then an > extra call to BufFileSize() isn't going to be noticeable, even in > cases where we only just went over work_mem. You could then adjust > tuplestore_space_used() to look at maxDiskSpace and return that value > if it's larger than BufFileSize(state->myfile) and state->maxSpace. > You could check if maxDiskSpace == 0 to determine if the tuplestore > has ever gone to disk. tuplestore_storage_type_name() would also need > to check maxDiskSpace and return "Disk" if that's non-zero. Thank you for the suggestion. Yes, I noticed [1] and once it is committed, I will start to study tuplestore.c in this direction. Best reagards, -- Tatsuo Ishii SRA OSS LLC English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp