Re: generic plans and "initial" pruning
David Rowley <dgrowleyml@gmail.com>
On Thu, 31 Mar 2022 at 16:25, Amit Langote <amitlangote09@gmail.com> wrote: > Rebased. I've been looking over the v8 patch and I'd like to propose semi-baked ideas to improve things. I'd need to go and write them myself to fully know if they'd actually work ok. 1. You've changed the signature of various functions by adding ExecLockRelsInfo *execlockrelsinfo. I'm wondering why you didn't just put the ExecLockRelsInfo as a new field in PlannedStmt? I think the above gets around messing the signatures of CreateQueryDesc(), ExplainOnePlan(), pg_plan_queries(), PortalDefineQuery(), ProcessQuery() It would get rid of your change of foreach to forboth in execute_sql_string() / PortalRunMulti() and gets rid of a number of places where your carrying around a variable named execlockrelsinfo_list. It would also make the patch significantly easier to review as you'd be touching far fewer files. 2. I don't really like the way you've gone about most of the patch... The way I imagine this working is that during create_plan() we visit all nodes that have run-time pruning then inside create_append_plan() and create_merge_append_plan() we'd tag those onto a new field in PlannerGlobal That way you can store the PartitionPruneInfos in the new PlannedStmt field in standard_planner() after the makeNode(PlannedStmt). Instead of storing the PartitionPruneInfo in the Append / MergeAppend struct, you'd just add a new index field to those structs. The index would start with 0 for the 0th PartitionPruneInfo. You'd basically just know the index by assigning list_length(root->glob->partitionpruneinfos). You'd then assign the root->glob->partitionpruneinfos to PlannedStmt.partitionpruneinfos and anytime you needed to do run-time pruning during execution, you'd need to use the Append / MergeAppend's partition_prune_info_idx to lookup the PartitionPruneInfo in some new field you add to EState to store those. You'd leave that index as -1 if there's no PartitionPruneInfo for the Append / MergeAppend node. When you do AcquireExecutorLocks(), you'd iterate over the PlannedStmt's PartitionPruneInfo to figure out which subplans to prune. You'd then have an array sized list_length(plannedstmt->runtimepruneinfos) where you'd store the result. When the Append/MergeAppend node starts up you just check if the part_prune_info_idx >= 0 and if there's a non-NULL result stored then use that result. That's how you'd ensure you always got the same run-time prune result between locking and plan startup. 3. Also, looking at ExecGetLockRels(), shouldn't it be the planner's job to determine the minimum set of relations which must be locked? I think the plan tree traversal during execution not great. Seems the whole point of this patch is to reduce overhead during execution. A full additional plan traversal aside from the 3 that we already do for start/run/end of execution seems not great. I think this means that during AcquireExecutorLocks() you'd start with the minimum set or RTEs that need to be locked as determined during create_plan() and stored in some Bitmapset field in PlannedStmt. This minimal set would also only exclude RTIs that would only possibly be used due to a PartitionPruneInfo with initial pruning steps, i.e. include RTIs from PartitionPruneInfo with no init pruining steps (you can't skip any locks for those). All you need to do to determine the RTEs to lock are to take the minimal set and execute each PartitionPruneInfo in the PlannedStmt that has init steps 4. It's a bit disappointing to see RelOptInfo.partitioned_rels getting revived here. Why don't you just add a partitioned_relids to PartitionPruneInfo and just have make_partitionedrel_pruneinfo build you a Relids of them. PartitionedRelPruneInfo already has an rtindex field, so you just need to bms_add_member whatever that rtindex is. It's a fairly high-level review at this stage. I can look in more detail if the above points get looked at. You may find or know of some reason why it can't be done like I mention above. David
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