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 1shTik-002DKQ-Pr for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Aug 2024 12:48:50 +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 1shTii-00CzV4-LE for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Aug 2024 12:48:49 +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 1shTii-00CzUv-CA for pgsql-hackers@lists.postgresql.org; Fri, 23 Aug 2024 12:48:48 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1shTif-00174G-Eg for pgsql-hackers@postgresql.org; Fri, 23 Aug 2024 12:48:48 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-712603f7ba5so1642582b3a.3 for ; Fri, 23 Aug 2024 05:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724417324; x=1725022124; darn=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=+7dRFXSXOOsRD8H2YmjtFLjW/atCiHTlOXq2IOn6vaI=; b=gAYZcVgTZ8O1g8KYVjShmnRnBAOMZa7/TM5vNaxme52g810Hgwypfwxj+tb1MbGBa7 lZrRI6Ts/wsrOEOdSBrMjVuEHB6KfDTx99LMkkBxRR/W3LsGDTg4NrOYwf+w77JOwPTG iu2h2gsCP+XhyS/kIKT9cArPhOClt7odW4eE9HYDRlilwVrJYPASegIsxwEUHHt6qz9V 8m3Yz1hq+YX1N+xWw79/BbkgUv8+lI4ziKFf7x7PBQ9FAXxNIiBRQxwscyEUnUWMbqDr ihgdxdycYPMifqpiSXX3oAOZT5aVaVRQck5K/o6Ob+Wxw6hWPNnoieAFrOsY+lnEoost V4Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724417324; x=1725022124; 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=+7dRFXSXOOsRD8H2YmjtFLjW/atCiHTlOXq2IOn6vaI=; b=MD41w9UczhJpzAYvx9O1HeXKVmNNmHYJnMh1GT1/lu43As2yglh/2ro0dWbuY7tWa1 ZaN1IksisC9RUhFi2TB5TKkCadEvNzkj78aHJx426XzYq0/aNypO60pHtmR1orSqfIWD gDCZP4fP9JCIgSyyqwgDv2MDGrZRNZoNTpbYrVBM5vmbWvRnQAyhQbM1Yugs0A6qUlGV QMpxSwLBWvRSLrA7tKxbjhDOvsLyNuj9GU6WhlnNKZaIHCkCOAIINQgpfpsDFyfMd9Gg Bf46Aiv7QEs0Il7H4B6DoVQ2cPfnphxUyNr74suT/to2M6eCN1Uz/ApfKEZ4VSjNz0kz 2F0A== X-Forwarded-Encrypted: i=1; AJvYcCXX+Efa2PsLW1/wytMODTvIC/WGR0RnvmOc0f+mzzHRLbwiW7RQJUs831FzqteFB5zRH/FS0AmLq514TSYM@postgresql.org X-Gm-Message-State: AOJu0YyZ/dem4aL591fXy3xbcxK77c5rv6tGtghkzbl0vPtZ6MhKBdh2 JGe1t2I3oIpMw4h863T7PHZFjAH/6a9ob5/MWBGmNUHFxNfg4u9dqNwWzpr0ipAFsF3orHfDHpM 4ER/4224Z5ALjqFAe8d20OTmmB9I= X-Google-Smtp-Source: AGHT+IG0jAXapPy6/SDf77KIefSSWMTnLhwpKF2cpcTPeIJ9UltMinftz91lxTRxPDFbh4aStTY+HVUL7wPj7Tc0zZA= X-Received: by 2002:a05:6a00:9147:b0:70a:fdd8:51f2 with SMTP id d2e1a72fcca58-714457e4a88mr1992961b3a.15.1724417324300; Fri, 23 Aug 2024 05:48:44 -0700 (PDT) MIME-Version: 1.0 References: <202406191709.jbvpf7d7hl6g@alvherre.pgsql> In-Reply-To: From: Amit Langote Date: Fri, 23 Aug 2024 21:48:27 +0900 Message-ID: Subject: Re: generic plans and "initial" pruning To: Robert Haas Cc: Alvaro Herrera , Andres Freund , Daniel Gustafsson , David Rowley , PostgreSQL Hackers , Thom Brown , Tom Lane 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 Wed, Aug 21, 2024 at 10:10=E2=80=AFPM Robert Haas wrote: > On Wed, Aug 21, 2024 at 8:45=E2=80=AFAM Amit Langote wrote: > > * The replanning aspect of the lock-in-the-executor design would be > > simpler if a CachedPlan contained the plan for a single query rather > > than a list of queries, as previously mentioned. This is particularly > > due to the requirements of the PORTAL_MULTI_QUERY case. However, this > > option might be impractical. > > It might be, but maybe it would be worth a try? I mean, > GetCachedPlan() seems to just call pg_plan_queries() which just loops > over the list of query trees and does the same thing for each one. If > we wanted to replan a single query, why couldn't we do > fake_querytree_list =3D list_make1(list_nth(querytree_list, n)) and then > call pg_plan_queries(fake_querytree_list)? Or something equivalent to > that. We could have a new GetCachedSinglePlan(cplan, n) to do this. I've been hacking to prototype this, and it's showing promise. It helps make the replan loop at the call sites that start the executor with an invalidatable plan more localized and less prone to action-at-a-distance issues. However, the interface and contract of the new function in my prototype are pretty specialized for the replan loop in this context=E2=80=94meaning it's not as general-purpose as GetCachedPlan(). Essentially, what you get when you call it is a 'throwaway' CachedPlan containing only the plan for the query that failed during ExecutorStart(), not a plan integrated into the original CachedPlanSource's stmt_list. A call site entering the replan loop will retry the execution with that throwaway plan, release it once done, and resume looping over the plans in the original list. The invalid plan that remains in the original list will be discarded and replanned in the next call to GetCachedPlan() using the same CachedPlanSource. While that may sound undesirable, I'm inclined to think it's not something that needs optimization, given that we're expecting this code path to be taken rarely. I'll post a version of a revamped locks-in-the-executor patch set using the above function after debugging some more. -- Thanks, Amit Langote