Skip to content

Commit

Permalink
sql: fix logic to collect stats on system.jobs
Browse files Browse the repository at this point in the history
This commit fixes an oversight in cockroachdb#102637 which intended to enable
stats collection on the jobs table, but was not successful.

I've manually confirmed that stats are now collected on the jobs table
in a local cluster:
```
  888074673664065537 | AUTO CREATE STATS               | Table statistics refresh for system.public.jobs                         | CREATE STATISTICS __auto__ FROM [15] WITH OPTIONS THROTTLING 0.9 AS OF SYSTEM TIME '-30s'  | root      | succeeded | NULL           | 2023-08-03 19:01:22.343
```

Informs cockroachdb#107405

Release note (performance improvement): We now automatically collect
table statistics on the system.jobs table, which will enable the optimizer
to produce better query plans for internal queries that access the
system.jobs table. This may result in better performance of the system.
Note: a previous attempt to enable stats on system.jobs starting in 23.1.0
was unsuccessful, but we have now fixed the oversight.
  • Loading branch information
rytaft committed Aug 4, 2023
1 parent dc28e19 commit fe2e250
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
6 changes: 0 additions & 6 deletions pkg/sql/create_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,6 @@ func (n *createStatsNode) makeJobRecord(ctx context.Context) (*jobs.Record, erro
)
}

if tableDesc.GetID() == keys.JobsTableID {
return nil, pgerror.New(
pgcode.WrongObjectType, "cannot create statistics on system.jobs",
)
}

if tableDesc.GetID() == keys.ScheduledJobsTableID {
return nil, pgerror.New(
pgcode.WrongObjectType, "cannot create statistics on system.scheduled_jobs",
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/distsql_stats
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,8 @@ ANALYZE system.lease
statement error pq: cannot create statistics on system.table_statistics
ANALYZE system.table_statistics

# Collecting stats on system.jobs is disallowed.
statement error pq: cannot create statistics on system.jobs
# Collecting stats on system.jobs is allowed.
statement ok
ANALYZE system.jobs

# Collecting stats on system.scheduled_jobs is disallowed.
Expand Down

0 comments on commit fe2e250

Please sign in to comment.