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 1tJA26-001EmR-Hg for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Dec 2024 11:28:34 +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 1tJA23-005zt1-O5 for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Dec 2024 11:28:32 +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 1tJA23-005zss-Bl for pgsql-hackers@lists.postgresql.org; Thu, 05 Dec 2024 11:28:32 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tJA21-001Avn-A5 for pgsql-hackers@postgresql.org; Thu, 05 Dec 2024 11:28:31 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-725a84ff55dso291765b3a.3 for ; Thu, 05 Dec 2024 03:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733398107; x=1734002907; 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=YkIfG98HamhqydvX1rytvA24ookQT01QgGIJ5t61DiU=; b=Af4awdplCQqQs6Lbywue4t+gzz6/WGs7TPxYUI8F52Dsko0WTgVCSrxAH1ASeEIK8I vKr839aftb3uO6N94ldaK4zlPPhmezEKirYRZKiyQ2PtAGlmwavDxkhi3AcLk3RTaw/h YKOVAmnbiGgzuA+3XBrcW3QgrzyCeAYMmU8HPbyVM8WYVujZjH+Qnva5jNNYXaO+xnpa cQawM9WJcKPnVI6qSq7b8eEEEGV1AgYDe2X1azV55yefssLLdZyCw45QiqbadPzd4aUf uOzpVbTC/sMlD4zKxFT8/4hgZTqdk9Qwxqp0AKCMrbmnrQL60YYQKOAwS4hlePxpCLwj 779w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733398107; x=1734002907; 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=YkIfG98HamhqydvX1rytvA24ookQT01QgGIJ5t61DiU=; b=axliqeYzAr5h/gb8NcNO8inPBNeNywh99fy2MX1j6DZxGHGvu5snkorUFuG5ifTT3s us4CUi7YMjYJVKY0au4kEiB9p3sZnovHBs5+YAeABfRdw4Q+JSXRBckDK+lSaKdaTwLb kD+gUdL3wPyYgulyOA1heGlCOruVXHvhGcP94ujCeHfYhNV3utK1rSHNAwILFOfSHOlh 58zyE7aVxDiolZPaoThDNhCHr9vikmflyqhFSzg2E07Y3GJ3z6FbW2RmDIF5AQ0hBnw8 xF39+SDiBGTkM0w8M2TKts32gVA8Ohlt6DvnyiJqpmyFxv7jFA6Jent+HfagT75f56ne qJzw== X-Forwarded-Encrypted: i=1; AJvYcCXyl5hGDly/4rn70Vmt4HO63ByyCoGrJ15DI2FhBr+2hEqWLbmXfVKgWY5DyWb+vfwv57JuGSDbg9yxKTTi@postgresql.org X-Gm-Message-State: AOJu0YzZxwG9oKDC79WOOIzCEJbtt8BFMlm3piJb2qM/E5oPmEqp2MLs axzva6fo+EB6/NouV4FZ8wsZKyD9Su0D4nb3Amgh0ShFSkvEswgI3kHaufsDpkkqjmsdii1Movv vUtfXCkX+NtlVmkVEGqo0qEIW8us= X-Gm-Gg: ASbGncvHIDsahA5z4et28mKSxzzsPn/uzRn9JRwaAL3+FjvkdamYoltYJi9lEsQGKYK CT4RbdIhNRvFKSiBHucxu7mImUlPnim0ofrti X-Google-Smtp-Source: AGHT+IEAsL4VsRFD1B3e9NtVAydhZUwvT6/PRsrMvV/wk6KvZUUuIWjqtz/KPLidnd24ixrJ0j+tY1Mun2SJnYG2PLA= X-Received: by 2002:a17:90b:4f8a:b0:2ee:a4f2:b311 with SMTP id 98e67ed59e1d1-2ef011e364amr14820279a91.8.1733398107285; Thu, 05 Dec 2024 03:28:27 -0800 (PST) MIME-Version: 1.0 References: <54c35fb9-da3a-4754-ab8c-46ed0b612465@vondra.me> <684c70d7-180e-461d-9377-600c2db581ba@vondra.me> In-Reply-To: From: Amit Langote Date: Thu, 5 Dec 2024 20:28:10 +0900 Message-ID: Subject: Re: generic plans and "initial" pruning To: Tomas Vondra Cc: Robert Haas , 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 Thu, Dec 5, 2024 at 3:53=E2=80=AFPM Amit Langote wrote: > On Thu, Dec 5, 2024 at 2:20=E2=80=AFAM Tomas Vondra wro= te: > > Sure, changing the APIs is allowed, I'm just wondering if maybe there > > might be a way to not have this issue, or at least notice the missing > > call early. > > > > I haven't tried, wouldn't it be better to modify ExecutorStart() to do > > the retries internally? I mean, the extensions wouldn't need to check i= f > > the plan is still valid, ExecutorStart() would take care of that. Yeah, > > it might need some new arguments, but that's more obvious. > > One approach could be to move some code from standard_ExecutorStart() > into ExecutorStart(). Specifically, the code responsible for setting > up enough state in the EState to perform ExecDoInitialPruning(), which > takes locks that might invalidate the plan. If the plan does become > invalid, the hook and standard_ExecutorStart() are not called. > Instead, the caller, ExecutorStartExt() in this case, creates a new > plan. > > This avoids the need to add ExecPlanStillValid() checks anywhere, > whether in core or extension code. However, it does mean accessing the > PlannedStmt earlier than InitPlan(), but the current placement of the > code is not exactly set in stone. I tried this approach and found that it essentially disables testing of this patch using the delay_execution module, which relies on the ExecutorStart_hook(). The way the testing works is that the hook in delay_execution.c pauses the execution of a cached plan to allow a concurrent session to drop an index referenced in the plan. When unpaused, execution initialization resumes by calling standard_ExecutorStart(). At this point, obtaining the lock on the partition whose index has been dropped invalidates the plan, which the hook detects and reports. It then also reports the successful re-execution of an updated plan that no longer references the dropped index. Hmm. --=20 Thanks, Amit Langote