Skip to content

Commit

Permalink
sql: make CREATE STATISTICS work properly with EXPLAIN ANALYZE (DEBUG)
Browse files Browse the repository at this point in the history
With this change, the bundle now contains the diagram for the
underlying plan.

Release note: None
  • Loading branch information
RaduBerinde committed Dec 7, 2020
1 parent 9afd7d2 commit 14e9ad6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/sql/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ func (ih *instrumentationHelper) ShouldCollectBundle() bool {
return ih.collectBundle
}

// ShouldInlineCreateStatsJob is true if we are running a statement under
// EXPLAIN ANALYZE, in which case we want to run any CREATE STATISTICS plan
// directly (and not through a job).
func (ih *instrumentationHelper) ShouldInlineCreateStatsJob() bool {
return ih.outputMode == explainAnalyzePlanOutput || ih.outputMode == explainAnalyzeDebugOutput
}

// ShouldBuildExplainPlan returns true if we should build an explain plan and
// call RecordExplainPlan.
func (ih *instrumentationHelper) ShouldBuildExplainPlan() bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt_exec_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ func (ef *execFactory) ConstructCreateStatistics(cs *tree.CreateStats) (exec.Nod
}
// Don't run as a job if we are inside an EXPLAIN / EXPLAIN ANALYZE. That will
// allow us to get insight into the actual execution.
runAsJob := !ef.isExplain
runAsJob := !ef.isExplain && !ef.planner.instrumentation.ShouldInlineCreateStatsJob()

return &createStatsNode{
CreateStats: *cs,
Expand Down

0 comments on commit 14e9ad6

Please sign in to comment.