Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pIiS9-0006yl-FI for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Jan 2023 03:52:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pIiS8-0005iN-6d for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Jan 2023 03:52:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pIiS7-0005iD-SC for pgsql-hackers@lists.postgresql.org; Fri, 20 Jan 2023 03:52:31 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pIiS1-0002Py-44 for pgsql-hackers@postgresql.org; Fri, 20 Jan 2023 03:52:30 +0000 Received: by mail-pj1-x1034.google.com with SMTP id m3-20020a17090a414300b00229ef93c5b0so3034883pjg.2 for ; Thu, 19 Jan 2023 19:52:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Q9ygLseo9exjaCjXwvBDp/1fuYm1a84GxYoxhKrhEJc=; b=gkBY/VH2ekgR1MJT1mbxksCNuklz6HhCFUjz/r1iTSq+QcEkoQ1oWu+PMjdBzGs77U wOcHXemkOsHp34kBOaACbNEHOokFvtBTq5fhz3eR/wa9MFz8kCNv36EmgOEZdGLVSyYy Cngl9STzjsBtrwyC9BOH+oYV63DmVB9V5XThrPN8/V80L7C39Oi2PD8XlQhOoccKYKuS nBsx7UKUEOnVnck5zHW+BdUxsCBCh6ylzqk+kKlkoS2HppbrkuV8XrG+XTOcOK3okpFS lBUOLLSBRZAg0oBhDtLyEUcKFfAkulMwPE2M4lmN/eJH6Gu0kEzFgz+yAvPoGCbfoxI3 eeJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=Q9ygLseo9exjaCjXwvBDp/1fuYm1a84GxYoxhKrhEJc=; b=isHh+eayYrvp4JNdl+iSyjQHeyEW6wb5ZMSDkWSwN6TTYIrKz7VtfNjPJS4h5YqdHM MfRazrTu4tW9VmwWkw0a0h5zGXqEmDWN4MTRfbOvTOaNDjSJkRGlhabIRoNRr/Mh9jiX o37HEa1T2RZasdRUM/IYZLauF820sc8ZmaqN8x9t3STj93494TABjbvQKlUBfiIYj1f3 YgKfgzQ58Jg3taPiD9Ucua+2p6bPSdzPKIHnQhpwRCFegLVF6ShZ9eKtugM07aMX9N3P wq/PbaXt2DWTN6/aSVjVg32UTCGzaC6fINUcFkbYRmHabSMRBGN7OFIpPMz+FnUprsCq uq7w== X-Gm-Message-State: AFqh2koDGZshDNhTasKMw4H+Ka5lXfIfqcdwAy/KRQ06ChJb7K2vQ2vT kov+rSfYaef59R4yeyg9USA2GpTL0BjLCNBrzaI= X-Google-Smtp-Source: AMrXdXseKkK1PAoE98ByT1fjohd+42ispVYSshy43Hl8d7jvRzs0F1aEyBR8pzCxyFZMGJ5fMYryT5VICbIWQ3tEhxA= X-Received: by 2002:a17:90b:3c89:b0:229:4a04:65f5 with SMTP id pv9-20020a17090b3c8900b002294a0465f5mr1229582pjb.57.1674186743886; Thu, 19 Jan 2023 19:52:23 -0800 (PST) MIME-Version: 1.0 References: <20221221101846.7zsi7lscnm5ediik@alvherre.pgsql> <1350682.1671635927@sss.pgh.pa.us> <4191508.1674157166@sss.pgh.pa.us> <349124.1674185509@sss.pgh.pa.us> In-Reply-To: <349124.1674185509@sss.pgh.pa.us> From: Amit Langote Date: Fri, 20 Jan 2023 12:52:07 +0900 Message-ID: Subject: Re: generic plans and "initial" pruning To: Tom Lane Cc: Alvaro Herrera , Robert Haas , Jacob Champion , David Rowley , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jan 20, 2023 at 12:31 PM Tom Lane wrote: > Amit Langote writes: > > On Fri, Jan 20, 2023 at 4:39 AM Tom Lane wrote: > >> I had what felt like an epiphany: the whole problem arises because the > >> system is wrongly factored. We should get rid of AcquireExecutorLocks > >> altogether, allowing the plancache to hand back a generic plan that > >> it's not certain of the validity of, and instead integrate the > >> responsibility for acquiring locks into executor startup. > > > Interesting. The current implementation relies on > > PlanCacheRelCallback() marking a generic CachedPlan as invalid, so > > perhaps there will have to be some sharing of state between the > > plancache and the executor for this to work? > > Yeah. Thinking a little harder, I think this would have to involve > passing a CachedPlan pointer to the executor, and what the executor > would do after acquiring each lock is to ask the plancache "hey, do > you still think this CachedPlan entry is valid?". In the case where > there's a problem, the AcceptInvalidationMessages call involved in > lock acquisition would lead to a cache inval that clears the validity > flag on the CachedPlan entry, and this would provide an inexpensive > way to check if that happened. OK, thanks, this is useful. > It might be possible to incorporate this pointer into PlannedStmt > instead of passing it separately. Yeah, that would be less churn. Though, I wonder if you still hold that PlannedStmt should not be scribbled upon outside the planner as you said upthread [1]? > >> * In a successfully built execution state tree, there will simply > >> not be any nodes corresponding to pruned-away, never-locked subplans. > > > I think this is true with the patch as proposed too, but I was still a > > bit worried about what an ExecutorStart_hook may be doing with an > > uninitialized plan tree. Maybe we're mandating that the hook must > > call standard_ExecutorStart() and only work with the finished > > PlanState tree? > > It would certainly be incumbent on any such hook to not touch > not-yet-locked parts of the plan tree. I'm not particularly concerned > about that sort of requirements change, because we'd be breaking APIs > all through this area in any case. OK. Perhaps something that should be documented around ExecutorStart(). > >> * In some cases (views, at least) we need to acquire lock on relations > >> that aren't directly reflected anywhere in the plan tree. So there'd > >> have to be a separate mechanism for getting those locks and rechecking > >> validity afterward. A list of relevant relation OIDs might be enough > >> for that. > > > Hmm, a list of only the OIDs wouldn't preserve the lock mode, > > Good point. I wonder if we could integrate this with the > RTEPermissionInfo data structure? You mean adding a rellockmode field to RTEPermissionInfo? > > Would you like me to hack up a PoC or are you already on that? > > I'm not planning to work on this myself, I was hoping you would. Alright, I'll try to get something out early next week. Thanks for all the pointers. -- Thanks, Amit Langote EDB: http://www.enterprisedb.com [1] https://www.postgresql.org/message-id/922566.1648784745%40sss.pgh.pa.us