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 1sg6M7-00FL21-Rk for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Aug 2024 17:39:47 +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 1sg6L7-000wZ3-I2 for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Aug 2024 17:38:46 +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.94.2) (envelope-from ) id 1sg6L7-000wYl-8J for pgsql-hackers@lists.postgresql.org; Mon, 19 Aug 2024 17:38:45 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sg6L5-000RPs-0P for pgsql-hackers@postgresql.org; Mon, 19 Aug 2024 17:38:44 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-52f024f468bso5771742e87.1 for ; Mon, 19 Aug 2024 10:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724089121; x=1724693921; 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=MRx2EKAyACXgFgpUXZcsb7RC2g1Jtfu5GarAnDzhmu0=; b=SFHFBSnLrT+SRwhruK4PPIeX7THLvSIh801WXTvLvlahV3zNQaJalJOWjiZ1MveZOb niCzRpXYOr0uAkZXZCKshOjcbdjg4CJHLGGumESaxDvPmQTILXisxbKgWN2Kduy2UNtL /EtoPvexdkxLc/RQU5ey++biPMRDI2lbI8t8lIYLOtUlIEX0C29jEQsmS1wriKcoVy8L WH1QBDczXG7yIy/tlbVM/JbdkDOR+Jqp7DfQvEXETkrq7b76TGx955ODCK2FMGmAxZVR ctV+TjLCrUrL549i1y5qPy0w89ikVqkdWDqSfG9y29Ol7dAJkhw1OFpPGAFnH83onvAG Jvyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724089121; x=1724693921; 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=MRx2EKAyACXgFgpUXZcsb7RC2g1Jtfu5GarAnDzhmu0=; b=tsrr6rX6PEm5l9BlbNeWevavU+XKnMVOzIdG5UpWCY8xtSAhkA4d1sD9S6XBuMi/uZ Z8hm1TAdHqKtjDqIUzZZ6Xuc63r6+GmRiqz4gx+YASYD4XbtR6M1uBoLIcTx+gokDf4j bweoHgz3wrv2JW5O95Hp6l3430rUjdH61Z5PbMCDUKHq7sVNiyvba2Fc3xoOXkAzqJO5 9WupzwK0tS4vMZ/ZjNzC3rs9R8/vXXIcjfR84G3jJd5VowB8YQS/IysB35ft+dTJuVhd oJnKsfxnzjsCZ43xm5V51k6BLGWS5v5PjWQh9KHQB6iMIQIpCYSSuaCUr8aS34mQa4MZ DC9Q== X-Forwarded-Encrypted: i=1; AJvYcCVWo432zW/thLpVb4H4ZWuEdG2fGrKOoRMbQ2dI09Jk1TJNHyP8NAYMMAm1sVbdpK2JyCGPCMkE2wLd5k+h1WaEGylnsgUc/xAmSw+V X-Gm-Message-State: AOJu0Ywf51GLrtfqU92udH0mGLTLDC71Z+jVOZxhgBLaLNCoSV8A5OBK Rrsupo+FvKEkv5vaRyOIbvtl92Oi+eoePBASJT5xpaAlsUY7Sk88zwzivuuJEspkk4pIsmMcw1m 8hRjg/E1i28tdxenCa6IFAN3FhUE= X-Google-Smtp-Source: AGHT+IGdoJZPfT+BJU83D8epANBj7kReQJ/WPTUqxUpPfKE88f5R2M3tw2betby+oXNx6Q6VH1pw+RJN8PtA+fPnj4U= X-Received: by 2002:a05:6512:1598:b0:52c:850b:cfc6 with SMTP id 2adb3069b0e04-5331c6dcd2dmr8301773e87.38.1724089120284; Mon, 19 Aug 2024 10:38:40 -0700 (PDT) MIME-Version: 1.0 References: <202406191709.jbvpf7d7hl6g@alvherre.pgsql> <1386845.1724086454@sss.pgh.pa.us> In-Reply-To: <1386845.1724086454@sss.pgh.pa.us> From: Robert Haas Date: Mon, 19 Aug 2024 13:38:28 -0400 Message-ID: Subject: Re: generic plans and "initial" pruning To: Tom Lane Cc: Amit Langote , Alvaro Herrera , Andres Freund , Daniel Gustafsson , David Rowley , PostgreSQL Hackers , Thom Brown 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 Mon, Aug 19, 2024 at 12:54=E2=80=AFPM Tom Lane wrote= : > What the examples here are showing is that AcquireExecutorLocks > is incomplete because it only provides defenses against DDL > initiated by other sessions, not by our own session. We have > CheckTableNotInUse but I'm not sure if it could be applied here. > We certainly aren't calling that in anywhere near as systematic > a way as we have for acquiring locks. > > Maybe we should rethink the principle that a session's locks > never conflict against itself, although I fear that might be > a nasty can of worms. It might not be that bad. It could replace the CheckTableNotInUse() protections that we have today but maybe cover more cases, and it could do so without needing any changes to the shared lock manager. Say every time you start a query you give that query an ID number, and all locks taken by that query are tagged with that ID number in the local lock table, and maybe some flags indicating why the lock was taken. When a new lock acquisition comes along you can say "oh, this lock was previously taken so that we could do thus-and-so" and then use that to fail with the appropriate error message. That seems like it might be more powerful than the refcnt check within CheckTableNotInUse(). But that seems somewhat incidental to what this thread is about. IIUC, Amit's original design involved having the plan cache call some new executor function to do partition pruning before lock acquisition, and then passing that data structure around, including back to the executor, so that we didn't repeat the pruning we already did, which would be a bad thing to do not only because it would incur CPU cost but also because really bad things would happen if we got a different answer the second time. IIUC, you didn't think that was going to work out nicely, and suggested instead moving the pruning+locking to ExecutorStart() time. But now Amit is finding problems with that approach, because by the time we reach PortalRun() for the PORTAL_MULTI_QUERY case, it's too late to replan, because we can't ask the plancache to replan just one query from the list; and if we try to fix that by moving ExecutorStart() to PortalStart(), then there are other problems. Do you have a view on what the way forward might be? This thread has gotten a tad depressing, honestly. All of the opinions about what we ought to do seem to be based on the firm conviction that X or Y or Z will not work, rather than on the confidence that A or B or C will work. Yet I'm inclined to believe this problem is solvable. --=20 Robert Haas EDB: http://www.enterprisedb.com