Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/sql/create_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ var errorOnConcurrentCreateStats = settings.RegisterBoolSetting(
true,
settings.WithPublic)

var automaticStatsJobAutoCleanup = settings.RegisterBoolSetting(
settings.ApplicationLevel,
"sql.stats.automatic_stats_job_auto_cleanup.enabled",
"set to true to enable automatic cleanup of completed AUTO CREATE STATISTICS jobs",
false)

const nonIndexColHistogramBuckets = 2

// StubTableStats generates "stub" statistics for a table which are missing
Expand Down Expand Up @@ -222,6 +228,12 @@ func (n *createStatsNode) runJob(ctx context.Context) error {
return nil
}
}
} else if automaticStatsJobAutoCleanup.Get(n.p.ExecCfg().SV()) {
if name := job.Details().(jobspb.CreateStatsDetails).Name; name == jobspb.AutoStatsName || name == jobspb.AutoPartialStatsName {
if err := n.p.ExecCfg().JobRegistry.DeleteTerminalJobByID(ctx, job.ID()); err != nil {
log.Dev.Warningf(ctx, "failed to auto-delete terminal automatic stats job: %v", err)
}
}
}
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/create_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func TestAutoPartialStatsJobDescription(t *testing.T) {
// Disable automatic statistics collection.
sqlRunner.Exec(t, `SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;`)
sqlRunner.Exec(t, `SET CLUSTER SETTING sql.stats.automatic_partial_collection.enabled = false;`)
sqlRunner.Exec(t, `SET CLUSTER SETTING sql.stats.automatic_stats_job_auto_cleanup.enabled = false;`)

// Create a test table.
sqlRunner.Exec(t, `CREATE TABLE test (id INT PRIMARY KEY, value INT);`)
Expand Down