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 1tJCIA-001S95-6x for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Dec 2024 13:53: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 1tJCI7-006VGE-NW for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Dec 2024 13:53:16 +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 1tJCI6-006VG5-RW for pgsql-hackers@lists.postgresql.org; Thu, 05 Dec 2024 13:53: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 1tJCI4-001BzJ-Sa for pgsql-hackers@postgresql.org; Thu, 05 Dec 2024 13:53:15 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id F36F320009; Thu, 5 Dec 2024 13:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1733406791; 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=SVwcNy2ijCYOFXXlAc1B5ahXPxzTk0B+PJTFEAtpWuU=; b=fXmm3BsRRI9jEYB5va3LFFpJOoyxj3wbEUY3YMUP+LYAEse/4v0uZMcOqoon658oWBi/eb BYCTqc4bGiOctPe7/DURCuD794I2syoXcueIVrWnWXprspMNBe0wO1lc9ofdejWeSj88d7 TyLlc5umcLVzJwXgD0ZBrxN5XM/s4ADbmGkPz8UJO+RZXMEOxgjwSIAV8jQvUu1laizUhJ YcO4AvU1RCZa0XjyVFqz1YeBeQd1MKiO+1yg8KaxpKCtwU7ZxVLpGkplJn9nSV2C7foF3E tZ78wU5oMhXHt9CBX2moUv6KBZP03QA7LrIv7uM7FnodeLXsF4RLBidpf6z3JA== Message-ID: <52e3aa78-18d6-424c-b48b-f5018d103824@vondra.me> Date: Thu, 5 Dec 2024 14:53:09 +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 07:53, Amit Langote wrote: > On Thu, Dec 5, 2024 at 2:20 AM Tomas Vondra wrote: >> ... >> >>>> What if an >>>> extension doesn't do that? What weirdness will happen? >>> >>> The QueryDesc.planstate won't contain a PlanState tree for starters >>> and other state information that InitPlan() populates in EState based >>> on the PlannedStmt. >> >> OK, and the consequence is that the query will fail, right? > > No, the core executor will retry the execution with a new updated > plan. In the absence of the early return, the extension might even > crash when accessing such incomplete QueryDesc. > > What the patch makes the ExecutorStart_hook do is similar to how > InitPlan() will return early when locks taken on partitions that > survive initial pruning invalidate the plan. > Isn't that what I said? My question was what happens if the extension does not add the new ExecPlanStillValid() call - sorry if that wasn't clear. If it can crash, that's what I meant by "fail". >>>> Maybe it'd be >>>> possible to at least check this in some other executor hook? Or at least >>>> we could ensure the check was done in assert-enabled builds? Or >>>> something to make extension authors aware of this? >>> >>> I've added a note in the commit message, but if that's not enough, one >>> idea might be to change the return type of ExecutorStart_hook so that >>> the extensions that implement it are forced to be adjusted. Say, from >>> void to bool to indicate whether standard_ExecutorStart() succeeded >>> and thus created a "valid" plan. I had that in the previous versions >>> of the patch. Thoughts? >> >> Maybe. My concern is that this case (plan getting invalidated) is fairly >> rare, so it's entirely plausible the extension will seem to work just >> fine without the code update for a long time. > > You might see the errors like the one below when the core executor or > a hook tries to initialize or process in some other way a known > invalid plan, for example, because an unpruned partition's index got > concurrently dropped before the executor got the lock: > > ERROR: could not open relation with OID xxx > Yeah, but how likely is that? How often get plans invalidated in regular application workload. People don't create or drop indexes very often, for example ... Again, I'm not saying requiring the call would be unacceptable, I'm sure we made similar changes in the past. But if it wasn't needed without too much contortion, that would be nice. regards -- Tomas Vondra