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.98.2) (envelope-from ) id 1xE9PR-00000000wj2-1rtC for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Oct 2026 17:57:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xE9PQ-000000011Vw-1TTP for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Oct 2026 17:57:00 +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.98.2) (envelope-from ) id 1xE9PP-000000011Vn-48Ox for pgsql-hackers@lists.postgresql.org; Tue, 06 Oct 2026 17:57:00 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xE9PN-00000000giU-1r4q for pgsql-hackers@lists.postgresql.org; Tue, 06 Oct 2026 17:56:58 +0000 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-3a7c8c25f7dso1241139a91.1 for ; Tue, 06 Oct 2026 10:56:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20251104.gappssmtp.com; s=20251104; t=1791309416; x=1791914216; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=hDSPbkKwNyQ/G0coHMHd4JEPgiiSmccebmgeBg0Rlz0=; b=RfwrU0QDzem05CX0KGiqy3mIc/5apKmUkjLd7A0scbrZqsVD7YAqlMkwe2j/Vf7koS JUKurCJgBIFDV8XBS44n+Um7ov22JHSMtOIW7p2AZ9NPyGzcJQwO4fNWIajpJNIuh4n+ OjWwqVQBPwLm6vqlGAZYqHaKPrtR/HXVgulN2vi+44PW9TLnqmyAtz/97071KHWSNtiD GgN9CpExJ9d6xHfCdCVF514d0hFHyPdcfzTqEinGHw6S8AwoEXXightmeMSwH/cszDsY DA4rdcm1LXullnfDL2ek9E7Ux/Vk1WUkrKi9bYX+ivl2Qm975McwbQeJ6tVHUYDq/nmu qvlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791309416; x=1791914216; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hDSPbkKwNyQ/G0coHMHd4JEPgiiSmccebmgeBg0Rlz0=; b=q1r9e8QBsdKL71RpOjK0hg1bo/9glHR6sB8sFE/xuFSPzBNAtmYo2+6OvszBUfaXtx +9l9TA1V+SSEOWAnFgSgS/Feq9aSKbjQfHZMRCbNlJkaT01zIt2FxV6r1v//Q3LjHGfa fhjjA+8D15iJc4g8zEuC9/2GxNKjOoSSIeEoQode4dIK0i3pP0QjEBA25xg1QXZmFc2L vDMb9jv8aerCfitGZDGcaMCjy8iS2WTN/SnWfQ6HpGLbtU1Fs7P+OU7z/xcDc87j+L/W Akb4ghCN8ZLGHKmmY/MrP5q1oNVjtatV2wbPTH598zjiyEHKDo9wtAdgYmfgnx9h03L/ YSAA== X-Forwarded-Encrypted: i=1; AKwUvBxyFez7RHEtcJvhrju7XK32Y79f0Umb6UIoT/gSqIxtLNvXAd+2dj8hemt/97FsfiT9RXyYdbYhxkvY12hQ@lists.postgresql.org X-Gm-Message-State: AFq9FYIjeitSab/dgQTff2uzlLalhLVhz+pB9yjsVWIJHDmti06OROwR plTZ0m0HU0AKA3IZycAOhrh2nsJ0K56MDLgxH+KATSQagouhtOW3lFjOaW68Gactuw== X-Gm-Gg: AYBFou38kmi82f4FIdmu1PbAJ91VcsoBqWHvhBwMlwkSJTFrr0Pkkd62AK3WUOAFmGT HNP9tkc5RmQ5bf4WzzOUD1eT25IVaWWH21sOrkTaKu5BOGf4hkcdBGLrIbjjAELaKjoCvNYdI6I LltFSQf+6Npjm3y7zvhtyln5ROdU3ejfElK7evgnouBgIZQZ2qDPebIvPRKSNBUMlrINN23OgMa ITY7o0P0daSZFVYWsG5+QANeFUYDq/y/OWTVWme3p2M2BNARDNdTAvDKUJ//QjTs71vDk/d6oHS Q7sPpR3xoijCiOEfOgO/nMFR/jEcnJ9hw4kva6T32c6v3iHE/UUK7fBh84MgOKfHbtSx8LGt6Ic as6i9dW7EvXYlIDjY+jCrTXgp8T4dIp22aFygwzA/a1RVgCEagmBX6fVOUf0x1SLJkDNc5H3RUt OEx9PpaRAHqyRz8XIyXW0S1PG2cl6gRsXsopUr95YxosJkfb4Lj3KvmKMZ64YhZpDKGiUAsadW X-Received: by 2002:a17:90b:384d:b0:39e:6c68:c787 with SMTP id 98e67ed59e1d1-3a8a1553dedmr8847a91.61.1791309416377; Tue, 06 Oct 2026 10:56:56 -0700 (PDT) Received: from [10.10.247.200] ([12.63.242.123]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a8987b1e1asm626666a91.1.2026.10.06.10.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 10:56:55 -0700 (PDT) Message-ID: <227a5a38f1536ea9d9dc84ea533f2182876ee56f.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: Manu Cc: James Hunter , =?ISO-8859-1?Q?=C1lvaro?= Herrera , pgsql-hackers@lists.postgresql.org Date: Tue, 06 Oct 2026 10:56:54 -0700 In-Reply-To: <179106756531.274884.9866634099979671297@gmail.com> References: <9800a3044cf2f2d948def3e5b68f8eda61a82d22.camel@j-davis.com> <179106756531.274884.9866634099979671297@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-9 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, 2026-10-03 at 19:46 -0300, Manu wrote: > Each Plan node gets a workmem field...The executor uses the node's > value...I first tried copying work_mem into the field at plan time.=C2=A0 > Then SET > LOCAL work_mem inside a PL/pgSQL function no longer reached a query > whose plan was already cached: it wrote a 13 MB temporary file that > master does not.=C2=A0 Replanning cached plans when work_mem changes fixe= s > that, but cost 47% of the tps in a pgbench run that changes work_mem > in > every transaction before a prepared 3-way join. Regarding the previous discussion here: https://www.postgresql.org/message-id/2a2b28e2ea677e3cec2850b2dd38b467bf129= 1fb.camel%40j-davis.com IIUC, you resolve the issue by introducing a special zero value, which preserves the existing behavior by default, and only an extension can set it to a non-zero value. There's no auto-replan, so using an extension would get behavior (a) described in the above thread. I generally like that approach. It allows some experimentation with planner hooks without changing existing behavior. It also avoids some difficulty transmitting work_mem to places that don't have easy access to the Plan structure. It's essentially a refactor, so the cost is ~200 lines, some code churn, and extra function parameters. I didn't review all the details yet, but if a real extension actually uses this, that seems reasonable to me. Regards, Jeff Davis