Re: generic plans and "initial" pruning
Amit Langote <amitlangote09@gmail.com>
On Fri, Jan 20, 2023 at 12:31 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: > Amit Langote <amitlangote09@gmail.com> writes: > > On Fri, Jan 20, 2023 at 4:39 AM Tom Lane <tgl@sss.pgh.pa.us> 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
Commits
-
Stamp 19beta1.
- 4b0bf0788b06 19 (unreleased) cited
-
Revert "Don't lock partitions pruned by initial pruning"
- 1722d5eb05d8 18.0 landed
-
Ensure first ModifyTable rel initialized if all are pruned
- 28317de723b6 18.0 cited
-
Fix bug in cbc127917 to handle nested Append correctly
- cbb9086c9ef6 18.0 landed
-
Remove unstable test suite added by 525392d57
- 4f1b6e5bb4fe 18.0 landed
-
Don't lock partitions pruned by initial pruning
- 525392d5727f 18.0 landed
-
Fix an oversight in cbc127917 to handle MERGE correctly
- 75dfde13639a 18.0 landed
-
Track unpruned relids to avoid processing pruned relations
- cbc127917e04 18.0 landed
-
Perform runtime initial pruning outside ExecInitNode()
- d47cbf474ecb 18.0 landed
-
Move PartitionPruneInfo out of plan nodes into PlannedStmt
- bb3ec16e14de 18.0 landed
-
Fix setrefs.c's failure to do expression processing on prune steps.
- bf826ea06297 18.0 cited
-
Remove obsolete executor cleanup code
- d060e921ea5a 17.0 landed
-
Revert "Move PartitionPruneInfo out of plan nodes into PlannedStmt"
- 5472743d9e85 16.0 landed
-
Move PartitioPruneInfo out of plan nodes into PlannedStmt
- ec386948948c 16.0 landed
-
Refactor and cleanup runtime partition prune code a little
- 297daa9d4353 15.0 landed
-
Remove some unnecessary fields from Plan trees.
- 52ed730d511b 12.0 cited
-
Remove more redundant relation locking during executor startup.
- f2343653f5b2 12.0 cited
-
Shut down Gather's children before shutting down Gather itself.
- acf555bc53ac 10.0 cited