-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: fix the collection of logical plan samples
The logic was in the wrong place and did not properly account for the optimizer mode and whether an execution error occured. This patch fixes it. To achieve this, the patch requires the ability to inspect the planNode tree after the execution machinery finishes running the query. Unfortunately, there is not a single point in the execution code where the following two properties hold at once: - the execution has completed (so it is known whether an error has occurred or not). - the planNode tree is still available for sampling. This is because when the local exec code for a planNode tree is started (`startExec`), it allocates memory in memory accounts set up by the distSQL exec machinery. At the end of execution, it is thus important to close the planNode tree before the exec machinery accounts are closed. So the execution code currently has co-"ownership" of closing the planNode tree. Unfortunately it does not have full ownership of the plan close because the executor still has to close the plan in case distSQL PlanAndRun() is not called. The proper way forward would be to remove local execution so that there are no planNode memory accounts any more, and so that the responsibility to close the plan is fully transferred back to the executor code. Unfortunately this is a major undertaking and we still want to get a fix in CockroachDB 2.1. So instead this patch makes `planTop.close()` responsible for sampling the logical plan. This "works" because that is the method guaranteed to be called in all execution paths. To achieve this planTop.close() calls into a `maybeSavePlan()` callsback set up by the executor code. This in turn needs the plan flags (optimizer used, distsql used) and the last error, which are now also stored in `planTop`. The rest of the commit is plumbing, including avoiding passing `sql.Statement` by-value throughout calls (it's a big struct!) Release note: None
- Loading branch information
Showing
17 changed files
with
195 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.