Re: generic plans and "initial" pruning
Amit Langote <amitlangote09@gmail.com>
Attachments
- v46-0004-Make-ExecutorStart-return-early-upon-plan-invali.patch (application/octet-stream) patch v46-0004
- v46-0006-Set-inFromCl-to-false-in-child-table-RTEs.patch (application/octet-stream) patch v46-0006
- v46-0005-Add-field-to-store-parent-relids-to-Append-Merge.patch (application/octet-stream) patch v46-0005
- v46-0008-Track-opened-range-table-relations-in-a-List-in-.patch (application/octet-stream) patch v46-0008
- v46-0007-Delay-locking-of-child-tables-in-cached-plans-un.patch (application/octet-stream) patch v46-0007
- v46-0003-Support-for-ExecInitNode-to-detect-CachedPlan-in.patch (application/octet-stream) patch v46-0003
- v46-0001-Refactor-ExecEnd-routines-to-enhance-efficiency.patch (application/octet-stream) patch v46-0001
- v46-0002-Check-pointer-NULLness-before-cleanup-in-ExecEnd.patch (application/octet-stream) patch v46-0002
Thanks for taking a look. On Mon, Aug 28, 2023 at 10:43 PM Robert Haas <robertmhaas@gmail.com> wrote: > On Fri, Aug 11, 2023 at 9:50 AM Amit Langote <amitlangote09@gmail.com> wrote: > > After removing the unnecessary cleanup code from most node types’ ExecEnd* functions, one thing I’m tempted to do is remove the functions that do nothing else but recurse to close the outerPlan, innerPlan child nodes. We could instead have ExecEndNode() itself recurse to close outerPlan, innerPlan child nodes at the top, which preserves the close-child-before-self behavior for Gather* nodes, and close node type specific cleanup functions for nodes that do have any local cleanup to do. Perhaps, we could even use planstate_tree_walker() called at the top instead of the usual bottom so that nodes with a list of child subplans like Append also don’t need to have their own ExecEnd* functions. > > I think 0001 needs to be split up. Like, this is code cleanup: > > - /* > - * Free the exprcontext > - */ > - ExecFreeExprContext(&node->ss.ps); > > This is providing for NULL pointers where we don't currently: > > - list_free_deep(aggstate->hash_batches); > + if (aggstate->hash_batches) > + list_free_deep(aggstate->hash_batches); > > And this is the early return mechanism per se: > > + if (!ExecPlanStillValid(estate)) > + return aggstate; > > I think at least those 3 kinds of changes deserve to be in separate > patches with separate commit messages explaining the rationale behind > each e.g. "Remove unnecessary cleanup calls in ExecEnd* functions. > These calls are no longer required, because <reasons>. Removing them > saves a few CPU cycles and simplifies planned refactoring, so do > that." Breaking up the patch as you describe makes sense, so I've done that: Attached 0001 removes unnecessary cleanup calls from ExecEnd*() routines. 0002 adds NULLness checks in ExecEnd*() routines on some pointers that may not be initialized by the corresponding ExecInit*() routines in the case where it returns early. 0003 adds the early return mechanism based on checking CachedPlan invalidation, though no CachedPlan is actually passed to the executor yet, so no functional changes here yet. Other patches are rebased over these. One significant change is in 0004 which does the refactoring to make the callers of ExecutorStart() aware that it may now return with a partially initialized planstate tree that should not be executed. I added a new flag EState.es_canceled to denote that state of the execution to complement the existing es_finished. I also needed to add AfterTriggerCancelQuery() to ensure that we don't attempt to fire a canceled query's triggers. Most of these changes are needed only to appease the various Asserts in these parts of the code and I thought they are warranted given the introduction of a new state of query execution. -- Thanks, Amit Langote EDB: http://www.enterprisedb.com
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