Skip to content

Commit fe2e250

Browse files
committed
sql: fix logic to collect stats on system.jobs
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.
1 parent dc28e19 commit fe2e250

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

pkg/sql/create_stats.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,6 @@ func (n *createStatsNode) makeJobRecord(ctx context.Context) (*jobs.Record, erro
233233
)
234234
}
235235

236-
if tableDesc.GetID() == keys.JobsTableID {
237-
return nil, pgerror.New(
238-
pgcode.WrongObjectType, "cannot create statistics on system.jobs",
239-
)
240-
}
241-
242236
if tableDesc.GetID() == keys.ScheduledJobsTableID {
243237
return nil, pgerror.New(
244238
pgcode.WrongObjectType, "cannot create statistics on system.scheduled_jobs",

pkg/sql/logictest/testdata/logic_test/distsql_stats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,8 +1657,8 @@ ANALYZE system.lease
16571657
statement error pq: cannot create statistics on system.table_statistics
16581658
ANALYZE system.table_statistics
16591659

1660-
# Collecting stats on system.jobs is disallowed.
1661-
statement error pq: cannot create statistics on system.jobs
1660+
# Collecting stats on system.jobs is allowed.
1661+
statement ok
16621662
ANALYZE system.jobs
16631663

16641664
# Collecting stats on system.scheduled_jobs is disallowed.

0 commit comments

Comments
 (0)