Re: generic plans and "initial" pruning
Robert Haas <robertmhaas@gmail.com>
On Wed, Sep 6, 2023 at 5:12 AM Amit Langote <amitlangote09@gmail.com> wrote: > Attached updated patches. Thanks for the review. I think 0001 looks ready to commit. I'm not sure that the commit message needs to mention future patches here, since this code cleanup seems like a good idea regardless, but if you feel otherwise, fair enough. On 0002, some questions: - In ExecEndLockRows, is the call to EvalPlanQualEnd a concern? i.e. Does that function need any adjustment? - In ExecEndMemoize, should there be a null-test around MemoryContextDelete(node->tableContext) as we have in ExecEndRecursiveUnion, ExecEndSetOp, etc.? I wonder how we feel about setting pointers to NULL after freeing the associated data structures. The existing code isn't consistent about doing that, and making it do so would be a fairly large change that would bloat this patch quite a bit. On the other hand, I think it's a good practice as a general matter, and we do do it in some ExecEnd functions. On 0003, I have some doubt about whether we really have all the right design decisions in detail here: - Why have this weird rule where sometimes we return NULL and other times the planstate? Is there any point to such a coding rule? Why not just always return the planstate? - Is there any point to all of these early exit cases? For example, in ExecInitBitmapAnd, why exit early if initialization fails? Why not just plunge ahead and if initialization failed the caller will notice that and when we ExecEndNode some of the child node pointers will be NULL but who cares? The obvious disadvantage of this approach is that we're doing a bunch of unnecessary initialization, but we're also speeding up the common case where we don't need to abort by avoiding a branch that will rarely be taken. I'm not quite sure what the right thing to do is here. - The cases where we call ExecGetRangeTableRelation or ExecOpenScanRelation are a bit subtler ... maybe initialization that we're going to do later is going to barf if the tuple descriptor of the relation isn't what we thought it was going to be. In that case it becomes important to exit early. But if that's not actually a problem, then we could apply the same principle here also -- don't pollute the code with early-exit cases, just let it do its thing and sort it out later. Do you know what the actual problems would be here if we didn't exit early in these cases? - Depending on the answers to the above points, one thing we could think of doing is put an early exit case into ExecInitNode itself: if (unlikely(!ExecPlanStillValid(whatever)) return NULL. Maybe Andres or someone is going to argue that that checks too often and is thus too expensive, but it would be a lot more maintainable than having similar checks strewn throughout the ExecInit* functions. Perhaps it deserves some thought/benchmarking. More generally, if there's anything we can do to centralize these checks in fewer places, I think that would be worth considering. The patch isn't terribly large as it stands, so I don't necessarily think that this is a critical issue, but I'm just wondering if we can do better. I'm not even sure that it would be too expensive to just initialize the whole plan always, and then just do one test at the end. That's not OK if the changed tuple descriptor (or something else) is going to crash or error out in a funny way or something before initialization is completed, but if it's just going to result in burning a few CPU cycles in a corner case, I don't know if we should really care. - The "At this point" comments don't give any rationale for why we shouldn't have received any such invalidation messages. That makes them fairly useless; the Assert by itself clarifies that you think that case shouldn't happen. The comment's job is to justify that claim. -- Robert Haas 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