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 1thvB1-008Z7H-DW for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Feb 2025 18:40:07 +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 1thvAz-00E7s9-Lf for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Feb 2025 18:40:05 +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 1thvAz-00E7s1-CQ for pgsql-hackers@lists.postgresql.org; Tue, 11 Feb 2025 18:40:05 +0000 Received: from mail-ej1-x642.google.com ([2a00:1450:4864:20::642]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1thvAw-000IHK-2X for pgsql-hackers@lists.postgresql.org; Tue, 11 Feb 2025 18:40:05 +0000 Received: by mail-ej1-x642.google.com with SMTP id a640c23a62f3a-ab7b80cc3d2so374314366b.3 for ; Tue, 11 Feb 2025 10:40:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739299202; x=1739904002; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rStoLBcTchk+siZPKygL541Jko5EHCGm0uCnuNb+ZuU=; b=Fh564J0nCCwKeabMcgWb32j8Ryz+2waLX1VjA/fYIytLt03ns9fTEWREJfqrnmJXMo a24zy5Hl7GjiCcjIGvS3fSiNS2FKPuPTXPjeY5mNkP7dMsSyJaqoAJZzhx9OE/HIUaGV 5eVUOn9k7/J+Wjol4SKOLYv3HxgBC42syDlSa+imlhU6TdGsMik+7anOfM5vcRFlrCB7 hVgpcov0ehxcZL9wq/gmTNbZgROLpi6IKJeDaKiulD0UsZQM7PXBP/3xrC+Xt6b1o1tm QrW9K5ykcwIkJdOj0IyuKMjHAiteCqwg3QzmXsKbptX9heufKKJeIUqzCUMhtTLhP8fN MzDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739299202; x=1739904002; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rStoLBcTchk+siZPKygL541Jko5EHCGm0uCnuNb+ZuU=; b=uwrIOPPIlb4mMeOwXJE3ODCA5kXvF7Edu4f2ngvS0viAIcNGsJ1GEM1JltLqog3Sbd uelIj+Lc0e0AnjGWDEJaDgiLDzk0YkIDo4wpnm+2DzOUVzVT7IB8XNuZfO401XZCuBDi RzixXDtBmtFE+2b5uN6KANiB/EeGVcx5C8NutiGXdpoFIOmN7pCYACOj++//SYwZNxyy WcKB50ZLf+bjs6B3LeSfXUiNUd1zswfl3SkTz3efl4akr3uGVCUp8HYgR5IkTivE5LkT Zu6PBO/mvmznUT3a0FE6szAggYrZ6iIgOc7+p78MWeKfYG+AtbZZ8RmSHIyvuNwh9twY 9QxQ== X-Gm-Message-State: AOJu0YwvcGY9H/MDfvOYdSafFmsF0xaMGPNoQoRNr36lsuuZaMb+CJfo OD7cK1C672K+hPk0HOwLEfq1K4x+6Q7QZTC61xcFHdVwhMOsJJVOIDC+JPfj8yifl0t6k0vjYLN BjjQr8TFVgcwpUSiCt8lluPxg3n4= X-Gm-Gg: ASbGncsohajc5yiwOEQEVSxMyCJ8bqvF27zLmRGCKO62YFy+yaWMtlwqOgFO/I7dn1h 9SJSpNYqCXgBWkJEiTqMgcEWTe9YweTyl09wodz73w/YuXYSbyL6K7SV69YqjI0WKwToywJiUDv I= X-Google-Smtp-Source: AGHT+IGi2WBsOjTovkRRXIqhIs2lCxcHEvcCaOzDQs3tYU0AAh+8UPpwWkN9RYXfUdwQw2gfzBl0VomW47fP9tqDoZ8= X-Received: by 2002:a05:6402:2788:b0:5dc:9589:9f64 with SMTP id 4fb4d7f45d1cf-5deadd7d3a9mr654157a12.13.1739299202248; Tue, 11 Feb 2025 10:40:02 -0800 (PST) MIME-Version: 1.0 References: <0beedccb92ba5a1db386bd09b44e15b20c1ac1fc.camel@j-davis.com> <6b134f12c727fdb3a03849deab585dea0dfb30aa.camel@j-davis.com> In-Reply-To: From: James Hunter Date: Tue, 11 Feb 2025 10:39:51 -0800 X-Gm-Features: AWEUYZmhMY2fypP51nvR0TWEBjKzr8uIFKWhAk6Bqzp_9wvG1MArx6plgH2fpRY Message-ID: Subject: Re: Proposal: "query_work_mem" GUC, to distribute working memory to the query's individual operators To: Jeff Davis Cc: "pgsql-hackers@lists.postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Feb 11, 2025 at 10:00=E2=80=AFAM Jeff Davis wro= te: > > On Mon, 2025-02-10 at 19:09 -0800, James Hunter wrote: > > I think it makes sense to split the work into two parts: one part > > that > > improves SQL execution, and a second part that improves the > > optimizer, > > to reflect the improvements to execution. > > I like the idea to store the value of work_mem in the > path/plan/executor nodes, and use that at execution time rather than > the GUC directly. > > IIUC, that would allow an extension to do what you want, right? A > planner hook could just walk the tree and edit those values for > individual nodes, and the executor would enforce them. Yes, exactly! * 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. * 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. * Either built-in logic or an extensibility hook would set "work_mem" on each individual Plan node, based on whatever heuristic or rule it chooses. Right now, my prototype sets "work_mem" inside ExecInitNode(). Thanks, James