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 1tJCVi-001TNK-Ev for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Dec 2024 14:07:18 +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 1tJCVf-006a2i-Vu for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Dec 2024 14:07:17 +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 1tJCVf-006a2a-Lk for pgsql-hackers@lists.postgresql.org; Thu, 05 Dec 2024 14:07:16 +0000 Received: from relay7-d.mail.gandi.net ([217.70.183.200]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tJCVe-001C4s-1L for pgsql-hackers@postgresql.org; Thu, 05 Dec 2024 14:07:16 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id E994620008; Thu, 5 Dec 2024 14:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1733407634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oo/7wxmf4/ozDta60VDePAf6wSRvQ0SDN8k+DolHm0c=; b=eKHu+lgjh42ImlolE+PksnDB02xKShCYHztrjIibCQssMo1rZtbHBLW+8UiR+vGMoxZdXo +biDsS4Xx+yApTWEXZ43F95tErPhTbbYa3kvg8V3rcGwi/q8NH8ECqTkSvn8U/Htvl22eE b4gU2DYxGfNHwSiIhG36KYSZQC0zITqbY1Hh9on5QilMqrnRCb/Zjf9PRSmnVbJmg+XGAw UVQb6rzsLoaoAX2zX/e314OvpgyRLWOzg2lOQ8/+RCtP7JjZ7cGMfU04FTmfKi1xitK2Vq hTaTGfXaQDB1Dc3QGPJa8A4Kx2tiOAkIV3M4CtRbzOPZzzG43X51WR4aPSCO0Q== Message-ID: Date: Thu, 5 Dec 2024 15:07:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: generic plans and "initial" pruning To: Amit Langote Cc: Robert Haas , Alvaro Herrera , Andres Freund , Daniel Gustafsson , David Rowley , PostgreSQL Hackers , Thom Brown , Tom Lane References: <54c35fb9-da3a-4754-ab8c-46ed0b612465@vondra.me> <684c70d7-180e-461d-9377-600c2db581ba@vondra.me> Content-Language: en-US From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: tomas@vondra.me List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/5/24 12:28, Amit Langote wrote: > On Thu, Dec 5, 2024 at 3:53 PM Amit Langote wrote: >> On Thu, Dec 5, 2024 at 2:20 AM Tomas Vondra wrote: >>> 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 if >>> 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. > It's not clear to me why the change disables this testing, and I can't try without a patch. Could you explain? thanks -- Tomas Vondra