Skip to content

Commit 545e0fb

Browse files
committed
sql: skip vtable for control ALL X JOBS
The PAUSE/RESUME/CANCEL ALL X JOBS syntax previously decoded every job payload to see if the payload had a field corresponding to X to find jobs of that type. Instead it can just find those jobs using the indexed job_type column in system.jobs. Release note: none. Epic: https://cockroachlabs.atlassian.net/browse/CRDB-48791.
1 parent 71bcba2 commit 545e0fb

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

pkg/sql/delegate/job_control.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ type ControlJobsDelegate struct {
2525

2626
// protoNameForType maps job types to the matching protobuf names for Payload.details in jobs.proto
2727
// This is also used to enumerate the types of jobs that we actually handle
28-
var protobufNameForType = map[string]string{
29-
"changefeed": "changefeed",
30-
"backup": "backup",
31-
"import": "import",
32-
"restore": "restore",
28+
var jobTypes = map[string]string{
29+
"changefeed": "CHANGEFEED",
30+
"backup": "BACKUP",
31+
"import": "IMPORT",
32+
"restore": "RESTORE",
3333
}
3434

3535
func (d *delegator) delegateJobControl(stmt ControlJobsDelegate) (tree.Statement, error) {
@@ -72,26 +72,11 @@ AND jobs.status IN (%s) AND jobs.created_by_id IN (%s)`,
7272
}
7373

7474
if stmt.Type != "" {
75-
if _, ok := protobufNameForType[stmt.Type]; !ok {
75+
if _, ok := jobTypes[stmt.Type]; !ok {
7676
return nil, errors.New("unsupported job type")
7777
}
78-
queryStrFormat := `%s JOBS (
79-
SELECT id
80-
FROM (
81-
SELECT id,
82-
status,
83-
(
84-
crdb_internal.pb_to_json(
85-
'cockroach.sql.jobs.jobspb.Payload',
86-
payload, false, true
87-
)->'%s'
88-
) IS NOT NULL AS correct_type
89-
FROM crdb_internal.system_jobs
90-
WHERE status IN (%s)
91-
)
92-
WHERE correct_type
93-
);`
94-
return d.parse(fmt.Sprintf(queryStrFormat, tree.JobCommandToStatement[stmt.Command], protobufNameForType[stmt.Type], filterClause))
78+
return d.parse(fmt.Sprintf(`%s JOBS SELECT id FROM system.jobs WHERE job_type = '%s' AND status IN (%s)`,
79+
tree.JobCommandToStatement[stmt.Command], jobTypes[stmt.Type], filterClause))
9580
}
9681

9782
return nil, errors.AssertionFailedf("Missing Schedules or Type clause in delegate parameters")

0 commit comments

Comments
 (0)