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 1rD96n-0014W8-HJ for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Dec 2023 20:12:01 +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 1rD96l-007xZU-OD for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Dec 2023 20:11:59 +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 1rD96k-007xZM-Kj for pgsql-hackers@lists.postgresql.org; Tue, 12 Dec 2023 20:11:59 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rD96e-00A5Hw-4g for pgsql-hackers@lists.postgresql.org; Tue, 12 Dec 2023 20:11:57 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 3496D3200A59; Tue, 12 Dec 2023 15:11:50 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 12 Dec 2023 15:11:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1702411909; x= 1702498309; bh=YAxqNccY33vjFRD2J1nb5LIssxtrzSmP39UncSU2ESg=; b=2 luhxqMwGB0FwO6ciXy9I+1jA5cIDaqwjywL6G+5Zrwd3OnL92ysuka5krb4/V5kW Iy+3vO833/PN8gBvi8yCx6572MAAU5EZvIosHMwnjQXfqZHoWqrQUYsscw2WjlW9 nGeqQsyrj/byh6Vo9z1mHYPejXcRzUeYpKNuBkNr0oQtXN6zPiu80a3eYBYTHiQ3 ZQMZ2SLeFevtxKRON6Feyr3UNigOSqdASouMHFs8a94hjjx47l01LnNciGmSXfcH xp2zJhjiSNJuc2RpLeixHAzpV9N/3cd39bdny+69+mkbiq5uqOkpqqgtzBcEnSAW 0Af9ZEJHH7gLNVPLjSGvQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudelgedgudefudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhv rghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorh hgqeenucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeej keffgfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtoh hmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghl vhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Dec 2023 15:11:48 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1702411891; bh=TaOR5xRvEseHDyr+1rcWh7Y/UdwiyazyNp4iWQgp0P4=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=hvQkE8oB8Q0ROXEfYOdHk4Qz0dmWENF2y2GuiSn7SfzGufQXimgJGlKvQ1xpjQU/D zZnfZOoZsp5nZkeaohWbaDrN8NoXdfDJmTF6plZ4haskTvpjwMLsvTwgKeKmqDVEiV s3L0EGpYn/NwwHl7Rw24p5oA+WXb4NN46ZEHaa/m0xyqipm+3JneinbB47nXV8Ewsj P5BVlxe8TfjgCrCJH0Dk5VE7NNpsgYxS8JdnsyyJOU9K5sHEMhba/RdAGGg60HOI1v 2UAHHQOkOkEUpbWQPWuKqC7wMwA0BgKkNlyLl5HJtwXVK57LhDsxgq5cLlVw8zXvwk 86rTxtXKCEKdg== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id BBBCB3B5; Tue, 12 Dec 2023 21:11:31 +0100 (CET) Date: Tue, 12 Dec 2023 21:11:31 +0100 From: Alvaro Herrera To: Ashutosh Bapat Cc: jian he , Andrei Lepikhov , Andy Fan , David Rowley , PostgreSQL Hackers Subject: Re: Report planning memory in EXPLAIN ANALYZE Message-ID: <202312122011.glue4ur4ajb4@alvherre.pgsql> 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 I would replace the text in explain.sgml with this: + Include information on memory consumption by the query planning phase. + This includes the precise amount of storage used by planner in-memory + structures, as well as overall total consumption of planner memory, + including allocation overhead. + This parameter defaults to FALSE. and remove the new example you're adding; it's not really necessary. In struct ExplainState, I'd put the new member just below summary. If we're creating a new memory context for planner, we don't need the "mem_counts_start" thing, and we don't need the MemoryContextSizeDifference thing. Just add the MemoryContextMemConsumed() function (which ISTM should be just below MemoryContextMemAllocated() instead of in the middle of the MemoryContextStats implementation), and just report the values we get there. I think the SizeDifference stuff increases surface damage for no good reason. ExplainOnePlan() is given a MemoryUsage object (or, if we do as above and no longer have a MemoryUsage struct at all in the first place, a MemoryContextCounters object) even when the MEMORY option is false. This means we waste computing memory usage when not needed. Let's avoid that useless overhead. I'd also do away with the comment you added in explain_ExecutorEnd() and do just this, below setting of es->summary: + /* No support for MEMORY option */ + /* es->memory = false; */ We don't need to elaborate more at present. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Doing what he did amounts to sticking his fingers under the hood of the implementation; if he gets his fingers burnt, it's his problem." (Tom Lane)