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 1thyOA-009Nvj-NJ for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Feb 2025 22:05:55 +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 1thyNA-0016nb-Hn for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Feb 2025 22:04:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1thyNA-0016nG-44 for pgsql-hackers@lists.postgresql.org; Tue, 11 Feb 2025 22:04:52 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1thyN7-000KQi-1p for pgsql-hackers@lists.postgresql.org; Tue, 11 Feb 2025 22:04:51 +0000 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2fa3e20952fso7677511a91.1 for ; Tue, 11 Feb 2025 14:04:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1739311487; x=1739916287; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=CwgVzN9SW/WuN0eRxe/TzHHcLPcWAalupXgTKGxMmXc=; b=EVanmT4oZTsIXZW89mFkJCO1h55wRhtmov8hVbREYtcWOdxKjaOkmW7X8ioqS+QYRA NxzFbaruaVyn8M9ULJyRGsWNIy6POo+37IZoPtB3+Mmk0vTYPIf3pkPAylnRbaulMiTb 3F3MioMVp7I2MEsI2gf2bN5qSQAIrYHrtjvVy5vikMi4X12ImkRP4okD8oWMRwxutRj+ c7JyhFpG8TKVYAHfftDOqZg6XupwDim6/EPVDOQ/Klh+sOenIacf3uF4MBwCeVDsyRJt y9QTm+vljOIix8mIdd4tuwIbgT6vdbxeIAFWxsZsTasHFvtioN8LY7FH6NFgRs9hssoc fcfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739311487; x=1739916287; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CwgVzN9SW/WuN0eRxe/TzHHcLPcWAalupXgTKGxMmXc=; b=TC3c4k7i7VvXlAlHvx1eT9Lq4PvJ4rORsZybV6IwGNcUkCdJyLPmeSe2T60kM3mq+r iQBhKes4NGrGiSOcNptyPFZ78LbssnHzl9E0Xg8KjasE6F8b+7FAP5d/01+OXWrxSmHU 7kowPvmriJCw3Nwxo4aQE4LYpZgEE29Zx7UxRiG1QiI9oLzn4lgt1izxSe9GgFFIIByw 7NILiQJ9EYJGY+ezJZYsJC39NIPoeZVPnGAnNwyyGAbw6b6dFzisEXxieatnTL5Uji7u ujjH278l50yboHIaJ5sTRDKu1WzOcZrn/PEDiR5a+nHiJrKSa0c7HNiRdtShrcZsOuJ6 535w== X-Gm-Message-State: AOJu0YxPAQRv5xxKfM5b6vc4DGbCTMGjwzGJziZ4ZgTu6cFacQIOOso+ D++6dWzUgGR3dRemNDWj38gca6v+vqtt4gjAtyU+o4sXtmPvvRgB+XzfFY2jWw== X-Gm-Gg: ASbGncsmS254GnbI2rykDpwBKtWzHx0nTK1e8lFVhxQAap4kqE/KEYYM8r0eqBe5YiK aI+NlprE9nlLIgJeFTlS9TbaTlBNc34IUgUxcvPm3Agf2HBAghgwPSh/IgFBeB9iVVD/nKzVAk3 r3mATWcqb+DsxVVNxY68/gmqhhS0k7EMWYyN3tZ9hX4fqytYYz9Yi1XhPZfP2u+O5KCR2rpTIcA jJVpgErlc9e/iaKsd8egDIxDwc5PsZK5z/vEMy7RV++eG+BFe3ZznU0vwqV7Aro5psaGqBIGyLd 1vt5RU/D9YLdsj0= X-Google-Smtp-Source: AGHT+IHMU2v4V+4oc+BGlnE9U9ztE+Zl0j4BSr685x8jcUlwHXSNGhRrJu5rP2l8aTL4+aJZozQjEA== X-Received: by 2002:a17:90b:544f:b0:2ee:aed6:9ec2 with SMTP id 98e67ed59e1d1-2fbf5c0f653mr1333037a91.14.1739311487141; Tue, 11 Feb 2025 14:04:47 -0800 (PST) Received: from [172.18.5.11] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220bcc860ebsm1307445ad.147.2025.02.11.14.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2025 14:04:46 -0800 (PST) Message-ID: <35ef2cd73b4c901feb9d04d755da27d02ec71b2e.camel@j-davis.com> Subject: Re: Proposal: "query_work_mem" GUC, to distribute working memory to the query's individual operators From: Jeff Davis To: James Hunter Cc: "pgsql-hackers@lists.postgresql.org" Date: Tue, 11 Feb 2025 14:04:45 -0800 In-Reply-To: References: <0beedccb92ba5a1db386bd09b44e15b20c1ac1fc.camel@j-davis.com> <6b134f12c727fdb3a03849deab585dea0dfb30aa.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-02-11 at 10:39 -0800, James Hunter wrote: > * The Path would store "nbytes" (=3D the optimizer's estimate of how > much working memory a given Path will use), to allow for future > optimizer logic to consider memory usage when choosing the best Path. >=20 > * The Plan would store a copy of "nbytes," along with "work_mem," and > the executor would enforce work_mem. A "(work_mem on)" option to the > "EXPLAIN" command would display both "nbytes" and "work_mem", per > Plan > node. Storing work_mem in each Plan node, and using that to enforce the memory limit (rather than using the GUC directly), seems uncontroversial to me. I'd suggest a standalone patch. Storing the optimizer's estimate of the memory wanted also sounds like a good idea. Let's pick a better name than "nbytes" though; maybe "requested_mem" or something? This change would make it a lot easier for an extension to adjust the per-node-work_mem, and also seems like good infrastructure for anything we build into the planner later. I suggest a standalone patch for this, as well. Can you write a useful extension with just the above two core patches? Regards, Jeff Davis